dtmf_dolphin_data.c 7.2 KB

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