Skip to content

Commit 0de0488

Browse files
author
harbaum
committed
Release 0.0.14
1 parent 2efda69 commit 0de0488

File tree

7 files changed

+272
-50
lines changed

7 files changed

+272
-50
lines changed

ftduino/libraries/WebUSB/examples/IoServer/JsonParser.cpp

Lines changed: 61 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ extern WebUSB WebUSBSerial;
2121
#endif
2222

2323
// generic JSON error codes
24-
#define ERR_UNEXP_STATE 1 // unexpected state
25-
#define ERR_EXP_OBJ 2 // expecting object
26-
#define ERR_EXP_STR 3 // expecting string
27-
#define ERR_EXP_SEP 4 // expecting ':'
28-
#define ERR_UNEXP_SUB 5 // unexpected substate
29-
#define ERR_UNEXP_ESTR 6 // unexpected state at end of string
30-
#define ERR_UNEXP_CONT 7 // unexpected continuation
31-
#define ERR_UNEXP_VAL 8 // unexpected value
32-
#define ERR_UNEXP_ACONT 9 // unexpected array continuation
24+
#define ERR_UNEXP_STATE 1 // unexpected state
25+
#define ERR_EXP_OBJ 2 // expecting object
26+
#define ERR_EXP_STR 3 // expecting string
27+
#define ERR_EXP_SEP 4 // expecting ':'
28+
#define ERR_UNEXP_SUB 5 // unexpected substate
29+
#define ERR_UNEXP_ESTR 6 // unexpected state at end of string
30+
#define ERR_UNEXP_CONT 7 // unexpected continuation
31+
#define ERR_UNEXP_VAL 8 // unexpected value
32+
#define ERR_UNEXP_ACONT 9 // unexpected array continuation
3333

3434
// ftDuino specific errors
3535
#define ERR_UNK_CMD 10 // unknown command
@@ -40,6 +40,7 @@ extern WebUSB WebUSBSerial;
4040
#define ERR_INV_MODE 15 // mode invalid for port
4141
#define ERR_INT 16 // internal error
4242
#define ERR_ILL_REQ 17 // illegal get request
43+
#define ERR_ILL_TYPE 18 // illegal (counter) type specification
4344

4445
void JsonParser::reply_error(char id) {
4546
#ifdef ARDUINO
@@ -79,6 +80,7 @@ void JsonParser::cmd_reset(void) {
7980
cmd = CMD_NONE;
8081
mode = MODE_NONE;
8182
parm = PARM_NONE;
83+
type = TYPE_NONE;
8284
req = REQ_NONE;
8385
port.type = port::PORT_NONE;
8486
value.valid = false;
@@ -94,6 +96,12 @@ void JsonParser::reset(void) {
9496
cmd_reset();
9597

9698
#ifdef ARDUINO
99+
// all counter inputs trigger on falling edge and clear them
100+
for(uint8_t c=0;c<4;c++) {
101+
ftduino.counter_set_mode(Ftduino::C1+c, Ftduino::C_EDGE_FALLING);
102+
ftduino.counter_clear(Ftduino::C1+c);
103+
}
104+
97105
// reset all ftduino ports
98106
digitalWrite(LED_BUILTIN, LOW);
99107
for(uint8_t i=0;i<8;i++)
@@ -143,6 +151,8 @@ void JsonParser::check_name(void) {
143151
parm = PARM_VALUE;
144152
else if(strcmp(substate_value.value.str, "mode") == 0)
145153
parm = PARM_MODE;
154+
else if(strcmp(substate_value.value.str, "type") == 0)
155+
parm = PARM_TYPE;
146156
else
147157
reply_error(ERR_UNK_PARM);
148158
}
@@ -161,6 +171,18 @@ void JsonParser::check_value(void) {
161171
lowercase_str(); // value string are all case insensitive
162172

163173
if(cmd == CMD_GET) {
174+
175+
if((depth == 1) && parm == PARM_TYPE) {
176+
printf("PARM TYPE %s\n", substate_value.value.str);
177+
178+
if(startsWith(substate_value.value.str, "state"))
179+
type = TYPE_STATE;
180+
else if(startsWith(substate_value.value.str, "counter"))
181+
type = TYPE_COUNTER;
182+
else
183+
reply_error(ERR_ILL_TYPE);
184+
}
185+
164186
if((depth == 1) && (parm == PARM_PORT)) {
165187
port.type = port::PORT_NONE;
166188
port.index = substate_value.value.str[1] -'0' - 1;
@@ -345,6 +367,26 @@ void JsonParser::cmd_complete(void) {
345367
#endif
346368
}
347369

370+
if(port.type == port::PORT_C) {
371+
if((type == TYPE_NONE) || (type == TYPE_STATE)) {
372+
#ifdef ARDUINO
373+
uint16_t v = ftduino.counter_get_state(Ftduino::C1 + port.index);
374+
char port_name[3] = { 'C', (char)('1' + port.index), 0 };
375+
reply_value(port_name, true, v);
376+
#else
377+
printf("get counter state %d\n", port.index);
378+
#endif
379+
} else if(type == TYPE_COUNTER) {
380+
#ifdef ARDUINO
381+
uint16_t v = ftduino.counter_get(Ftduino::C1 + port.index);
382+
char port_name[3] = { 'C', (char)('1' + port.index), 0 };
383+
reply_value(port_name, false, v);
384+
#else
385+
printf("get counter value %d\n", port.index);
386+
#endif
387+
}
388+
}
389+
348390
if(req == REQ_DEVS) {
349391
#ifdef ARDUINO
350392
// currently only one master is supported
@@ -363,7 +405,7 @@ void JsonParser::cmd_complete(void) {
363405
if(req == REQ_VER) {
364406
#ifdef ARDUINO
365407
// currently only one master is supported
366-
Serial.print("{ \"version\": \"0.9.0\" }");
408+
Serial.print("{ \"version\": \"0.9.1\" }");
367409
Serial.flush();
368410
#else
369411
printf("Version request\n");
@@ -389,6 +431,14 @@ void JsonParser::cmd_complete(void) {
389431
}
390432
break;
391433

434+
case port::PORT_C:
435+
#ifdef ARDUINO
436+
ftduino.counter_clear(Ftduino::C1+port.index);
437+
#else
438+
printf("setting counter port\n");
439+
#endif
440+
break;
441+
392442
// act according to output set commands
393443
case port::PORT_O:
394444
if(mode != MODE_NONE) {
@@ -439,7 +489,7 @@ void JsonParser::cmd_complete(void) {
439489
reply_error(ERR_INV_MODE);
440490
}
441491
break;
442-
492+
443493
// act according to output set commands
444494
case port::PORT_M:
445495
if(mode != MODE_NONE) {

ftduino/libraries/WebUSB/examples/IoServer/JsonParser.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ class JsonParser
4141
MODE_LEFT, MODE_RIGHT, MODE_BRAKE, // M1-M4 motor modes
4242
} mode;
4343
enum { PARM_NONE,
44-
PARM_PORT, PARM_VALUE, PARM_MODE,
44+
PARM_PORT, PARM_VALUE, PARM_MODE, PARM_TYPE,
4545
} parm;
4646
enum { REQ_NONE,
4747
REQ_DEVS, REQ_VER
4848
} req;
49+
enum { TYPE_NONE, TYPE_STATE, TYPE_COUNTER,
50+
} type;
4951
struct port {
5052
enum { PORT_NONE, PORT_I, PORT_C, PORT_O, PORT_M, PORT_LED } type:3;
5153
uint8_t index:5;

package_ftduino_index.json

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,6 @@
99
"online": "http://ftduino.de"
1010
},
1111
"platforms": [
12-
{
13-
"name": "ftDuino",
14-
"architecture": "avr",
15-
"version": "0.0.6",
16-
"category": "ftDuino",
17-
"url": "https://raw.githubusercontent.com/harbaum/ftduino/master/releases/0.0.6/ftduino-0.0.6.zip",
18-
"archiveFileName": "ftduino-0.0.6.zip",
19-
"checksum": "SHA-256:60e4b353b2802d4f1cb25eebbe35941e179a1b852dc75f6a7c7702126df8f8c7",
20-
"size": "144406",
21-
"help": {
22-
"online": "http://ftduino.de/issues"
23-
},
24-
"boards": [
25-
{
26-
"name": "ftDuino fischertechnik compatible controller"
27-
}
28-
]
29-
},
3012
{
3113
"name": "ftDuino",
3214
"architecture": "avr",
@@ -152,6 +134,24 @@
152134
"name": "ftDuino fischertechnik compatible controller"
153135
}
154136
]
137+
},
138+
{
139+
"name": "ftDuino",
140+
"architecture": "avr",
141+
"version": "0.0.14",
142+
"category": "ftDuino",
143+
"url": "https://raw.githubusercontent.com/harbaum/ftduino/master/releases/0.0.14/ftduino-0.0.14.zip",
144+
"archiveFileName": "ftduino-0.0.14.zip",
145+
"checksum": "SHA-256:ce10bcc6436c81c98954134f84168f56554a1ae873c74acf7c16b3cb407aa79b",
146+
"size": "207084",
147+
"help": {
148+
"online": "http://ftduino.de/issues"
149+
},
150+
"boards": [
151+
{
152+
"name": "ftDuino fischertechnik compatible controller"
153+
}
154+
]
155155
}
156156
],
157157
"tools": []

releases/0.0.14/ftduino-0.0.14.zip

202 KB
Binary file not shown.

releases/0.0.6/ftduino-0.0.6.zip

-141 KB
Binary file not shown.

webusb/scratch3/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.map

0 commit comments

Comments
 (0)