X-Git-Url: https://git.rohieb.name/hackover2013-badge-firmware.git/blobdiff_plain/46a985dc4e6c6a0cc1a943e58a06d160609f9f13..4292be14c78b8f30075c9e4837dd026f6fec532e:/project/commands/cmd_pwm.c diff --git a/project/commands/cmd_pwm.c b/project/commands/cmd_pwm.c index 505470d..3d070d5 100644 --- a/project/commands/cmd_pwm.c +++ b/project/commands/cmd_pwm.c @@ -56,38 +56,29 @@ void cmd_pwm(uint8_t argc, char **argv) { int32_t frequencyTicks = 65535; int32_t dutyCycle = CFG_PWM_DEFAULT_DUTYCYCLE; - if(argc > 0) { - getNumber (argv[0], &dutyCycle); - if(dutyCycle < 1 || dutyCycle > 100) { - printf("Invalid duty cycle [1..65535]%s", CFG_PRINTF_NEWLINE); - return; - } - - if(argc > 1) { - getNumber (argv[1], &frequencyTicks); - if(frequencyTicks < 0 || frequencyTicks > 0xffff) { - printf("Invalid frequency [1..65535]%s", CFG_PRINTF_NEWLINE); - return; - } - } else { - frequencyTicks = 65535; - } - } else { - dutyCycle = CFG_PWM_DEFAULT_DUTYCYCLE; + getNumber (argv[0], &dutyCycle); + if(dutyCycle < 1 || dutyCycle > 100) + { + printf("Invalid duty cycle [1..65535]%s", CFG_PRINTF_NEWLINE); + return; } - if(! pwmStarted) { - printf("Initializing PWM%s", CFG_PRINTF_NEWLINE); - pwmInit(); + getNumber (argv[1], &frequencyTicks); + if(frequencyTicks < 0 || frequencyTicks > 0xffff) + { + printf("Invalid frequency [1..65535]%s", CFG_PRINTF_NEWLINE); + return; } - + printf("Setting frequency: %u ticks%s", (uint16_t) frequencyTicks, CFG_PRINTF_NEWLINE); pwmSetFrequencyInTicks(frequencyTicks); printf("Setting duty cycle: %u%%%s", (uint16_t) dutyCycle, CFG_PRINTF_NEWLINE); pwmSetDutyCycle(dutyCycle); - if(! pwmStarted) { - pwmStart(); - pwmStarted = 1; + if(! pwmStarted) + { + printf("Initializing PWM%s", CFG_PRINTF_NEWLINE); + pwmStart(); + pwmStarted = 1; } } #endif