static void cmd_dc(BaseSequentialStream *chp, int argc, char *argv[]) { static const int TTL_MS = 30000; if (argc == 0) { motor_stop(); puts("Usage:\n" " dc <duty cycle>\n" " dc arm"); return; } // Safety check static bool _armed = false; if (!strcmp(argv[0], "arm")) { _armed = true; puts("OK"); return; } if (!_armed) { puts("Error: Not armed"); return; } const float value = atoff(argv[0]); lowsyslog("Duty cycle %f\n", value); motor_set_duty_cycle(value, TTL_MS); }
static void cmd_startstop(BaseSequentialStream *chp, int argc, char *argv[]) { static const int TTL_MS = 5000; if (argc == 0) { motor_stop(); puts("Usage:\n" " startstop <number of cycles> [duty cycle = 0.1]"); return; } motor_stop(); const int num_cycles = (int)atoff(argv[0]); const float dc = (argc > 1) ? atoff(argv[1]) : 0.1; int current_cycle = 0; for (; current_cycle < num_cycles; current_cycle++) { printf("Cycle %d of %d, dc %f...\n", current_cycle + 1, num_cycles, dc); // Waiting for the motor to spin down sleep(3); if (!motor_is_idle()) { puts("NOT STOPPED"); break; } // Starting with the specified duty cycle motor_set_duty_cycle(dc, TTL_MS); // Checking if started and stopping sleep(3); if (!motor_is_running()) { puts("NOT RUNNING"); break; } motor_stop(); } printf("Finished %d cycles of %d\n", current_cycle, num_cycles); }