Skip to content

Commit 51e1a06

Browse files
authored
Merge pull request #709 from entrylabs/develop-hw
1.9.50
2 parents 1125816 + 9b8aa06 commit 51e1a06

19 files changed

+5691
-5327
lines changed

app/firmwares/etkit.hex

+738-1,273
Large diffs are not rendered by default.

app/firmwares/etkit_middle.hex

+871
Large diffs are not rendered by default.

app/firmwares/roborobo_cube.hex

+1,671-2,013
Large diffs are not rendered by default.

app/firmwares/roborobo_robokit_rs.hex

+1,845-1,852
Large diffs are not rendered by default.

app/modules/etkit.js

+102-150
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,37 @@
11
function Module() {
22
this.sp = null;
33
this.sensorTypes = {
4-
ALIVE:0,
5-
DIGITAL:1,
6-
ANALOG:2,
7-
DHT_PIN:3,
8-
LCD:4,
9-
CO2: 5,
10-
OLED: 6,
11-
TIMER:8,
12-
READ_BLUETOOTH: 9,
13-
WRITE_BLUETOOTH: 10,
4+
ALIVE: 0,
5+
DIGITAL: 1,
6+
ANALOG: 2,
7+
DHT_PIN: 3,
8+
LCD: 4,
9+
PWM: 5,
10+
SERVO_PIN: 6,
11+
PULSEIN: 7,
12+
ULTRASONIC: 8,
13+
TIMER: 9,
14+
WRITE_SEG: 10,
15+
READ_SEG: 13,
16+
READ_BLUETOOTH: 11,
17+
WRITE_BLUETOOTH: 12,
18+
GAS: 14
1419
};
1520
this.actionTypes = {
1621
GET:1,
1722
SET:2,
1823
MODULE:3,
19-
RESET:4,
24+
RESET:4
2025
};
2126
this.sensorValueSize = {
2227
FLOAT:2,
2328
SHORT:3,
24-
STRING:4,
29+
STRING:4
2530
};
2631
this.digitalPortTimeList = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
2732
this.sensorData = {
33+
PULSEIN: {},
34+
ULTRASONIC: 0,
2835
DIGITAL: {
2936
'0': 0,
3037
'1': 0,
@@ -50,14 +57,12 @@ function Module() {
5057
'5': 0,
5158
},
5259
DHT_PIN: 0,
53-
CO2: 0,
5460
TIMER: 0,
5561
READ_BLUETOOTH: 0,
62+
READ_SEG: 0,
5663
};
57-
this.defaultOutput = {
58-
};
59-
this.recentCheckData = {
60-
};
64+
this.defaultOutput = {};
65+
this.recentCheckData = {};
6166
this.sendBuffers = [];
6267
this.lastTime = 0;
6368
this.lastSendTime = 0;
@@ -72,7 +77,8 @@ Module.prototype.setSerialPort = function (sp) {
7277
this.sp = sp;
7378
};
7479
Module.prototype.requestInitialData = function() {
75-
return this.makeSensorReadBuffer(this.sensorTypes.ANALOG, 0);
80+
//return this.makeSensorReadBuffer(this.sensorTypes.ANALOG, 0);
81+
return true;
7682
};
7783
Module.prototype.checkInitialData = function(data, config) {
7884
return true;
@@ -153,24 +159,33 @@ Module.prototype.handleLocalData = function(data) {
153159

154160
switch(type) {
155161
case self.sensorTypes.DIGITAL: {
156-
self.sensorData.DIGITAL[port] = value;
162+
self.sensorData.DIGITAL[port] = value;
157163
break;
158164
}
159165
case self.sensorTypes.ANALOG: {
160-
self.sensorData.ANALOG[port] = value;
166+
self.sensorData.ANALOG[port] = value;
161167
break;
162168
}
163-
164169
case self.sensorTypes.DHT_PIN: {
165-
self.sensorData.DHT_PIN = value;
170+
self.sensorData.DHT_PIN = value;
171+
break;
172+
}
173+
case self.sensorTypes.PULSEIN: {
174+
self.sensorData.PULSEIN[port] = value;
175+
break;
176+
}
177+
case self.sensorTypes.ULTRASONIC: {
178+
self.sensorData.ULTRASONIC = value;
166179
break;
167180
}
168-
169181
case self.sensorTypes.READ_BLUETOOTH: {
170182
self.sensorData.READ_BLUETOOTH = value;
171183
break;
172184
}
173-
185+
case self.sensorTypes.READ_SEG: {
186+
self.sensorData.READ_SEG = value;
187+
break;
188+
}
174189
case self.sensorTypes.TIMER: {
175190
self.sensorData.TIMER = value;
176191
break;
@@ -202,105 +217,81 @@ Module.prototype.requestLocalData = function() {
202217
Module.prototype.makeSensorReadBuffer = function(device, port, data) {
203218
let buffer;
204219
const dummy = new Buffer([10]);
205-
if(device == this.sensorTypes.DHT_PIN) {
206-
buffer = new Buffer([255, 85, 7, sensorIdx, this.actionTypes.GET, device, port, 10]);
220+
if (device == this.sensorTypes.DIGITAL) {
221+
if (!data) {
222+
buffer = new Buffer([255, 85, 6, sensorIdx, this.actionTypes.GET, device, port, 0, 10]);
223+
} else {
224+
buffer = new Buffer([255, 85, 6, sensorIdx, this.actionTypes.GET, device, port, data, 10]);
225+
}
226+
}
227+
/*
228+
else if(device == this.sensorTypes.ANALOG) {
229+
if (!data) {
230+
buffer = new Buffer([255, 85, 6, sensorIdx, this.actionTypes.GET, device, port, 0, 10]);
231+
} else {
232+
buffer = new Buffer([255, 85, 6, sensorIdx, this.actionTypes.GET, device, port, data, 10]);
233+
}
234+
}
235+
*/
236+
else if(device == this.sensorTypes.DHT_PIN) {
237+
//buffer = new Buffer([255, 85, 6, sensorIdx, this.actionTypes.GET, device, port, 10]);
238+
239+
if (!data) {
240+
buffer = new Buffer([255, 85, 6, sensorIdx, this.actionTypes.GET, device, port, 0, 10]);
241+
} else {
242+
buffer = new Buffer([255, 85, 6, sensorIdx, this.actionTypes.GET, device, port, data, 10]);
243+
}
244+
245+
}
246+
else if (device == this.sensorTypes.ULTRASONIC) {
247+
buffer = new Buffer([255, 85, 6, sensorIdx, this.actionTypes.GET, device, port[0], port[1], 10]);
207248
}
208249
else if (device == this.sensorTypes.READ_BLUETOOTH) {
209250
buffer = new Buffer([255, 85, 5, sensorIdx, this.actionTypes.GET, device, port, 10]);
210251
}
252+
else if (device == this.sensorTypes.READ_SEG) {
253+
if (!data) {
254+
buffer = new Buffer([255, 85, 6, sensorIdx, this.actionTypes.GET, device, port, 0, 10]);
255+
} else {
256+
buffer = new Buffer([255, 85, 5, sensorIdx, this.actionTypes.GET, device, port, 10]);
257+
}
258+
259+
}
211260
else if (!data) {
212261
buffer = new Buffer([255, 85, 5, sensorIdx, this.actionTypes.GET, device, port, 10]);
262+
213263
}
214264
else {
215265
value = new Buffer(2);
216266
value.writeInt16LE(data);
217267
buffer = new Buffer([255, 85, 7, sensorIdx, this.actionTypes.GET, device, port, 10]);
218-
buffer = Buffer.concat([buffer, value, dummy]);
268+
269+
buffer = Buffer.concat([buffer, value, dummy]);
270+
219271
}
220272

221273
sensorIdx++;
222274
if(sensorIdx > 254) {
223275
sensorIdx = 0;
224276
}
225-
277+
226278
return buffer;
227279
};
228280
Module.prototype.makeOutputBuffer = function(device, port, data) {
229281
let buffer;
230282
const value = new Buffer(2);
231283
const dummy = new Buffer([10]);
232284
switch(device) {
285+
case this.sensorTypes.SERVO_PIN:
286+
case this.sensorTypes.PWM:
233287
case this.sensorTypes.DIGITAL: {
234288
value.writeInt16LE(data);
235-
buffer = new Buffer([
236-
255,
237-
85,
238-
6,
239-
sensorIdx,
240-
this.actionTypes.SET,
241-
device,
242-
port,
243-
]);
289+
buffer = new Buffer([255, 85, 6, sensorIdx, this.actionTypes.SET, device, port,]);
244290
buffer = Buffer.concat([buffer, value, dummy]);
245291
break;
246-
247-
}
248-
case this.sensorTypes.WRITE_BLUETOOTH: {
249-
var text0 = new Buffer(2);
250-
var text1 = new Buffer(2);
251-
var text2 = new Buffer(2);
252-
var text3 = new Buffer(2);
253-
var text4 = new Buffer(2);
254-
var text5 = new Buffer(2);
255-
var text6 = new Buffer(2);
256-
var text7 = new Buffer(2);
257-
var text8 = new Buffer(2);
258-
var text9 = new Buffer(2);
259-
var text10 = new Buffer(2);
260-
var text11 = new Buffer(2);
261-
var text12 = new Buffer(2);
262-
var text13 = new Buffer(2);
263-
var text14 = new Buffer(2);
264-
var text15 = new Buffer(2);
265-
if ($.isPlainObject(data)) {
266-
text0.writeInt16LE(data.text0);
267-
text1.writeInt16LE(data.text1);
268-
text2.writeInt16LE(data.text2);
269-
text3.writeInt16LE(data.text3);
270-
text4.writeInt16LE(data.text4);
271-
text5.writeInt16LE(data.text5);
272-
text6.writeInt16LE(data.text6);
273-
text7.writeInt16LE(data.text7);
274-
text8.writeInt16LE(data.text8);
275-
text9.writeInt16LE(data.text9);
276-
text10.writeInt16LE(data.text10);
277-
text11.writeInt16LE(data.text11);
278-
text12.writeInt16LE(data.text12);
279-
text13.writeInt16LE(data.text13);
280-
text14.writeInt16LE(data.text14);
281-
text15.writeInt16LE(data.text15);
282-
} else {
283-
text0.writeInt16LE(0);
284-
text1.writeInt16LE(0);
285-
text2.writeInt16LE(0);
286-
text3.writeInt16LE(0);
287-
text4.writeInt16LE(0);
288-
text5.writeInt16LE(0);
289-
text6.writeInt16LE(0);
290-
text7.writeInt16LE(0);
291-
text8.writeInt16LE(0);
292-
text9.writeInt16LE(0);
293-
text10.writeInt16LE(0);
294-
text11.writeInt16LE(0);
295-
text12.writeInt16LE(0);
296-
text13.writeInt16LE(0);
297-
text14.writeInt16LE(0);
298-
text15.writeInt16LE(0);
299-
}
300-
buffer = new Buffer([255, 85, 36, sensorIdx, this.actionTypes.MODULE, device, port]);
301-
buffer = Buffer.concat([buffer, text0, text1, text2, text3, text4, text5, text6, text7, text8, text9, text10, text11, text12, text13, text14, text15, dummy]);
302-
break;
303292
}
293+
case this.sensorTypes.WRITE_SEG:
294+
case this.sensorTypes.WRITE_BLUETOOTH:
304295
case this.sensorTypes.LCD: {
305296
var text0 = new Buffer(2);
306297
var text1 = new Buffer(2);
@@ -356,70 +347,29 @@ Module.prototype.makeOutputBuffer = function(device, port, data) {
356347
buffer = new Buffer([255, 85, 36, sensorIdx, this.actionTypes.MODULE, device, port]);
357348
buffer = Buffer.concat([buffer, text0, text1, text2, text3, text4, text5, text6, text7, text8, text9, text10, text11, text12, text13, text14, text15, dummy]);
358349
break;
359-
}
360-
case this.sensorTypes.OLED: {
361-
362-
const coordinate_x = new Buffer(2);
363-
const coordinate_y = new Buffer(2);
350+
}
351+
/*
352+
case this.sensorTypes.SEG: {
364353
var text0 = new Buffer(2);
365354
var text1 = new Buffer(2);
366355
var text2 = new Buffer(2);
367356
var text3 = new Buffer(2);
368-
var text4 = new Buffer(2);
369-
var text5 = new Buffer(2);
370-
var text6 = new Buffer(2);
371-
var text7 = new Buffer(2);
372-
var text8 = new Buffer(2);
373-
var text9 = new Buffer(2);
374-
var text10 = new Buffer(2);
375-
var text11 = new Buffer(2);
376-
var text12 = new Buffer(2);
377-
var text13 = new Buffer(2);
378-
var text14 = new Buffer(2);
379-
var text15 = new Buffer(2);
380357
if ($.isPlainObject(data)) {
381-
coordinate_x.writeInt16LE(data.value0);
382-
coordinate_y.writeInt16LE(data.value1);
383-
text0.writeInt16LE(data.text0);
384-
text1.writeInt16LE(data.text1);
385-
text2.writeInt16LE(data.text2);
386-
text3.writeInt16LE(data.text3);
387-
text4.writeInt16LE(data.text4);
388-
text5.writeInt16LE(data.text5);
389-
text6.writeInt16LE(data.text6);
390-
text7.writeInt16LE(data.text7);
391-
text8.writeInt16LE(data.text8);
392-
text9.writeInt16LE(data.text9);
393-
text10.writeInt16LE(data.text10);
394-
text11.writeInt16LE(data.text11);
395-
text12.writeInt16LE(data.text12);
396-
text13.writeInt16LE(data.text13);
397-
text14.writeInt16LE(data.text14);
398-
text15.writeInt16LE(data.text15);
358+
text0.writeInt16LE(data.text0);
359+
text1.writeInt16LE(data.text1);
360+
text2.writeInt16LE(data.text2);
361+
text3.writeInt16LE(data.text3);
399362
} else {
400-
coordinate_x.writeInt16LE(0);
401-
coordinate_y.writeInt16LE(0);
402-
text0.writeInt16LE(0);
403-
text1.writeInt16LE(0);
404-
text2.writeInt16LE(0);
405-
text3.writeInt16LE(0);
406-
text4.writeInt16LE(0);
407-
text5.writeInt16LE(0);
408-
text6.writeInt16LE(0);
409-
text7.writeInt16LE(0);
410-
text8.writeInt16LE(0);
411-
text9.writeInt16LE(0);
412-
text10.writeInt16LE(0);
413-
text11.writeInt16LE(0);
414-
text12.writeInt16LE(0);
415-
text13.writeInt16LE(0);
416-
text14.writeInt16LE(0);
417-
text15.writeInt16LE(0);
363+
text0.writeInt16LE(0);
364+
text1.writeInt16LE(0);
365+
text2.writeInt16LE(0);
366+
text3.writeInt16LE(0);
418367
}
419-
buffer = new Buffer([255, 85, 40, sensorIdx, this.actionTypes.MODULE, device, port]);
420-
buffer = Buffer.concat([buffer, coordinate_x, coordinate_y, text0, text1, text2, text3, text4, text5, text6, text7, text8, text9, text10, text11, text12, text13, text14, text15, dummy]);
368+
buffer = new Buffer([255, 85, 36, sensorIdx, this.actionTypes.MODULE, device, port]);
369+
buffer = Buffer.concat([buffer, text0, text1, text2, text3, dummy]);
421370
break;
422371
}
372+
*/
423373
}
424374
return buffer;
425375
};
@@ -460,6 +410,7 @@ Module.prototype.handleRemoteData = function(handler) {
460410
data: dataObj.data,
461411
};
462412
buffer = Buffer.concat([buffer, self.makeSensorReadBuffer(key, dataObj.port, dataObj.data)]);
413+
463414
}
464415
}
465416
});
@@ -493,13 +444,14 @@ Module.prototype.disconnect = function(connect) {
493444
const self = this;
494445
connect.close();
495446
if (self.sp) {
496-
delete self.sp;
447+
delete self.sp;
497448
}
498449
};
499450

500451
Module.prototype.reset = function() {
501452
this.lastTime = 0;
502453
this.lastSendTime = 0;
454+
this.sensorData.PULSEIN = {};
503455
};
504456

505457
module.exports = new Module();

0 commit comments

Comments
 (0)