Shop OBEX P1 Docs P2 Docs Learn Events
I'd like some simple examples of data entry using a keyboard, please. — Parallax Forums

I'd like some simple examples of data entry using a keyboard, please.

ElectricAyeElectricAye Posts: 4,561
edited 2011-04-15 21:55 in Propeller 1
I've never implemented a keyboard before and, though I know there are objects for it in the OBEX, I was hoping some of you fine folks wouldn't mind posting some simple examples of data entry using a keyboard. My lack of assembly knowledge combined with the usual lack of comments in the OBEX always makes it difficult for me to get started with things like this.

Ideally, what I would like to do is have a VGA screen that looks something like this:
VGA screen wrote:

Filename:
Date:
Test run:

And then I'd like to be able to click next to each colon with a mouse, type in the data, hit the Enter key and have those entered values be assigned to their respective variables without a whole lot of obscene dramas taking place.

Many thanks,
Mark

Comments

  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2011-04-13 09:08
    @Mark,

    The input routine in PropDOS has served me repeatedly for keyboard input in various programs. Perhaps it would be of help? http://forums.parallaxinc.com/forums/default.aspx?f=25&m=224206

    OBC
  • ElectricAyeElectricAye Posts: 4,561
    edited 2011-04-13 11:40
    @Mark,

    The input routine in PropDOS has served me repeatedly for keyboard input in various programs....

    Jeff,

    Wow, this PropDOS of yours is one major piece of work! Would you say line 773, PUB input(data, size) | keystroke,len is the best place to start looking, to educate myself on keyboard usage?

    thanks!
  • StefanL38StefanL38 Posts: 2,292
    edited 2011-04-13 11:47
    Ariba has developed a pc-emulation for the tv-text and vga-text-object you can use it as a almost drop-in replacement for these drivers

    On his website you can download the propterminal.exe and demos for how to use the keyboard or mouse.
    The demos show basic techniques how you can do it. The website is german but the Propterminal manual and the spin-files are in english
    http://insonix.ch/propeller/prop_term.html

    best regards

    Stefan

    the mose-democode
    {{ Mouse Test }}
    
    '  Receives Mouse-events and shows buttons and position as Hex numbers.
    '  Sets pixels, lines or boxes while a mouse button pressed, this shows the
    '  Graphic feature of the PropTerminal.
    
    CON
    
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
    
    OBJ
      ms     :       "PC_Mouse"
      TV     :       "PC_Text" 
      
    VAR
    
    
    PUB Main | b
    
      'start the terminal
      TV.start(12)
      TV.str(string("Mouse Demo...",13))
    
      'start the mouse
      ms.start(24, 25)
      ms.delta_reset
    
      repeat
          if ms.buttons
            TV.out(1)  'Home   if a button pressed
          else
            TV.out(0)  'cls    if no mouse button pressed
    
          'echo mouse events in hex
          TV.out("B")
          TV.out(":")
          TV.dec(ms.buttons)
          TV.out(" ")
          TV.out("X")
          TV.out(":")
          TV.dec(ms.abs_x)
          TV.out(" ")
          TV.out("Y")
          TV.out(":")
          TV.dec(ms.abs_y)
          TV.out(" ")
    
          'draw with the mouse
          TV.out(5)                 'PropTerminal Grafics
          TV.out(ms.buttons)
          TV.out(ms.abs_x >> 1)
          TV.out((230 - ms.abs_y) >> 1)
    
          waitcnt(clkfreq/10 + cnt)
    
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2011-04-13 15:15
    It's got a a lot of extras but is a decent routine for keyboard input. Hope it helps!

    OBC
  • ElectricAyeElectricAye Posts: 4,561
    edited 2011-04-13 18:51
    To Stefan and Jeff,

    I'm sure this stuff will make sense to me once my brain is out of its allergic Springtime fog. Even on a good day, my eyes glaze over when I have to read computer code. Especially coding masterpieces written by gurus. Frankly, today I was hoping for something on the level with Dr. Seuss.

    NerdBig8-thumb.gif

    BTW, the first known use of the word nerd was from Dr. Seuss in 1950.
  • ElectricAyeElectricAye Posts: 4,561
    edited 2011-04-15 11:20
    Okay, so I got my Dr. Seuss level of keyboard data entry going. Or started, at least.

    I'm attaching the file in case anybody wants to wade through my horrible coding skills, unorthodox usage of Spin tag whatchamacallits, outlandishly long variable names, overly verbose commentary and other tidbits than invariably infuriate people who actually know what they're doing when it comes to microcontrollers. I'm sure it's still got a bunch of bugs in it somewhere.

    Thanks again to Jeff and Stephan for helping me out of the total fog. Much appreciated. :-)
  • MagIO2MagIO2 Posts: 2,243
    edited 2011-04-15 11:39
    I think the Xes are a little bit confusing. Why don't you use a different background-color and print spaces instead? This more looks like a input-field.

    You should also limit the number of characters that can be entered. Otherwise you can have a buffer overflow which might cause any kind of problems in your program.

    Then make the input routine a function that can be used in several parts of the program by passing the screen position and the length of the input field.

    ..

    ;o)
  • ElectricAyeElectricAye Posts: 4,561
    edited 2011-04-15 11:52
    MagIO2 wrote: »
    I think the Xes are a little bit confusing. Why don't you use a different background-color and print spaces instead?...

    That's a good idea. I think I'll add that on as I build on this.


    MagIO2 wrote: »
    ...

    You should also limit the number of characters that can be entered....

    Well, maybe I didn't do it quite right, but I thought (FileNameCursorPosition < 8) took care of that. When I tested it, the program seemed to work in that regard.

    Thanks for the comments and for taking the time to look at the code. I almost never post any code because I know it will freak out the code gurus on here. LOL.
  • MagIO2MagIO2 Posts: 2,243
    edited 2011-04-15 12:04
    Upss ... my fault ... I have a Netbook here and did not scroll to the end of the line ;o)

    Just one little point: what's the reason for having ByteArrayAddressPointer and FileNameCursorPosition?

    Byte[ByteArrayAddressPointer] := PressedKey
    if you replace that by
    SDcardFileName[ Pointer ] := PressedKey
    you only need one pointer.

    You should post code ..
    1. It's not bad at all
    2. it propably helps others
    3. gurus only want to give you wisdom ...


    PS: But you don't check for >0 when hitting backspace.
  • ElectricAyeElectricAye Posts: 4,561
    edited 2011-04-15 12:13
    MagIO2 wrote: »
    ....


    PS: But you don't check for >0 when hitting backspace.

    Oh, good point! I'll have to fix that tonight. Thanks very much!
  • StefanL38StefanL38 Posts: 2,292
    edited 2011-04-15 20:24
    Hi ElectricAye,
    in case anybody wants to wade through my horrible coding skills, unorthodox usage of Spin tag whatchamacallits, outlandishly long variable names, overly verbose commentary and other tidbits
    first of all a comment on this:

    Just in case the quoted was not meant with a big selfironic smile on your face.

    You are the person that has to stay together with yourself every day 24 hours. So you this person should think positive whenever possible about this person.
    This includes from time to time to step away from yourself 2m left and 2m up to watch yourself what you are doing. Giving a positive or negative value to the doing - not to your person itself.
    Your person itself has always the same big value in itself. If you keep this in mind it will be much easier to look at things that went wrong.

    Anyway in case of your code my opinion is: it is good. I'm coding with the same length of variablenames to make things clear just by reading selfexplaining names.
    So the basic comment is in the names itself. I'm using ctrl-shift cursor left/right to mark these names and then copy & paste them.
    Saves time and avoids typos. So I'm pretty fast in writing code even with long variable names (and less debugging for typos).

    Showing code means I'm willing to learn from comments.
    The command repeat has various options including a "until" and a "while" which makes the repeating conditional
    this is a variant which I personally prefer over using a "quit" as it makes the code more readable
      repeat until (PressedKey == 13)
    
    could be a variant to code this.

    About what MagIO2 wrote
    But you don't check for >0 when hitting backspace.
    I prefer to test things not only quick with one example but to test with everything extreme I can think of

    In this case hitting backspace a dozen times
    1) slowly,
    2) very fast
    3) with varying speed to see what happens. I do this even if I "know" nothing bad can happen. Just to reassure that really nothing can happen and to catch up all the case where I only "thought" nothing bad could happen

    Maybe I can call this systematic testing. This will assure that the code is working properly right while writing the code
    and not doing strange things later on if I already forgot about the details how this piece of code works.

    I would add a CON-section with constant names for cursor-controlcodes
    CON
      BackSpace = 8
      CR = 13
    etc.
    
    best regards

    Stefan
  • ElectricAyeElectricAye Posts: 4,561
    edited 2011-04-15 21:55
    StefanL38 wrote: »
    ... I'm coding with the same length of variablenames to make things clear just by reading selfexplaining names. ....

    Wow, Stefan, these are all very great suggestions. I will definitely incorporate them as I work this keyboard capability into my next project. I think you are the only person on this forum (besides me) whom I've ever heard confess to using long self-explanatory variable names. When I first started using the Propeller a few years ago, I used to complain about how the OBEX was filled with code written in "electronic grunt" that was impossible for a newbie to follow, but I was always slapped down for being inefficient, a whiner or whatever. Personally, I'm not happy unless each of my variable names contains a built-in biography of the variable, including its place of birth, favorite color, hobbies and whether or not it uses tobacco products.

    Thanks for the help!
    Mark
Sign In or Register to comment.