weather_station_scene_receiver_config.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. #include "../weather_station_app_i.h"
  2. enum WSSettingIndex {
  3. WSSettingIndexFrequency,
  4. WSSettingIndexHopping,
  5. WSSettingIndexModulation,
  6. WSSettingIndexLock,
  7. };
  8. #define HOPPING_COUNT 2
  9. const char* const hopping_text[HOPPING_COUNT] = {
  10. "OFF",
  11. "ON",
  12. };
  13. const uint32_t hopping_value[HOPPING_COUNT] = {
  14. WSHopperStateOFF,
  15. WSHopperStateRunnig,
  16. };
  17. uint8_t weather_station_scene_receiver_config_next_frequency(const uint32_t value, void* context) {
  18. furi_assert(context);
  19. WeatherStationApp* app = context;
  20. uint8_t index = 0;
  21. for(uint8_t i = 0; i < subghz_setting_get_frequency_count(app->setting); i++) {
  22. if(value == subghz_setting_get_frequency(app->setting, i)) {
  23. index = i;
  24. break;
  25. } else {
  26. index = subghz_setting_get_frequency_default_index(app->setting);
  27. }
  28. }
  29. return index;
  30. }
  31. uint8_t weather_station_scene_receiver_config_next_preset(const char* preset_name, void* context) {
  32. furi_assert(context);
  33. WeatherStationApp* app = context;
  34. uint8_t index = 0;
  35. for(uint8_t i = 0; i < subghz_setting_get_preset_count(app->setting); i++) {
  36. if(!strcmp(subghz_setting_get_preset_name(app->setting, i), preset_name)) {
  37. index = i;
  38. break;
  39. } else {
  40. // index = subghz_setting_get_frequency_default_index(app ->setting);
  41. }
  42. }
  43. return index;
  44. }
  45. uint8_t weather_station_scene_receiver_config_hopper_value_index(
  46. const uint32_t value,
  47. const uint32_t values[],
  48. uint8_t values_count,
  49. void* context) {
  50. furi_assert(context);
  51. UNUSED(values_count);
  52. WeatherStationApp* app = context;
  53. if(value == values[0]) {
  54. return 0;
  55. } else {
  56. variable_item_set_current_value_text(
  57. (VariableItem*)scene_manager_get_scene_state(
  58. app->scene_manager, WeatherStationSceneReceiverConfig),
  59. " -----");
  60. return 1;
  61. }
  62. }
  63. static void weather_station_scene_receiver_config_set_frequency(VariableItem* item) {
  64. WeatherStationApp* app = variable_item_get_context(item);
  65. uint8_t index = variable_item_get_current_value_index(item);
  66. if(app->txrx->hopper_state == WSHopperStateOFF) {
  67. char text_buf[10] = {0};
  68. snprintf(
  69. text_buf,
  70. sizeof(text_buf),
  71. "%lu.%02lu",
  72. subghz_setting_get_frequency(app->setting, index) / 1000000,
  73. (subghz_setting_get_frequency(app->setting, index) % 1000000) / 10000);
  74. variable_item_set_current_value_text(item, text_buf);
  75. app->txrx->preset->frequency = subghz_setting_get_frequency(app->setting, index);
  76. } else {
  77. variable_item_set_current_value_index(
  78. item, subghz_setting_get_frequency_default_index(app->setting));
  79. }
  80. }
  81. static void weather_station_scene_receiver_config_set_preset(VariableItem* item) {
  82. WeatherStationApp* app = variable_item_get_context(item);
  83. uint8_t index = variable_item_get_current_value_index(item);
  84. variable_item_set_current_value_text(
  85. item, subghz_setting_get_preset_name(app->setting, index));
  86. ws_preset_init(
  87. app,
  88. subghz_setting_get_preset_name(app->setting, index),
  89. app->txrx->preset->frequency,
  90. subghz_setting_get_preset_data(app->setting, index),
  91. subghz_setting_get_preset_data_size(app->setting, index));
  92. }
  93. static void weather_station_scene_receiver_config_set_hopping_running(VariableItem* item) {
  94. WeatherStationApp* app = variable_item_get_context(item);
  95. uint8_t index = variable_item_get_current_value_index(item);
  96. variable_item_set_current_value_text(item, hopping_text[index]);
  97. if(hopping_value[index] == WSHopperStateOFF) {
  98. char text_buf[10] = {0};
  99. snprintf(
  100. text_buf,
  101. sizeof(text_buf),
  102. "%lu.%02lu",
  103. subghz_setting_get_default_frequency(app->setting) / 1000000,
  104. (subghz_setting_get_default_frequency(app->setting) % 1000000) / 10000);
  105. variable_item_set_current_value_text(
  106. (VariableItem*)scene_manager_get_scene_state(
  107. app->scene_manager, WeatherStationSceneReceiverConfig),
  108. text_buf);
  109. app->txrx->preset->frequency = subghz_setting_get_default_frequency(app->setting);
  110. variable_item_set_current_value_index(
  111. (VariableItem*)scene_manager_get_scene_state(
  112. app->scene_manager, WeatherStationSceneReceiverConfig),
  113. subghz_setting_get_frequency_default_index(app->setting));
  114. } else {
  115. variable_item_set_current_value_text(
  116. (VariableItem*)scene_manager_get_scene_state(
  117. app->scene_manager, WeatherStationSceneReceiverConfig),
  118. " -----");
  119. variable_item_set_current_value_index(
  120. (VariableItem*)scene_manager_get_scene_state(
  121. app->scene_manager, WeatherStationSceneReceiverConfig),
  122. subghz_setting_get_frequency_default_index(app->setting));
  123. }
  124. app->txrx->hopper_state = hopping_value[index];
  125. }
  126. static void
  127. weather_station_scene_receiver_config_var_list_enter_callback(void* context, uint32_t index) {
  128. furi_assert(context);
  129. WeatherStationApp* app = context;
  130. if(index == WSSettingIndexLock) {
  131. view_dispatcher_send_custom_event(app->view_dispatcher, WSCustomEventSceneSettingLock);
  132. }
  133. }
  134. void weather_station_scene_receiver_config_on_enter(void* context) {
  135. WeatherStationApp* app = context;
  136. VariableItem* item;
  137. uint8_t value_index;
  138. item = variable_item_list_add(
  139. app->variable_item_list,
  140. "Frequency:",
  141. subghz_setting_get_frequency_count(app->setting),
  142. weather_station_scene_receiver_config_set_frequency,
  143. app);
  144. value_index =
  145. weather_station_scene_receiver_config_next_frequency(app->txrx->preset->frequency, app);
  146. scene_manager_set_scene_state(
  147. app->scene_manager, WeatherStationSceneReceiverConfig, (uint32_t)item);
  148. variable_item_set_current_value_index(item, value_index);
  149. char text_buf[10] = {0};
  150. snprintf(
  151. text_buf,
  152. sizeof(text_buf),
  153. "%lu.%02lu",
  154. subghz_setting_get_frequency(app->setting, value_index) / 1000000,
  155. (subghz_setting_get_frequency(app->setting, value_index) % 1000000) / 10000);
  156. variable_item_set_current_value_text(item, text_buf);
  157. item = variable_item_list_add(
  158. app->variable_item_list,
  159. "Hopping:",
  160. HOPPING_COUNT,
  161. weather_station_scene_receiver_config_set_hopping_running,
  162. app);
  163. value_index = weather_station_scene_receiver_config_hopper_value_index(
  164. app->txrx->hopper_state, hopping_value, HOPPING_COUNT, app);
  165. variable_item_set_current_value_index(item, value_index);
  166. variable_item_set_current_value_text(item, hopping_text[value_index]);
  167. item = variable_item_list_add(
  168. app->variable_item_list,
  169. "Modulation:",
  170. subghz_setting_get_preset_count(app->setting),
  171. weather_station_scene_receiver_config_set_preset,
  172. app);
  173. value_index = weather_station_scene_receiver_config_next_preset(
  174. furi_string_get_cstr(app->txrx->preset->name), app);
  175. variable_item_set_current_value_index(item, value_index);
  176. variable_item_set_current_value_text(
  177. item, subghz_setting_get_preset_name(app->setting, value_index));
  178. variable_item_list_add(app->variable_item_list, "Lock Keyboard", 1, NULL, NULL);
  179. variable_item_list_set_enter_callback(
  180. app->variable_item_list,
  181. weather_station_scene_receiver_config_var_list_enter_callback,
  182. app);
  183. view_dispatcher_switch_to_view(app->view_dispatcher, WeatherStationViewVariableItemList);
  184. }
  185. bool weather_station_scene_receiver_config_on_event(void* context, SceneManagerEvent event) {
  186. WeatherStationApp* app = context;
  187. bool consumed = false;
  188. if(event.type == SceneManagerEventTypeCustom) {
  189. if(event.event == WSCustomEventSceneSettingLock) {
  190. app->lock = WSLockOn;
  191. scene_manager_previous_scene(app->scene_manager);
  192. consumed = true;
  193. }
  194. }
  195. return consumed;
  196. }
  197. void weather_station_scene_receiver_config_on_exit(void* context) {
  198. WeatherStationApp* app = context;
  199. variable_item_list_set_selected_item(app->variable_item_list, 0);
  200. variable_item_list_reset(app->variable_item_list);
  201. }