Skip to content

Commit

Permalink
Release 0.0.14
Browse files Browse the repository at this point in the history
  • Loading branch information
harbaum committed Apr 2, 2019
1 parent 2efda69 commit 0de0488
Show file tree
Hide file tree
Showing 7 changed files with 272 additions and 50 deletions.
72 changes: 61 additions & 11 deletions ftduino/libraries/WebUSB/examples/IoServer/JsonParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ extern WebUSB WebUSBSerial;
#endif

// generic JSON error codes
#define ERR_UNEXP_STATE 1 // unexpected state
#define ERR_EXP_OBJ 2 // expecting object
#define ERR_EXP_STR 3 // expecting string
#define ERR_EXP_SEP 4 // expecting ':'
#define ERR_UNEXP_SUB 5 // unexpected substate
#define ERR_UNEXP_ESTR 6 // unexpected state at end of string
#define ERR_UNEXP_CONT 7 // unexpected continuation
#define ERR_UNEXP_VAL 8 // unexpected value
#define ERR_UNEXP_ACONT 9 // unexpected array continuation
#define ERR_UNEXP_STATE 1 // unexpected state
#define ERR_EXP_OBJ 2 // expecting object
#define ERR_EXP_STR 3 // expecting string
#define ERR_EXP_SEP 4 // expecting ':'
#define ERR_UNEXP_SUB 5 // unexpected substate
#define ERR_UNEXP_ESTR 6 // unexpected state at end of string
#define ERR_UNEXP_CONT 7 // unexpected continuation
#define ERR_UNEXP_VAL 8 // unexpected value
#define ERR_UNEXP_ACONT 9 // unexpected array continuation

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

void JsonParser::reply_error(char id) {
#ifdef ARDUINO
Expand Down Expand Up @@ -79,6 +80,7 @@ void JsonParser::cmd_reset(void) {
cmd = CMD_NONE;
mode = MODE_NONE;
parm = PARM_NONE;
type = TYPE_NONE;
req = REQ_NONE;
port.type = port::PORT_NONE;
value.valid = false;
Expand All @@ -94,6 +96,12 @@ void JsonParser::reset(void) {
cmd_reset();

#ifdef ARDUINO
// all counter inputs trigger on falling edge and clear them
for(uint8_t c=0;c<4;c++) {
ftduino.counter_set_mode(Ftduino::C1+c, Ftduino::C_EDGE_FALLING);
ftduino.counter_clear(Ftduino::C1+c);
}

// reset all ftduino ports
digitalWrite(LED_BUILTIN, LOW);
for(uint8_t i=0;i<8;i++)
Expand Down Expand Up @@ -143,6 +151,8 @@ void JsonParser::check_name(void) {
parm = PARM_VALUE;
else if(strcmp(substate_value.value.str, "mode") == 0)
parm = PARM_MODE;
else if(strcmp(substate_value.value.str, "type") == 0)
parm = PARM_TYPE;
else
reply_error(ERR_UNK_PARM);
}
Expand All @@ -161,6 +171,18 @@ void JsonParser::check_value(void) {
lowercase_str(); // value string are all case insensitive

if(cmd == CMD_GET) {

if((depth == 1) && parm == PARM_TYPE) {
printf("PARM TYPE %s\n", substate_value.value.str);

if(startsWith(substate_value.value.str, "state"))
type = TYPE_STATE;
else if(startsWith(substate_value.value.str, "counter"))
type = TYPE_COUNTER;
else
reply_error(ERR_ILL_TYPE);
}

if((depth == 1) && (parm == PARM_PORT)) {
port.type = port::PORT_NONE;
port.index = substate_value.value.str[1] -'0' - 1;
Expand Down Expand Up @@ -345,6 +367,26 @@ void JsonParser::cmd_complete(void) {
#endif
}

if(port.type == port::PORT_C) {
if((type == TYPE_NONE) || (type == TYPE_STATE)) {
#ifdef ARDUINO
uint16_t v = ftduino.counter_get_state(Ftduino::C1 + port.index);
char port_name[3] = { 'C', (char)('1' + port.index), 0 };
reply_value(port_name, true, v);
#else
printf("get counter state %d\n", port.index);
#endif
} else if(type == TYPE_COUNTER) {
#ifdef ARDUINO
uint16_t v = ftduino.counter_get(Ftduino::C1 + port.index);
char port_name[3] = { 'C', (char)('1' + port.index), 0 };
reply_value(port_name, false, v);
#else
printf("get counter value %d\n", port.index);
#endif
}
}

if(req == REQ_DEVS) {
#ifdef ARDUINO
// currently only one master is supported
Expand All @@ -363,7 +405,7 @@ void JsonParser::cmd_complete(void) {
if(req == REQ_VER) {
#ifdef ARDUINO
// currently only one master is supported
Serial.print("{ \"version\": \"0.9.0\" }");
Serial.print("{ \"version\": \"0.9.1\" }");
Serial.flush();
#else
printf("Version request\n");
Expand All @@ -389,6 +431,14 @@ void JsonParser::cmd_complete(void) {
}
break;

case port::PORT_C:
#ifdef ARDUINO
ftduino.counter_clear(Ftduino::C1+port.index);
#else
printf("setting counter port\n");
#endif
break;

// act according to output set commands
case port::PORT_O:
if(mode != MODE_NONE) {
Expand Down Expand Up @@ -439,7 +489,7 @@ void JsonParser::cmd_complete(void) {
reply_error(ERR_INV_MODE);
}
break;

// act according to output set commands
case port::PORT_M:
if(mode != MODE_NONE) {
Expand Down
4 changes: 3 additions & 1 deletion ftduino/libraries/WebUSB/examples/IoServer/JsonParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ class JsonParser
MODE_LEFT, MODE_RIGHT, MODE_BRAKE, // M1-M4 motor modes
} mode;
enum { PARM_NONE,
PARM_PORT, PARM_VALUE, PARM_MODE,
PARM_PORT, PARM_VALUE, PARM_MODE, PARM_TYPE,
} parm;
enum { REQ_NONE,
REQ_DEVS, REQ_VER
} req;
enum { TYPE_NONE, TYPE_STATE, TYPE_COUNTER,
} type;
struct port {
enum { PORT_NONE, PORT_I, PORT_C, PORT_O, PORT_M, PORT_LED } type:3;
uint8_t index:5;
Expand Down
36 changes: 18 additions & 18 deletions package_ftduino_index.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,6 @@
"online": "http://ftduino.de"
},
"platforms": [
{
"name": "ftDuino",
"architecture": "avr",
"version": "0.0.6",
"category": "ftDuino",
"url": "https://raw.githubusercontent.com/harbaum/ftduino/master/releases/0.0.6/ftduino-0.0.6.zip",
"archiveFileName": "ftduino-0.0.6.zip",
"checksum": "SHA-256:60e4b353b2802d4f1cb25eebbe35941e179a1b852dc75f6a7c7702126df8f8c7",
"size": "144406",
"help": {
"online": "http://ftduino.de/issues"
},
"boards": [
{
"name": "ftDuino fischertechnik compatible controller"
}
]
},
{
"name": "ftDuino",
"architecture": "avr",
Expand Down Expand Up @@ -152,6 +134,24 @@
"name": "ftDuino fischertechnik compatible controller"
}
]
},
{
"name": "ftDuino",
"architecture": "avr",
"version": "0.0.14",
"category": "ftDuino",
"url": "https://raw.githubusercontent.com/harbaum/ftduino/master/releases/0.0.14/ftduino-0.0.14.zip",
"archiveFileName": "ftduino-0.0.14.zip",
"checksum": "SHA-256:ce10bcc6436c81c98954134f84168f56554a1ae873c74acf7c16b3cb407aa79b",
"size": "207084",
"help": {
"online": "http://ftduino.de/issues"
},
"boards": [
{
"name": "ftDuino fischertechnik compatible controller"
}
]
}
],
"tools": []
Expand Down
Binary file added releases/0.0.14/ftduino-0.0.14.zip
Binary file not shown.
Binary file removed releases/0.0.6/ftduino-0.0.6.zip
Binary file not shown.
1 change: 1 addition & 0 deletions webusb/scratch3/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.map
Loading

0 comments on commit 0de0488

Please sign in to comment.