Permalink
Browse files

Adding back in the wrapped send function.

  • Loading branch information...
voodootikigod committed Jan 24, 2014
1 parent 5656d99 commit c5899247220a87968e440aba16336d9e7c37cadf
Showing with 16 additions and 18 deletions.
  1. +16 −18 firmware/firmware.cpp
View
@@ -49,35 +49,33 @@ void setup() {
+void send(int action, int pin, int value) {
+ if (previous[pin] != value) {
+ client.write(action);
+ client.write(pin);
+ client.write(value);
+ }
+ previous[pin] = value;
+}
void report() {
for (int i = 0; i < 20; i++) {
if (reading[i]) {
- int dr = (reading[i] & 1);
- int ar = (reading[i] & 2);
-
- if (i < 10 && dr) {
- // Digital pins are 0-9 and can only do digital read
- client.write(0x03);
- client.write(i);
- client.write(digitalRead(i));
+ if (i < 10 && (reading[i] & 1)) {
+ send(0x03, i, digitalRead(i));
} else {
- if (dr) {
- client.write(0x03);
- client.write(i);
- client.write(digitalRead(i));
- }
- if (ar) {
- client.write(0x04);
- client.write(i);
- client.write(analogRead(i));
+ if (reading[i] & 1) {
+ send(0x03, i, digitalRead(i));
+ } else {
+ if (reading[i] & 2) {
+ send(0x04, i, analogRead(i));
+ }
}
}
}
}
}
-
void loop() {
report();

0 comments on commit c589924

Please sign in to comment.