mag_scene_emulate_config.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. #include "../mag_i.h"
  2. #define TAG "MagSceneEmulateConfig"
  3. enum MagEmulateConfigIndex {
  4. MagEmulateConfigIndexTx,
  5. MagEmulateConfigIndexTrack,
  6. MagEmulateConfigIndexReverse,
  7. MagEmulateConfigIndexClock,
  8. MagEmulateConfigIndexInterpacket,
  9. };
  10. #define TX_COUNT 7
  11. const char* const tx_text[TX_COUNT] = {
  12. "RFID",
  13. "GPIO",
  14. "Piezo",
  15. "LF + P",
  16. "NFC",
  17. "434MHz",
  18. "868MHz",
  19. };
  20. const uint32_t tx_value[TX_COUNT] = {
  21. MagTxStateRFID,
  22. MagTxStateGPIO,
  23. MagTxStatePiezo,
  24. MagTxStateLF_P,
  25. MagTxStateNFC,
  26. MagTxCC1101_434,
  27. MagTxCC1101_868,
  28. };
  29. #define TRACK_COUNT 4
  30. const char* const track_text[TRACK_COUNT] = {
  31. "1 + 2",
  32. "1",
  33. "2",
  34. "3",
  35. };
  36. const uint32_t track_value[TRACK_COUNT] = {
  37. MagTrackStateOneAndTwo,
  38. MagTrackStateOne,
  39. MagTrackStateTwo,
  40. MagTrackStateThree,
  41. };
  42. #define REVERSE_COUNT 2
  43. const char* const reverse_text[REVERSE_COUNT] = {
  44. "OFF",
  45. "ON",
  46. };
  47. const uint32_t reverse_value[REVERSE_COUNT] = {
  48. MagReverseStateOff,
  49. MagReverseStateOn,
  50. };
  51. #define CLOCK_COUNT 15
  52. const char* const clock_text[CLOCK_COUNT] = {
  53. "200us",
  54. "220us",
  55. "240us",
  56. "250us",
  57. "260us",
  58. "280us",
  59. "300us",
  60. "325us",
  61. "350us",
  62. "375us",
  63. "400us",
  64. "450us",
  65. "500us",
  66. "600us",
  67. "700us",
  68. };
  69. const uint32_t clock_value[CLOCK_COUNT] = {
  70. 200,
  71. 220,
  72. 240,
  73. 250,
  74. 260,
  75. 280,
  76. 300,
  77. 325,
  78. 350,
  79. 375,
  80. 400,
  81. 450,
  82. 500,
  83. 600,
  84. 700,
  85. };
  86. #define INTERPACKET_COUNT 13
  87. const char* const interpacket_text[INTERPACKET_COUNT] = {
  88. "0us",
  89. "2us",
  90. "4us",
  91. "6us",
  92. "8us",
  93. "10us",
  94. "12us",
  95. "14us",
  96. "16us",
  97. "18us",
  98. "20us",
  99. "25us",
  100. "30us",
  101. };
  102. const uint32_t interpacket_value[INTERPACKET_COUNT] = {
  103. 0,
  104. 2,
  105. 4,
  106. 6,
  107. 8,
  108. 10,
  109. 12,
  110. 14,
  111. 16,
  112. 18,
  113. 20,
  114. 25,
  115. 30,
  116. };
  117. static void mag_scene_emulate_config_set_tx(VariableItem* item) {
  118. Mag* mag = variable_item_get_context(item);
  119. uint8_t index = variable_item_get_current_value_index(item);
  120. variable_item_set_current_value_text(item, tx_text[index]);
  121. mag->state.tx = tx_value[index];
  122. };
  123. static void mag_scene_emulate_config_set_track(VariableItem* item) {
  124. Mag* mag = variable_item_get_context(item);
  125. uint8_t index = variable_item_get_current_value_index(item);
  126. if(mag->state.reverse == MagReverseStateOff) {
  127. variable_item_set_current_value_text(item, track_text[index]);
  128. mag->state.track = track_value[index];
  129. } else if(mag->state.reverse == MagReverseStateOn) {
  130. variable_item_set_current_value_index(
  131. item, value_index_uint32(MagTrackStateOneAndTwo, track_value, TRACK_COUNT));
  132. }
  133. // TODO: Check there is data in selected track?
  134. // Only display track options with data?
  135. };
  136. static void mag_scene_emulate_config_set_reverse(VariableItem* item) {
  137. Mag* mag = variable_item_get_context(item);
  138. uint8_t index = variable_item_get_current_value_index(item);
  139. if(mag->state.track == MagTrackStateOneAndTwo) {
  140. // only allow reverse track to be set when playing both 1 and 2
  141. variable_item_set_current_value_text(item, reverse_text[index]);
  142. mag->state.reverse = reverse_value[index];
  143. //FURI_LOG_D(TAG, "%s", reverse_text[index]);
  144. //FURI_LOG_D(TAG, "%d", mag->setting->reverse);
  145. } else {
  146. variable_item_set_current_value_index(
  147. item, value_index_uint32(MagReverseStateOff, reverse_value, REVERSE_COUNT));
  148. }
  149. };
  150. static void mag_scene_emulate_config_set_clock(VariableItem* item) {
  151. Mag* mag = variable_item_get_context(item);
  152. uint8_t index = variable_item_get_current_value_index(item);
  153. variable_item_set_current_value_text(item, clock_text[index]);
  154. mag->state.us_clock = clock_value[index];
  155. };
  156. static void mag_scene_emulate_config_set_interpacket(VariableItem* item) {
  157. Mag* mag = variable_item_get_context(item);
  158. uint8_t index = variable_item_get_current_value_index(item);
  159. variable_item_set_current_value_text(item, interpacket_text[index]);
  160. mag->state.us_interpacket = interpacket_value[index];
  161. };
  162. void mag_scene_emulate_config_on_enter(void* context) {
  163. Mag* mag = context;
  164. VariableItem* item;
  165. uint8_t value_index;
  166. // Clock
  167. item = variable_item_list_add(
  168. mag->variable_item_list, "Clock:", CLOCK_COUNT, mag_scene_emulate_config_set_clock, mag);
  169. value_index = value_index_uint32(mag->state.us_clock, clock_value, CLOCK_COUNT);
  170. scene_manager_set_scene_state(mag->scene_manager, MagSceneEmulateConfig, (uint32_t)item);
  171. variable_item_set_current_value_index(item, value_index);
  172. variable_item_set_current_value_text(item, clock_text[value_index]);
  173. // Track
  174. item = variable_item_list_add(
  175. mag->variable_item_list, "Track:", TRACK_COUNT, mag_scene_emulate_config_set_track, mag);
  176. value_index = value_index_uint32(mag->state.track, track_value, TRACK_COUNT);
  177. scene_manager_set_scene_state(mag->scene_manager, MagSceneEmulateConfig, (uint32_t)item);
  178. variable_item_set_current_value_index(item, value_index);
  179. variable_item_set_current_value_text(item, track_text[value_index]);
  180. // Reverse
  181. //FURI_LOG_D(TAG, "%d", mag->setting->reverse);
  182. item = variable_item_list_add(
  183. mag->variable_item_list,
  184. "Reverse:",
  185. REVERSE_COUNT,
  186. mag_scene_emulate_config_set_reverse,
  187. mag);
  188. value_index = value_index_uint32(mag->state.reverse, reverse_value, REVERSE_COUNT);
  189. scene_manager_set_scene_state(mag->scene_manager, MagSceneEmulateConfig, (uint32_t)item);
  190. variable_item_set_current_value_index(item, value_index);
  191. variable_item_set_current_value_text(item, reverse_text[value_index]);
  192. // TX
  193. #ifdef FW_ORIGIN_Official
  194. if(mag->state.is_debug) {
  195. #endif
  196. item = variable_item_list_add(
  197. mag->variable_item_list, "TX via:", TX_COUNT, mag_scene_emulate_config_set_tx, mag);
  198. value_index = value_index_uint32(mag->state.tx, tx_value, TX_COUNT);
  199. scene_manager_set_scene_state(mag->scene_manager, MagSceneEmulateConfig, (uint32_t)item);
  200. variable_item_set_current_value_index(item, value_index);
  201. variable_item_set_current_value_text(item, tx_text[value_index]);
  202. #ifdef FW_ORIGIN_Official
  203. }
  204. #else
  205. variable_item_set_locked(item, !mag->state.is_debug, "Enable Debug!");
  206. #endif
  207. // Interpacket
  208. /*
  209. item = variable_item_list_add(
  210. mag->variable_item_list,
  211. "Interpacket:",
  212. INTERPACKET_COUNT,
  213. mag_scene_emulate_config_set_interpacket,
  214. mag);
  215. value_index =
  216. value_index_uint32(mag->setting->us_interpacket, interpacket_value, INTERPACKET_COUNT);
  217. scene_manager_set_scene_state(mag->scene_manager, MagSceneEmulateConfig, (uint32_t)item);
  218. variable_item_set_current_value_index(item, value_index);
  219. variable_item_set_current_value_text(item, interpacket_text[value_index]);*/
  220. UNUSED(mag_scene_emulate_config_set_interpacket);
  221. view_dispatcher_switch_to_view(mag->view_dispatcher, MagViewVariableItemList);
  222. }
  223. bool mag_scene_emulate_config_on_event(void* context, SceneManagerEvent event) {
  224. Mag* mag = context;
  225. SceneManager* scene_manager = mag->scene_manager;
  226. bool consumed = false;
  227. UNUSED(mag);
  228. UNUSED(scene_manager);
  229. UNUSED(event);
  230. return consumed;
  231. }
  232. void mag_scene_emulate_config_on_exit(void* context) {
  233. Mag* mag = context;
  234. variable_item_list_set_selected_item(mag->variable_item_list, 0);
  235. variable_item_list_reset(mag->variable_item_list);
  236. // mag_last_settings_save?
  237. // scene_manager_set_scene_state? Using subghz_scene_reciever_config as framework/inspo
  238. }