static void process_cmds(void) { char line[VCHANNEL_MAX_LINE]; int size; char *p, *tok1, *tok2, *tok3, *tok4, *tok5, *tok6, *tok7, *tok8; while ((size = g_vchannel_read_fn(line, sizeof(line))) >= 0) { p = unescape(line); tok1 = get_token(&p); tok2 = get_token(&p); tok3 = get_token(&p); tok4 = get_token(&p); tok5 = get_token(&p); tok6 = get_token(&p); tok7 = get_token(&p); tok8 = get_token(&p); if (strcmp(tok1, "SYNC") == 0) do_sync(); else if (strcmp(tok1, "STATE") == 0) do_state(strtoul(tok2, NULL, 0), long_to_hwnd(strtoul(tok3, NULL, 0)), strtol(tok4, NULL, 0)); else if (strcmp(tok1, "POSITION") == 0) do_position(strtoul(tok2, NULL, 0), long_to_hwnd(strtoul(tok3, NULL, 0)), strtol(tok4, NULL, 0), strtol(tok5, NULL, 0), strtol(tok6, NULL, 0), strtol(tok7, NULL, 0)); else if (strcmp(tok1, "ZCHANGE") == 0) do_zchange(strtoul(tok2, NULL, 0), long_to_hwnd(strtoul(tok3, NULL, 0)), long_to_hwnd(strtoul(tok4, NULL, 0))); else if (strcmp(tok1, "FOCUS") == 0) do_focus(strtoul(tok2, NULL, 0), long_to_hwnd(strtoul(tok3, NULL, 0))); else if (strcmp(tok1, "DESTROY") == 0) do_destroy(long_to_hwnd(strtoul(tok3, NULL, 0))); else if (strcmp(tok1, "SPAWN") == 0) do_spawn(strtoul(tok2, NULL, 0), tok3); else if (strcmp(tok1, "PERSISTENT") == 0) do_persistent(strtoul(tok2, NULL, 0), strtol(tok3, NULL, 0)); free(p); } }
int main() { int button = LOW; int button_old = LOW; int state = STATE_LEDOFF; init(); pinMode(LED, OUTPUT); pinMode(BUTTON, INPUT); while(1) { button = digitalRead(BUTTON); state = do_state(button, button_old, state); button_old = button; delay(DELAY_MS); do_action(state); } return 0; }
int main() { struct state_dat state = { STATE_LEDOFF, 128, 0 }; int button = LOW; int button_old = LOW; init(); pinMode(LED, OUTPUT); pinMode(BUTTON, INPUT); while (1) { button = digitalRead(BUTTON); do_state(button, button_old, &state); button_old = button; delay(DELAY_MS); do_action(&state); } return 0; }