Shop OBEX P1 Docs P2 Docs Learn Events
Telling the computer a button was pressed — Parallax Forums

Telling the computer a button was pressed

floflo Posts: 38
edited 2010-04-27 00:26 in Propeller 1
I’m very new to serial communication and was hoping you guys could offer your wisdom and recommendations.

Here’s what I’m trying to do:
My computer needs to send an arbitrary amount of bytes (anything between 7 to 512 bytes) to a my prop as fast as possible. Also, it needs to send 1 byte to indicate which of 8 LEDs should be on. My prop, needs to send the contents of a shift register (1 byte of 8 button states) back to the computer.

I’d imagine something like this:

Computer sends a packet who’s first byte indicates weather the packet is data (variable 7-255 bytes) or LED on/off (1 byte) states. Once the prop received the entire packet and performs error checking (checksum or something similar), it scans the button input pins and sends back 1 byte to indicate the button states and 1 byte to indicate that the packet was received and to send another. The computer would do the button debouncing.

It would look like this:

Computer packet - data: x(byte that indicates data), 1, 2, … 253,  254,  255
Computer packet – LED statuses: y(byte that indicates LED statuses), 1 

Prop packet – button presses and confirm: z(byte that indicates buttonPresses), 1, 2 (byte that indicates successful packet receipt)




Is there somewhere I can read up on packet design and would this make sense?

Comments

  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2010-04-27 00:26
    I would have thought that you would debounce on the Prop before sending, nevertheless you might want to send the byte back after the acknowledgement character so that the PC would always expect this character to begin the "packet". You could include a simple checksum after the ack and buttons, but since you are debouncing on the PC it might not matter anyway. But what are you doing with the data from the PC? Where is it going etc? Your Prop wants to process this information before receiving another packet.

    If the data from the PC is comprised of normal 7-bit ASCII characters (i.e. strings) then you could use unique control characters to mark the beginning of the block and the end. A count byte after the SOH (start of header) would help too as well as a checksum before the terminator.

    I chuckled to see that you have listened to the spell checker, wonderful little creatures they are, always so helpful, but not too smart, you never know whether they will choose the correct words for the context.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    *Peter*
Sign In or Register to comment.