int cmd_settimer(int argc, char *argv[], FILE *ostrm) { #else int cmd_settimer(int argc, char *argv[]) { #endif int res; int count; if (argc != 2) { res = efputs("usage: settimer [count]\r\n", ostrm); if (res == EOF) { return WRITE_ERROR; } return WRONG_NUMBER_ARGS; } count = myAtoi(argv[1]); if (count < 0 || count > 65535) { res = efputs("Duration must be between 0 and 65535\r\n", ostrm); if (res == EOF) { return WRITE_ERROR; } return INVALID_INPUT; } interrupt_fired = 0; svc_setTimer(count, my_timer_action); while(!interrupt_fired) { ; } efputs("Interrupt Fired\r\n", STDOUT); efflush(ostrm); return SUCCESS; }
int openFiles(int argc, char **argv) { uint32_t pid; char msg[128]; Stream *lcd; pid = getCurrentPID(); lcd = svc_myFopen("/dev/lcd/lcd"); svc_myFopen("/dev/button/sw1"); svc_myCreate("dev/fs/data"); svc_myFopen("/dev/fs/data"); sprintf(msg, "Hello from PID %d. Leaving 3 files open, will be closed on kill.\r\n", (int) pid); efputs(msg, STDOUT); efflush(STDOUT); svc_myFputs(msg, lcd); sprintf(msg, "About to kill PID %d.\r\n", (int) pid); efputs(msg, STDOUT); efflush(STDOUT); svc_myFputs(msg, lcd); /* kill me */ svc_myKill(pid); return 0; }
int cmd_process_demo(int argc, char *argv[], FILE *ostrm) { #else int cmd_process_demo(int argc, char *argv[]) { #endif uint32_t pid; char msg[64]; flash_orange_led_pid = svc_spawn(flash_orange_led); sprintf(msg, "spawned PID: %d\r\n", (int) flash_orange_led_pid); efputs(msg, STDOUT); pid = svc_spawn(openFiles); sprintf(msg, "spawned PID: %d\r\n", (int) pid); efputs(msg, STDOUT); pid = svc_spawn(cmd_touch2led); sprintf(msg, "spawned PID: %d\r\n", (int) pid); efputs(msg, STDOUT); pid = svc_spawn(cmd_pot2ser); sprintf(msg, "spawned PID: %d\r\n", (int) pid); efputs(msg, STDOUT); return 0; }
/* there is a race condition when reading the button value */ int sw2message(int argc, char **argv) { Stream *sw2; int c; uint32_t pid; char msg[64]; pid = getCurrentPID(); sw2 = svc_myFopen("/dev/button/sw2"); while(TRUE) { c = svc_myFgetc(sw2); if (c == EOF) { efputs("sw2message: end of file received from button\r\n", STDOUT); } if (c) { sprintf(msg, "Hello from PID %d. sw2 was pressed\r\n", (int) pid); efputs(msg, STDOUT); } } }
void save_json( cJSON *root, const char *filename ) { SDL_RWops *f = dir_fopen_warn(get_user_directory(), filename, "w+"); if (f == NULL) return; char *buffer = cJSON_Print(root); if (buffer != NULL) { efputs(buffer, f); free(buffer); } SDL_RWclose(f); }
int flash_orange_led(int argc, char **argv) { char msg[64]; orange_led = svc_myFopen("/dev/led/orange"); start_millis = svc_get_current_millis(); while(time_remaining) { if (flash_orange_led_pid == 0) { continue; } svc_setTimer(interval, turn_on_led_and_reset_timer); svc_myFputc(orange_led_on, orange_led); current_millis = svc_get_current_millis(); svc_block(); } svc_myFputc(0, orange_led); sprintf(msg, "About to kill PID %d.\r\n", (int) flash_orange_led_pid); efputs(msg, STDOUT); svc_myKill(flash_orange_led_pid); return SUCCESS; }