dtmf_dolphin_data.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. #include "dtmf_dolphin_data.h"
  2. typedef struct {
  3. const uint8_t row;
  4. const uint8_t col;
  5. const uint8_t span;
  6. } DTMFDolphinTonePos;
  7. typedef struct {
  8. const char *name;
  9. const float frequency_1;
  10. const float frequency_2;
  11. const DTMFDolphinTonePos pos;
  12. const uint16_t pulses; // for Redbox
  13. const uint16_t pulse_ms; // for Redbox
  14. const uint16_t gap_duration; // for Redbox
  15. } DTMFDolphinTones;
  16. typedef struct {
  17. const char* name;
  18. DTMFDolphinToneSection block;
  19. uint8_t tone_count;
  20. DTMFDolphinTones tones[DTMF_DOLPHIN_MAX_TONE_COUNT];
  21. } DTMFDolphinSceneData;
  22. DTMFDolphinSceneData DTMFDolphinSceneDataDialer = {
  23. .name = "Dialer",
  24. .block = DTMF_DOLPHIN_TONE_BLOCK_DIALER,
  25. .tone_count = 16,
  26. .tones = {
  27. {"1", 697.0, 1209.0, {0, 0, 1}, 0, 0, 0},
  28. {"2", 697.0, 1336.0, {0, 1, 1}, 0, 0, 0},
  29. {"3", 697.0, 1477.0, {0, 2, 1}, 0, 0, 0},
  30. {"A", 697.0, 1633.0, {0, 3, 1}, 0, 0, 0},
  31. {"4", 770.0, 1209.0, {1, 0, 1}, 0, 0, 0},
  32. {"5", 770.0, 1336.0, {1, 1, 1}, 0, 0, 0},
  33. {"6", 770.0, 1477.0, {1, 2, 1}, 0, 0, 0},
  34. {"B", 770.0, 1633.0, {1, 3, 1}, 0, 0, 0},
  35. {"7", 852.0, 1209.0, {2, 0, 1}, 0, 0, 0},
  36. {"8", 852.0, 1336.0, {2, 1, 1}, 0, 0, 0},
  37. {"9", 852.0, 1477.0, {2, 2, 1}, 0, 0, 0},
  38. {"C", 852.0, 1633.0, {2, 3, 1}, 0, 0, 0},
  39. {"*", 941.0, 1209.0, {3, 0, 1}, 0, 0, 0},
  40. {"0", 941.0, 1336.0, {3, 1, 1}, 0, 0, 0},
  41. {"#", 941.0, 1477.0, {3, 2, 1}, 0, 0, 0},
  42. {"D", 941.0, 1633.0, {3, 3, 1}, 0, 0, 0},
  43. }
  44. };
  45. DTMFDolphinSceneData DTMFDolphinSceneDataBluebox = {
  46. .name = "Bluebox",
  47. .block = DTMF_DOLPHIN_TONE_BLOCK_BLUEBOX,
  48. .tone_count = 13,
  49. .tones = {
  50. {"1", 700.0, 900.0, {0, 0, 1}, 0, 0, 0},
  51. {"2", 700.0, 1100.0, {0, 1, 1}, 0, 0, 0},
  52. {"3", 900.0, 1100.0, {0, 2, 1}, 0, 0, 0},
  53. {"4", 700.0, 1300.0, {1, 0, 1}, 0, 0, 0},
  54. {"5", 900.0, 1300.0, {1, 1, 1}, 0, 0, 0},
  55. {"6", 1100.0, 1300.0, {1, 2, 1}, 0, 0, 0},
  56. {"7", 700.0, 1500.0, {2, 0, 1}, 0, 0, 0},
  57. {"8", 900.0, 1500.0, {2, 1, 1}, 0, 0, 0},
  58. {"9", 1100.0, 1500.0, {2, 2, 1}, 0, 0, 0},
  59. {"0", 1300.0, 1500.0, {3, 1, 1}, 0, 0, 0},
  60. {"KP", 1100.0, 1700.0, {0, 3, 2}, 0, 0, 0},
  61. {"ST", 1500.0, 1700.0, {1, 3, 2}, 0, 0, 0},
  62. {"2600", 2600.0, 0.0, {3, 2, 3}, 0, 0, 0},
  63. }
  64. };
  65. DTMFDolphinSceneData DTMFDolphinSceneDataRedboxUS = {
  66. .name = "Redbox (US)",
  67. .block = DTMF_DOLPHIN_TONE_BLOCK_REDBOX_US,
  68. .tone_count = 4,
  69. .tones = {
  70. {"Nickel", 1700.0, 2200.0, {0, 0, 5}, 1, 66, 0},
  71. {"Dime", 1700.0, 2200.0, {1, 0, 5}, 2, 66, 66},
  72. {"Quarter", 1700.0, 2200.0, {2, 0, 5}, 5, 33, 33},
  73. {"Dollar", 1700.0, 2200.0, {3, 0, 5}, 1, 650, 0},
  74. }
  75. };
  76. DTMFDolphinSceneData DTMFDolphinSceneDataRedboxCA = {
  77. .name = "Redbox (CA)",
  78. .block = DTMF_DOLPHIN_TONE_BLOCK_REDBOX_CA,
  79. .tone_count = 3,
  80. .tones = {
  81. {"Nickel", 2200.0, 0.0, {0, 0, 5}, 1, 66, 0},
  82. {"Dime", 2200.0, 0.0, {1, 0, 5}, 2, 66, 66},
  83. {"Quarter", 2200.0, 0.0, {2, 0, 5}, 5, 33, 33},
  84. }
  85. };
  86. DTMFDolphinSceneData DTMFDolphinSceneDataRedboxUK = {
  87. .name = "Redbox (UK)",
  88. .block = DTMF_DOLPHIN_TONE_BLOCK_REDBOX_UK,
  89. .tone_count = 2,
  90. .tones = {
  91. {"10p", 1000.0, 0.0, {0, 0, 5}, 1, 200, 0},
  92. {"50p", 1000.0, 0.0, {1, 0, 5}, 1, 350, 0},
  93. }
  94. };
  95. DTMFDolphinSceneData DTMFDolphinSceneDataMisc = {
  96. .name = "Misc",
  97. .block = DTMF_DOLPHIN_TONE_BLOCK_MISC,
  98. .tone_count = 3,
  99. .tones = {
  100. {"CCITT 11", 700.0, 1700.0, {0, 0, 5}, 0, 0, 0},
  101. {"CCITT 12", 900.0, 1700.0, {1, 0, 5}, 0, 0, 0},
  102. {"CCITT KP2", 1300.0, 1700.0, {2, 0, 5}, 0, 0, 0},
  103. }
  104. };
  105. DTMFDolphinToneSection current_section;
  106. DTMFDolphinSceneData *current_scene_data;
  107. void dtmf_dolphin_data_set_current_section(DTMFDolphinToneSection section) {
  108. current_section = section;
  109. switch (current_section)
  110. {
  111. case DTMF_DOLPHIN_TONE_BLOCK_BLUEBOX:
  112. current_scene_data = &DTMFDolphinSceneDataBluebox;
  113. break;
  114. case DTMF_DOLPHIN_TONE_BLOCK_REDBOX_US:
  115. current_scene_data = &DTMFDolphinSceneDataRedboxUS;
  116. break;
  117. case DTMF_DOLPHIN_TONE_BLOCK_REDBOX_CA:
  118. current_scene_data = &DTMFDolphinSceneDataRedboxCA;
  119. break;
  120. case DTMF_DOLPHIN_TONE_BLOCK_REDBOX_UK:
  121. current_scene_data = &DTMFDolphinSceneDataRedboxUK;
  122. break;
  123. case DTMF_DOLPHIN_TONE_BLOCK_MISC:
  124. current_scene_data = &DTMFDolphinSceneDataMisc;
  125. break;
  126. default: // DTMF_DOLPHIN_TONE_BLOCK_DIALER:
  127. current_scene_data = &DTMFDolphinSceneDataDialer;
  128. break;
  129. }
  130. }
  131. DTMFDolphinToneSection dtmf_dolphin_data_get_current_section() {
  132. return current_section;
  133. }
  134. DTMFDolphinSceneData *dtmf_dolphin_data_get_current_scene_data() {
  135. return current_scene_data;
  136. }
  137. bool dtmf_dolphin_data_get_tone_frequencies(float *freq1, float *freq2, uint8_t row, uint8_t col) {
  138. for (size_t i = 0; i < current_scene_data->tone_count; i++) {
  139. DTMFDolphinTones tones = current_scene_data->tones[i];
  140. if (tones.pos.row == row && tones.pos.col == col) {
  141. freq1[0] = tones.frequency_1;
  142. freq2[0] = tones.frequency_2;
  143. return true;
  144. }
  145. }
  146. return false;
  147. }
  148. bool dtmf_dolphin_data_get_filter_data(uint16_t *pulses, uint16_t *pulse_ms, uint16_t *gap_ms, uint8_t row, uint8_t col) {
  149. for (size_t i = 0; i < current_scene_data->tone_count; i++) {
  150. DTMFDolphinTones tones = current_scene_data->tones[i];
  151. if (tones.pos.row == row && tones.pos.col == col) {
  152. pulses[0] = tones.pulses;
  153. pulse_ms[0] = tones.pulse_ms;
  154. gap_ms[0] = tones.gap_duration;
  155. return true;
  156. }
  157. }
  158. return false;
  159. }
  160. const char* dtmf_dolphin_data_get_tone_name(uint8_t row, uint8_t col) {
  161. for (size_t i = 0; i < current_scene_data->tone_count; i++) {
  162. DTMFDolphinTones tones = current_scene_data->tones[i];
  163. if (tones.pos.row == row && tones.pos.col == col) {
  164. return tones.name;
  165. }
  166. }
  167. return NULL;
  168. }
  169. const char* dtmf_dolphin_data_get_current_section_name() {
  170. if (current_scene_data) {
  171. return current_scene_data->name;
  172. }
  173. return NULL;
  174. }
  175. void dtmf_dolphin_tone_get_max_pos(uint8_t* max_rows, uint8_t* max_cols, uint8_t* max_span) {
  176. max_rows[0] = 0;
  177. max_cols[0] = 0;
  178. max_span[0] = 0;
  179. uint8_t tmp_rowspan[5] = { 0, 0, 0, 0, 0 };
  180. for (size_t i = 0; i < current_scene_data->tone_count; i++) {
  181. DTMFDolphinTones tones = current_scene_data->tones[i];
  182. if (tones.pos.row > max_rows[0]) {
  183. max_rows[0] = tones.pos.row;
  184. }
  185. if (tones.pos.col > max_cols[0]) {
  186. max_cols[0] = tones.pos.col;
  187. }
  188. tmp_rowspan[tones.pos.row] += tones.pos.span;
  189. if (tmp_rowspan[tones.pos.row] > max_span[0])
  190. max_span[0] = tmp_rowspan[tones.pos.row];
  191. }
  192. max_rows[0]++;
  193. max_cols[0]++;
  194. }
  195. uint8_t dtmf_dolphin_get_tone_span(uint8_t row, uint8_t col) {
  196. for (size_t i = 0; i < current_scene_data->tone_count; i++) {
  197. DTMFDolphinTones tones = current_scene_data->tones[i];
  198. if (tones.pos.row == row && tones.pos.col == col) {
  199. return tones.pos.span;
  200. }
  201. }
  202. return 0;
  203. }