summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2016-05-04 19:57:54 +0200
committerChristian Pointner <equinox@spreadspace.org>2016-05-04 19:57:54 +0200
commitc81360e290059e79876623b0e9c4f6ad89bf2956 (patch)
treef98e244b8209297678cd00d5ddf8d3cf5c7fab7a
parentarduino stub digitalWire... etc work now (diff)
usb-pjon sending works now... recv still needs testing
-rw-r--r--usb-pjon/usb-pjon.cpp23
1 files changed, 19 insertions, 4 deletions
diff --git a/usb-pjon/usb-pjon.cpp b/usb-pjon/usb-pjon.cpp
index 66d58e1..dc6deef 100644
--- a/usb-pjon/usb-pjon.cpp
+++ b/usb-pjon/usb-pjon.cpp
@@ -33,7 +33,7 @@
#include "Arduino.h"
#include "PJON.h"
-PJON bus(5, 45); // Bus connection to pin 12, device id 45
+PJON bus(8); // Bus connection to pin 8
void error_handler(uint8_t code, uint8_t data) {
if(code == CONNECTION_LOST) {
@@ -55,12 +55,26 @@ void error_handler(uint8_t code, uint8_t data) {
}
}
+void recv_handler(uint8_t length, uint8_t *payload) {
+ if(length == 0) {
+ printf("got 0 byte message...\r\n");
+ return;
+ }
+ led_on();
+ printf("got message(%d bytes): '%s'\r\n", length, payload);
+ delay(30);
+ led_off();
+}
+
+
void handle_cmd(uint8_t cmd)
{
switch(cmd) {
- case '0': led_off(); break;
- case '1': led_on(); break;
- case 's': bus.send(44, "hello", 5); break;
+ case '1': case '2': case '3':
+ case '4': case '5': case '6':
+ case '7': case '8': case '9': bus.set_id(cmd - '0'); printf("device id is now: %d\r\n", cmd - '0'); break;
+ case 'b': bus.send(BROADCAST, "hello world", 11); break;
+ case 's': bus.send(9, "hi!", 3); break;
case '!': reset2bootloader(); break;
default: printf("error\r\n"); return;
}
@@ -80,6 +94,7 @@ int main(void)
arduino_init();
bus.begin();
bus.set_error(error_handler);
+ bus.set_receiver(recv_handler);
for(;;) {
int16_t BytesReceived = usbio_bytes_received();