diff --git a/tfrog-motordriver/communication.c b/tfrog-motordriver/communication.c index ca87e88..e748393 100644 --- a/tfrog-motordriver/communication.c +++ b/tfrog-motordriver/communication.c @@ -119,6 +119,11 @@ int hextoi(char* buf) ret *= 16; ret += *buf - 'A' + 0xA; } + else if ('a' <= *buf && *buf <= 'f') + { + ret *= 16; + ret += *buf - 'a' + 0xA; + } buf++; } return ret; @@ -1033,6 +1038,12 @@ int extended_command_analyze(char* data) send("BUZ_LVL"); itoa10(val, saved_param.buz_lvl); send(val); + send("; \nINITIODIR:"); + nhex(val, saved_param.io_dir, 2); + send(val); + send("; \nINITIODATA:"); + nhex(val, saved_param.io_data, 2); + send(val); send("; \n\n"); } else if (strstr(data, "$LOCKPARAM") == data) @@ -1237,6 +1248,20 @@ int extended_command_analyze(char* data) send(data); send("\n00P\n\n"); } + else if (strstr(data, "$SETINITIODIR") == data) + { + saved_param.io_dir = hextoi(data + 13); + + send(data); + send("\n00P\n\n"); + } + else if (strstr(data, "$SETINITIODATA") == data) + { + saved_param.io_data = hextoi(data + 14); + + send(data); + send("\n00P\n\n"); + } else if (strstr(data, "$EEPROMSAVE") == data) { if (EEPROM_Write(0, &saved_param, sizeof(saved_param)) < 0) diff --git a/tfrog-motordriver/eeprom.h b/tfrog-motordriver/eeprom.h index 58657ee..55d221d 100644 --- a/tfrog-motordriver/eeprom.h +++ b/tfrog-motordriver/eeprom.h @@ -37,6 +37,8 @@ typedef struct _Tfrog_EEPROM_data unsigned char buz_lvl; unsigned char high_frequency_encoder; unsigned char rely_hall; + unsigned char io_dir; + unsigned char io_data; char __endbyte; // must be at the end of the struct to detect actual struct size } Tfrog_EEPROM_data; @@ -64,6 +66,8 @@ typedef struct _Tfrog_EEPROM_data 0, \ 0, \ 0, \ + 0, \ + 0, \ } #define TFROG_EEPROM_DATA_TEXT 0 diff --git a/tfrog-motordriver/main.c b/tfrog-motordriver/main.c index 64588d3..a095cc9 100644 --- a/tfrog-motordriver/main.c +++ b/tfrog-motordriver/main.c @@ -586,6 +586,10 @@ int main() { THEVA.GENERAL.ENCODER.HFREQ = 0; } + + driver_state.io_dir = saved_param.io_dir; + set_io_dir(saved_param.io_dir); + set_io_data(saved_param.io_data); } // Configure USB vbus pin