Telling the computer a button was pressed
flo
Posts: 38
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:
Is there somewhere I can read up on packet design and would this make sense?
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
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*