Skip to content

Commit

Permalink
Fixes #23: Implement menu to set node ID > 9
Browse files Browse the repository at this point in the history
  • Loading branch information
ataffanel committed Jan 18, 2018
1 parent 84289ff commit 9da3a6c
Showing 1 changed file with 47 additions and 2 deletions.
49 changes: 47 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ int _write (int fd, const void *buf, size_t count)

static void handleSerialInput(char ch) {
bool configChanged = true;
static enum menu_e {mainMenu, modeMenu} currentMenu = mainMenu;
static enum menu_e {mainMenu, modeMenu, idMenu} currentMenu = mainMenu;
static unsigned int tempId = 0;

switch (currentMenu) {
case mainMenu:
Expand All @@ -220,6 +221,13 @@ static void handleSerialInput(char ch) {
case '9':
changeAddress(ch - '0');
break;
case 'i':
printf("Type new node ID then enter: ");
fflush(stdout);
currentMenu = idMenu;
configChanged = false;
tempId = 0;
break;
case 'a': changeMode(MODE_ANCHOR); break;
case 't': changeMode(MODE_TAG); break;
case 's': changeMode(MODE_SNIFFER); break;
Expand Down Expand Up @@ -272,6 +280,42 @@ static void handleSerialInput(char ch) {
break;
}
break;
case idMenu:
switch(ch) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
tempId *= 10;
tempId += ch - '0';
putchar(ch);
fflush(stdout);
configChanged = false;
break;
case '\n':
case '\r':
printf("\r\n");
fflush(stdout);
if (tempId < 256) {
printf("Setting node ID to %d\r\n", tempId);
changeAddress(tempId);
} else {
printf("Wrong ID '%d', the ID should be between 0 and 255\r\n", tempId);
configChanged = false;
}
currentMenu = mainMenu;
break;
default:
configChanged = false;
break;
}
break;
}

if (configChanged) {
Expand Down Expand Up @@ -355,7 +399,8 @@ static void printMode() {
static void help() {
printf("Help\r\n");
printf("-------------------\r\n");
printf("0-9 - set address\r\n");
printf("0-9 - set address (node ID)\r\n");
printf("i - set node ID from 0 to 255\r\n");
printf("a - anchor mode\r\n");
printf("t - tag mode\r\n");
printf("s - sniffer mode\r\n");
Expand Down

0 comments on commit 9da3a6c

Please sign in to comment.