view_settings.c 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* Copyright (C) 2022-2023 Salvatore Sanfilippo -- All Rights Reserved
  2. * See the LICENSE file for information about the license. */
  3. #include "app.h"
  4. /* Renders a single view with frequency and modulation setting. However
  5. * this are logically two different views, and only one of the settings
  6. * will be highlighted. */
  7. void render_view_settings(Canvas *const canvas, ProtoViewApp *app) {
  8. UNUSED(app);
  9. canvas_set_font(canvas, FontPrimary);
  10. if (app->current_view == ViewFrequencySettings)
  11. canvas_draw_str_with_border(canvas,1,10,"Frequency",ColorWhite,ColorBlack);
  12. else
  13. canvas_draw_str(canvas,1,10,"Frequency");
  14. if (app->current_view == ViewModulationSettings)
  15. canvas_draw_str_with_border(canvas,70,10,"Modulation",ColorWhite,ColorBlack);
  16. else
  17. canvas_draw_str(canvas,70,10,"Modulation");
  18. canvas_set_font(canvas, FontSecondary);
  19. canvas_draw_str(canvas,10,61,"Use up and down to modify");
  20. /* Show frequency. We can use big numbers font since it's just a number. */
  21. if (app->current_view == ViewFrequencySettings) {
  22. char buf[16];
  23. snprintf(buf,sizeof(buf),"%.2f",(double)app->frequency/1000000);
  24. canvas_set_font(canvas, FontBigNumbers);
  25. canvas_draw_str(canvas, 30, 40, buf);
  26. } else if (app->current_view == ViewModulationSettings) {
  27. int current = app->modulation;
  28. canvas_set_font(canvas, FontPrimary);
  29. canvas_draw_str(canvas, 33, 39, ProtoViewModulations[current].name);
  30. }
  31. }
  32. /* Handle input for the settings view. */
  33. void process_input_settings(ProtoViewApp *app, InputEvent input) {
  34. /* Here we handle only up and down. Avoid any work if the user
  35. * pressed something else. */
  36. if (input.type != InputTypePress ||
  37. (input.key != InputKeyDown && input.key != InputKeyUp)) return;
  38. if (app->current_view == ViewFrequencySettings) {
  39. size_t curidx = 0, i;
  40. size_t count = subghz_setting_get_frequency_count(app->setting);
  41. /* Scan the list of frequencies to check for the index of the
  42. * currently set frequency. */
  43. for(i = 0; i < count; i++) {
  44. uint32_t freq = subghz_setting_get_frequency(app->setting,i);
  45. if (freq == app->frequency) {
  46. curidx = i;
  47. break;
  48. }
  49. }
  50. if (i == count) return; /* Should never happen. */
  51. if (input.key == InputKeyUp) {
  52. curidx = (curidx+1) % count;
  53. } else if (input.key == InputKeyDown) {
  54. curidx = curidx == 0 ? count-1 : curidx-1;
  55. }
  56. app->frequency = subghz_setting_get_frequency(app->setting,curidx);
  57. } else if (app->current_view == ViewModulationSettings) {
  58. uint32_t count = 0;
  59. uint32_t modid = app->modulation;
  60. while(ProtoViewModulations[count].name != NULL) count++;
  61. if (input.key == InputKeyUp) {
  62. modid = (modid+1) % count;
  63. } else if (input.key == InputKeyDown) {
  64. modid = modid == 0 ? count-1 : modid-1;
  65. }
  66. app->modulation = modid;
  67. }
  68. /* Apply changes. */
  69. FURI_LOG_E(TAG, "Setting view, setting frequency/modulation to %lu %s", app->frequency, ProtoViewModulations[app->modulation].name);
  70. radio_rx_end(app);
  71. radio_begin(app);
  72. radio_rx(app);
  73. }