added responses to Bridge.ino
This commit is contained in:
parent
57be162d49
commit
3a3d086827
|
@ -41,21 +41,34 @@ void process(uint8_t buff[], int l) {
|
||||||
// Command selection
|
// Command selection
|
||||||
if (l==5 && cmd0=='D' && cmd1=='W') {
|
if (l==5 && cmd0=='D' && cmd1=='W') {
|
||||||
char c = buff[4];
|
char c = buff[4];
|
||||||
if (c=='0' || c=='1')
|
if (c=='0' || c=='1') {
|
||||||
digitalWrite(pin, c-'0');
|
digitalWrite(pin, c-'0');
|
||||||
|
reportDigitalRead(pin, true, true);
|
||||||
|
}
|
||||||
} else if (l==4 && cmd0=='D' && cmd1=='R') {
|
} else if (l==4 && cmd0=='D' && cmd1=='R') {
|
||||||
reportDigitalRead(pin, true, true);
|
reportDigitalRead(pin, true, true);
|
||||||
} else if (l==7 && cmd0=='A' && cmd1=='W') {
|
} else if (l==7 && cmd0=='A' && cmd1=='W') {
|
||||||
analogWrite(pin, buff[4]);
|
analogWrite(pin, buff[4]);
|
||||||
|
reportAnalogRead(pin);
|
||||||
} else if (l==4 && cmd0=='A' && cmd1=='R') {
|
} else if (l==4 && cmd0=='A' && cmd1=='R') {
|
||||||
reportAnalogRead(pin);
|
reportAnalogRead(pin);
|
||||||
} else if (l==4 && cmd0=='P' && cmd1=='I') {
|
} else if (l==4 && cmd0=='P' && cmd1=='I') {
|
||||||
pinMode(pin, INPUT);
|
pinMode(pin, INPUT);
|
||||||
|
reportPinMode(pin, INPUT);
|
||||||
} else if (l==4 && cmd0=='P' && cmd1=='O') {
|
} else if (l==4 && cmd0=='P' && cmd1=='O') {
|
||||||
pinMode(pin, OUTPUT);
|
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) {
|
void reportDigitalRead(int pin, boolean raw, boolean dataset) {
|
||||||
// "Dpp0" - "Dpp1"
|
// "Dpp0" - "Dpp1"
|
||||||
// 0 1 2 3
|
// 0 1 2 3
|
||||||
|
@ -87,4 +100,5 @@ void reportAnalogRead(int pin) {
|
||||||
buff[4] += v%10; v /= 10;
|
buff[4] += v%10; v /= 10;
|
||||||
buff[3] += v;
|
buff[3] += v;
|
||||||
Bridge.writeMessage(buff, 7);
|
Bridge.writeMessage(buff, 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue