diff options
Diffstat (limited to 'software/rda1846dongle/rda1846dongle.c')
-rw-r--r-- | software/rda1846dongle/rda1846dongle.c | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/software/rda1846dongle/rda1846dongle.c b/software/rda1846dongle/rda1846dongle.c index 618b7ea..4bc4c2f 100644 --- a/software/rda1846dongle/rda1846dongle.c +++ b/software/rda1846dongle/rda1846dongle.c @@ -41,13 +41,43 @@ #include "rda1846.h" -void handle_cmd(uint8_t cmd) +#define DEFAULT_FREQ 145900 +int32_t current_freq_kHz = DEFAULT_FREQ; + +static int32_t print_actual_freq(void) +{ + int32_t f = rda1846_get_freq_kHz(); + if(f < 0) + printf("actual frequency: NaN MHz"); + else + printf("actual frequency: %d.%03d MHz", (uint16_t)(f / 1000), (uint16_t)(f % 1000)); + return f; +} + +static void update_current_freq(void) +{ + printf("setting frequency to %d.%03d MHz .. ", (uint16_t)(current_freq_kHz / 1000), + (uint16_t)(current_freq_kHz % 1000)); + if(rda1846_set_freq_kHz(current_freq_kHz)) + printf("error\r\n"); + else + printf("ok\r\n"); + + current_freq_kHz = print_actual_freq(); + if(current_freq_kHz < 0) + current_freq_kHz = DEFAULT_FREQ; +} + +static void handle_cmd(uint8_t cmd) { switch(cmd) { case '0': led_off(); break; case '1': led_on(); break; case 't': led_toggle(); break; case 'r': reset2bootloader(); break; + case 'f': print_actual_freq(); break; + case '+': current_freq_kHz+=500; update_current_freq(); break; + case '-': current_freq_kHz-=500; update_current_freq(); break; default: printf("error\r\n"); return; } printf("ok\r\n"); @@ -61,10 +91,10 @@ int main(void) cpu_init(); led_init(); usbio_init(); + sei(); rda1846_init(); - - sei(); + rda1846_set_freq_kHz(current_freq_kHz); for(;;) { int16_t BytesReceived = usbio_bytes_received(); |