view_settings.c 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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.key != InputKeyDown && input.key != InputKeyUp) return;
  37. if (app->current_view == ViewFrequencySettings) {
  38. size_t curidx = 0, i;
  39. size_t count = subghz_setting_get_frequency_count(app->setting);
  40. /* Scan the list of frequencies to check for the index of the
  41. * currently set frequency. */
  42. for(i = 0; i < count; i++) {
  43. uint32_t freq = subghz_setting_get_frequency(app->setting,i);
  44. if (freq == app->frequency) {
  45. curidx = i;
  46. break;
  47. }
  48. }
  49. if (i == count) return; /* Should never happen. */
  50. if (input.key == InputKeyUp) {
  51. curidx = (curidx+1) % count;
  52. } else if (input.key == InputKeyDown) {
  53. curidx = curidx == 0 ? count-1 : curidx-1;
  54. }
  55. app->frequency = subghz_setting_get_frequency(app->setting,curidx);
  56. } else if (app->current_view == ViewModulationSettings) {
  57. uint32_t count = 0;
  58. uint32_t modid = app->modulation;
  59. while(ProtoViewModulations[count].name != NULL) count++;
  60. if (input.key == InputKeyUp) {
  61. modid = (modid+1) % count;
  62. } else if (input.key == InputKeyDown) {
  63. modid = modid == 0 ? count-1 : modid-1;
  64. }
  65. app->modulation = modid;
  66. }
  67. /* Apply changes. */
  68. FURI_LOG_E(TAG, "Setting view, setting frequency/modulation to %lu %s", app->frequency, ProtoViewModulations[app->modulation].name);
  69. radio_rx_end(app);
  70. radio_begin(app);
  71. radio_rx(app);
  72. }