Shop OBEX P1 Docs P2 Docs Learn Events
Ouputing Char Codes as Chars using FullDuplexSerialPlus? — Parallax Forums

Ouputing Char Codes as Chars using FullDuplexSerialPlus?

SRLMSRLM Posts: 5,045
edited 2008-11-09 00:51 in Propeller 1
Okay, I know that there must be a really simple way of converting numbers to chars, but I seem to be very incompentent today. I'm using the getkey function of the keyboard.spin object, and I'm using FullDuplexSerialPlus to output the stuff to a PST. I can get it to display a number, but what I really want to do is the have it convert the number into a charecter. How do I do that?

Edit: I tried putting a lookup table as in debug.str(lookup(keycode: "a", "b", "c")) but that didn't work.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-11-08 23:13
    The displayable keycodes are already in the proper format in that their lower 8 bits are the ASCII code for the character. Just use serial.tx(<keycode>). You'll need to test first for the keycodes for control characters like carriage return and tab (and backspace) since the keycodes for these are not the same as the ASCII control codes. Look at the end of the source file for keyboard.spin for a table of returned keycode values.
  • SRLMSRLM Posts: 5,045
    edited 2008-11-08 23:33
    Thank you. I was looking for something like decToStr(), but the tx() works great. With some preliminary testing, it seems that I can pass it straight from the keyboard to the terminal without worrying about special chars (like CR, TAB, space). It seems to understand these. The F# keys give the odd stuff, like accented chars. Anyway, thanks for pointing me in the right dirrection.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-11-08 23:46
    Not all the control characters work. For example, the backspace key gives a scancode of $C8 while an ASCII backspace is $08.
  • SRLMSRLM Posts: 5,045
    edited 2008-11-09 00:51
    Eventually, I would like to output the codes the same way they came in: via a PS/2 port. I'm starting with the keyboard, since I have one that works, but my eventual goal is to be able to build my own propeller based mouse (using a touch screen). However, I'll keep the differences in mind for when I need to do a diffenent application.

    As a side note, I'd also like to get the Prop to intercept the key commands and output a morse code equivelent via a solinoid. More of an annoying toy than anything else.
Sign In or Register to comment.