dino 0.10.0 → 0.11.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/CHANGELOG.md +67 -0
  2. data/README.md +24 -8
  3. data/bin/dino +108 -0
  4. data/dino.gemspec +2 -1
  5. data/examples/button/button.rb +3 -2
  6. data/examples/ethernet.rb +15 -0
  7. data/examples/{ir_receiver.rb → ir_receiver/ir_receiver.rb} +3 -2
  8. data/examples/led/led.rb +3 -3
  9. data/examples/{potentiometer.rb → potentiometer/potentiometer.rb} +4 -6
  10. data/examples/{rgb_led.rb → rgb_led/rgb_led.rb} +4 -6
  11. data/examples/{sensor.rb → sensor/sensor.rb} +5 -6
  12. data/examples/ser2net.rb +31 -0
  13. data/examples/servo/servo.rb +16 -0
  14. data/examples/stepper/stepper.rb +3 -3
  15. data/lib/dino/board.rb +69 -59
  16. data/lib/dino/components/base_component.rb +8 -7
  17. data/lib/dino/components/rgb_led.rb +19 -17
  18. data/lib/dino/components/sensor.rb +2 -2
  19. data/lib/dino/components/servo.rb +8 -5
  20. data/lib/dino/components/stepper.rb +9 -9
  21. data/lib/dino/tx_rx.rb +5 -4
  22. data/lib/dino/tx_rx/base.rb +64 -0
  23. data/lib/dino/tx_rx/serial.rb +44 -0
  24. data/lib/dino/tx_rx/tcp.rb +23 -0
  25. data/lib/dino/version.rb +1 -1
  26. data/spec/lib/board_spec.rb +53 -39
  27. data/spec/lib/components/led_spec.rb +1 -1
  28. data/spec/lib/components/rgb_led_spec.rb +49 -4
  29. data/spec/lib/components/sensor_spec.rb +14 -10
  30. data/spec/lib/components/servo_spec.rb +9 -4
  31. data/spec/lib/components/stepper_spec.rb +2 -2
  32. data/spec/lib/tx_rx/serial_spec.rb +111 -0
  33. data/spec/lib/tx_rx/tcp_spec.rb +37 -0
  34. data/spec/spec_helper.rb +10 -1
  35. data/src/du/du.ino +19 -0
  36. data/src/du_ethernet/du_ethernet.ino +71 -0
  37. data/src/lib/Dino.cpp +257 -0
  38. data/src/lib/Dino.h +85 -0
  39. metadata +25 -17
  40. data/examples/servo.rb +0 -13
  41. data/examples/telnet.rb +0 -28
  42. data/lib/dino/tx_rx/telnet.rb +0 -53
  43. data/lib/dino/tx_rx/usb_serial.rb +0 -69
  44. data/spec/lib/tx_rx/telnet_spec.rb +0 -66
  45. data/spec/lib/tx_rx/usb_serial_spec.rb +0 -101
  46. data/src/du.ino +0 -251
data/src/du.ino DELETED
@@ -1,251 +0,0 @@
1
- #include <Servo.h>
2
-
3
- bool debug = false;
4
-
5
- int index = 0;
6
-
7
- char messageBuffer[12];
8
- char cmd[3];
9
- char pin[3];
10
- char val[4];
11
- char aux[4];
12
-
13
- Servo servo;
14
-
15
- void setup() {
16
- Serial.begin(115200);
17
- }
18
-
19
- void loop() {
20
- while(Serial.available() > 0) {
21
- char x = Serial.read();
22
- if (x == '!') index = 0; // start
23
- else if (x == '.') process(); // end
24
- else messageBuffer[index++] = x;
25
- }
26
- }
27
-
28
- /*
29
- * Deal with a full message and determine function to call
30
- */
31
- void process() {
32
- index = 0;
33
-
34
- strncpy(cmd, messageBuffer, 2);
35
- cmd[2] = '\0';
36
- strncpy(pin, messageBuffer + 2, 2);
37
- pin[2] = '\0';
38
-
39
- if (atoi(cmd) > 90) {
40
- strncpy(val, messageBuffer + 4, 2);
41
- val[2] = '\0';
42
- strncpy(aux, messageBuffer + 6, 3);
43
- aux[3] = '\0';
44
- } else {
45
- strncpy(val, messageBuffer + 4, 3);
46
- val[4] = '\0';
47
- strncpy(aux, messageBuffer + 7, 3);
48
- aux[4] = '\0';
49
- }
50
-
51
- if (debug) {
52
- Serial.println(messageBuffer);
53
- }
54
- int cmdid = atoi(cmd);
55
-
56
- // Serial.println(cmd);
57
- // Serial.println(pin);
58
- // Serial.println(val);
59
- // Serial.println(aux);
60
-
61
- switch(cmdid) {
62
- case 0: sm(pin,val); break;
63
- case 1: dw(pin,val); break;
64
- case 2: dr(pin,val); break;
65
- case 3: aw(pin,val); break;
66
- case 4: ar(pin,val); break;
67
- case 97: handlePing(pin,val,aux); break;
68
- case 98: handleServo(pin,val,aux); break;
69
- case 99: toggleDebug(val); break;
70
- default: break;
71
- }
72
- }
73
-
74
- /*
75
- * Toggle debug mode
76
- */
77
- void toggleDebug(char *val) {
78
- if (atoi(val) == 0) {
79
- debug = false;
80
- Serial.println("goodbye");
81
- } else {
82
- debug = true;
83
- Serial.println("hello");
84
- }
85
- }
86
-
87
- /*
88
- * Set pin mode
89
- */
90
- void sm(char *pin, char *val) {
91
- if (debug) Serial.println("sm");
92
- int p = getPin(pin);
93
- if(p == -1) { if(debug) Serial.println("badpin"); return; }
94
- if (atoi(val) == 0) {
95
- pinMode(p, OUTPUT);
96
- } else {
97
- pinMode(p, INPUT);
98
- }
99
- }
100
-
101
- /*
102
- * Digital write
103
- */
104
- void dw(char *pin, char *val) {
105
- if (debug) Serial.println("dw");
106
- int p = getPin(pin);
107
- if(p == -1) { if(debug) Serial.println("badpin"); return; }
108
- pinMode(p, OUTPUT);
109
- if (atoi(val) == 0) {
110
- digitalWrite(p, LOW);
111
- } else {
112
- digitalWrite(p, HIGH);
113
- }
114
- }
115
-
116
- /*
117
- * Digital read
118
- */
119
- void dr(char *pin, char *val) {
120
- if (debug) Serial.println("dr");
121
- int p = getPin(pin);
122
- if(p == -1) { if(debug) Serial.println("badpin"); return; }
123
- pinMode(p, INPUT);
124
- int oraw = digitalRead(p);
125
- char m[7];
126
- sprintf(m, "%02d::%02d", p,oraw);
127
- Serial.println(m);
128
- }
129
-
130
- /*
131
- * Analog read
132
- */
133
- void ar(char *pin, char *val) {
134
- if(debug) Serial.println("ar");
135
- int p = getPin(pin);
136
- if(p == -1) { if(debug) Serial.println("badpin"); return; }
137
- pinMode(p, INPUT); // don't want to sw
138
- int rval = analogRead(p);
139
- char m[8];
140
- sprintf(m, "%s::%03d", pin, rval);
141
- Serial.println(m);
142
- }
143
-
144
- void aw(char *pin, char *val) {
145
- if(debug) Serial.println("aw");
146
- int p = getPin(pin);
147
- pinMode(p, OUTPUT);
148
- if(p == -1) { if(debug) Serial.println("badpin"); return; }
149
- analogWrite(p,atoi(val));
150
- }
151
-
152
- int getPin(char *pin) { //Converts to A0-A5, and returns -1 on error
153
- int ret = -1;
154
- if(pin[0] == 'A' || pin[0] == 'a') {
155
- switch(pin[1]) {
156
- case '0': ret = A0; break;
157
- case '1': ret = A1; break;
158
- case '2': ret = A2; break;
159
- case '3': ret = A3; break;
160
- case '4': ret = A4; break;
161
- case '5': ret = A5; break;
162
- default: break;
163
- }
164
- } else {
165
- ret = atoi(pin);
166
- if(ret == 0 && (pin[0] != '0' || pin[1] != '0')) {
167
- ret = -1;
168
- }
169
- }
170
- return ret;
171
- }
172
-
173
- /*
174
- * Handle Ping commands
175
- * fire, read
176
- */
177
- void handlePing(char *pin, char *val, char *aux) {
178
- if (debug) Serial.println("ss");
179
- int p = getPin(pin);
180
-
181
- if(p == -1) { if(debug) Serial.println("badpin"); return; }
182
- Serial.println("got signal");
183
-
184
- // 01(1) Fire and Read
185
- if (atoi(val) == 1) {
186
- char m[16];
187
-
188
- pinMode(p, OUTPUT);
189
- digitalWrite(p, LOW);
190
- delayMicroseconds(2);
191
- digitalWrite(p, HIGH);
192
- delayMicroseconds(5);
193
- digitalWrite(p, LOW);
194
-
195
- Serial.println("ping fired");
196
-
197
- pinMode(p, INPUT);
198
- sprintf(m, "%s::read::%08d", pin, pulseIn(p, HIGH));
199
- Serial.println(m);
200
-
201
- delay(50);
202
- }
203
- }
204
-
205
- /*
206
- * Handle Servo commands
207
- * attach, detach, write, read, writeMicroseconds, attached
208
- */
209
- void handleServo(char *pin, char *val, char *aux) {
210
- if (debug) Serial.println("ss");
211
- int p = getPin(pin);
212
- if(p == -1) { if(debug) Serial.println("badpin"); return; }
213
- Serial.println("signal: servo");
214
-
215
- // 00(0) Detach
216
- if (atoi(val) == 0) {
217
- servo.detach();
218
- char m[12];
219
- sprintf(m, "%s::detached", pin);
220
- Serial.println(m);
221
-
222
- // 01(1) Attach
223
- } else if (atoi(val) == 1) {
224
- // servo.attach(p, 750, 2250);
225
- servo.attach(p);
226
- char m[12];
227
- sprintf(m, "%s::attached", pin);
228
- Serial.println(m);
229
-
230
- // 02(2) Write
231
- } else if (atoi(val) == 2) {
232
- Serial.println("writing to servo");
233
- Serial.println(atoi(aux));
234
- // Write to servo
235
- servo.write(atoi(aux));
236
- delay(15);
237
-
238
- // TODO: Experiment with microsecond pulses
239
- // digitalWrite(pin, HIGH); // start the pulse
240
- // delayMicroseconds(pulseWidth); // pulse width
241
- // digitalWrite(pin, LOW); // stop the pulse
242
-
243
- // 03(3) Read
244
- } else if (atoi(val) == 3) {
245
- Serial.println("reading servo");
246
- int sval = servo.read();
247
- char m[13];
248
- sprintf(m, "%s::read::%03d", pin, sval);
249
- Serial.println(m);
250
- }
251
- }