diff options
author | Federico Fissore <f.fissore@arduino.cc> | 2013-05-16 16:43:47 +0200 |
---|---|---|
committer | Federico Fissore <f.fissore@arduino.cc> | 2013-05-16 16:43:47 +0200 |
commit | e7ace175a23d5ecd516133181a43c70fa837b7bf (patch) | |
tree | e5041c34905869d8c251a1707c9b0e9ccfeff847 | |
parent | 09749bdf014bd1ddbf3b7e43c88658a7e6bb5ffd (diff) |
added responses to Bridge.ino
-rw-r--r-- | libraries/Bridge/examples/Bridge/Bridge.ino | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/libraries/Bridge/examples/Bridge/Bridge.ino b/libraries/Bridge/examples/Bridge/Bridge.ino index c4f71db..dc453c4 100644 --- a/libraries/Bridge/examples/Bridge/Bridge.ino +++ b/libraries/Bridge/examples/Bridge/Bridge.ino @@ -41,21 +41,34 @@ void process(uint8_t buff[], int l) { // Command selection if (l==5 && cmd0=='D' && cmd1=='W') { char c = buff[4]; - if (c=='0' || c=='1') + if (c=='0' || c=='1') { digitalWrite(pin, c-'0'); + reportDigitalRead(pin, true, true); + } } else if (l==4 && cmd0=='D' && cmd1=='R') { reportDigitalRead(pin, true, true); } else if (l==7 && cmd0=='A' && cmd1=='W') { analogWrite(pin, buff[4]); + reportAnalogRead(pin); } else if (l==4 && cmd0=='A' && cmd1=='R') { reportAnalogRead(pin); } else if (l==4 && cmd0=='P' && cmd1=='I') { pinMode(pin, INPUT); + reportPinMode(pin, INPUT); } else if (l==4 && cmd0=='P' && cmd1=='O') { pinMode(pin, OUTPUT); + reportPinMode(pin, OUTPUT); } } +void reportPinMode(int pin, uint8_t dir) { + uint8_t buff[] = { 'P', 'I', '0', '0' }; + buff[1] = dir == INPUT ? 'I' : 'O'; + buff[2] += pin/10; + buff[3] += pin%10; + Bridge.writeMessage(buff, 4); +} + void reportDigitalRead(int pin, boolean raw, boolean dataset) { // "Dpp0" - "Dpp1" // 0 1 2 3 @@ -87,4 +100,5 @@ void reportAnalogRead(int pin) { buff[4] += v%10; v /= 10; buff[3] += v; Bridge.writeMessage(buff, 7); -}
\ No newline at end of file +} + |