dtmf_dolphin_data.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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 = 3,
  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. }};
  99. DTMFDolphinToneSection current_section;
  100. DTMFDolphinSceneData* current_scene_data;
  101. void dtmf_dolphin_data_set_current_section(DTMFDolphinToneSection section) {
  102. current_section = section;
  103. switch(current_section) {
  104. case DTMF_DOLPHIN_TONE_BLOCK_BLUEBOX:
  105. current_scene_data = &DTMFDolphinSceneDataBluebox;
  106. break;
  107. case DTMF_DOLPHIN_TONE_BLOCK_REDBOX_US:
  108. current_scene_data = &DTMFDolphinSceneDataRedboxUS;
  109. break;
  110. case DTMF_DOLPHIN_TONE_BLOCK_REDBOX_CA:
  111. current_scene_data = &DTMFDolphinSceneDataRedboxCA;
  112. break;
  113. case DTMF_DOLPHIN_TONE_BLOCK_REDBOX_UK:
  114. current_scene_data = &DTMFDolphinSceneDataRedboxUK;
  115. break;
  116. case DTMF_DOLPHIN_TONE_BLOCK_MISC:
  117. current_scene_data = &DTMFDolphinSceneDataMisc;
  118. break;
  119. default: // DTMF_DOLPHIN_TONE_BLOCK_DIALER:
  120. current_scene_data = &DTMFDolphinSceneDataDialer;
  121. break;
  122. }
  123. }
  124. DTMFDolphinToneSection dtmf_dolphin_data_get_current_section() {
  125. return current_section;
  126. }
  127. DTMFDolphinSceneData* dtmf_dolphin_data_get_current_scene_data() {
  128. return current_scene_data;
  129. }
  130. bool dtmf_dolphin_data_get_tone_frequencies(float* freq1, float* freq2, uint8_t row, uint8_t col) {
  131. for(size_t i = 0; i < current_scene_data->tone_count; i++) {
  132. DTMFDolphinTones tones = current_scene_data->tones[i];
  133. if(tones.pos.row == row && tones.pos.col == col) {
  134. freq1[0] = tones.frequency_1;
  135. freq2[0] = tones.frequency_2;
  136. return true;
  137. }
  138. }
  139. return false;
  140. }
  141. bool dtmf_dolphin_data_get_filter_data(
  142. uint16_t* pulses,
  143. uint16_t* pulse_ms,
  144. uint16_t* gap_ms,
  145. uint8_t row,
  146. uint8_t col) {
  147. for(size_t i = 0; i < current_scene_data->tone_count; i++) {
  148. DTMFDolphinTones tones = current_scene_data->tones[i];
  149. if(tones.pos.row == row && tones.pos.col == col) {
  150. pulses[0] = tones.pulses;
  151. pulse_ms[0] = tones.pulse_ms;
  152. gap_ms[0] = tones.gap_duration;
  153. return true;
  154. }
  155. }
  156. return false;
  157. }
  158. const char* dtmf_dolphin_data_get_tone_name(uint8_t row, uint8_t col) {
  159. for(size_t i = 0; i < current_scene_data->tone_count; i++) {
  160. DTMFDolphinTones tones = current_scene_data->tones[i];
  161. if(tones.pos.row == row && tones.pos.col == col) {
  162. return tones.name;
  163. }
  164. }
  165. return NULL;
  166. }
  167. const char* dtmf_dolphin_data_get_current_section_name() {
  168. if(current_scene_data) {
  169. return current_scene_data->name;
  170. }
  171. return NULL;
  172. }
  173. void dtmf_dolphin_tone_get_max_pos(uint8_t* max_rows, uint8_t* max_cols, uint8_t* max_span) {
  174. max_rows[0] = 0;
  175. max_cols[0] = 0;
  176. max_span[0] = 0;
  177. uint8_t tmp_rowspan[5] = {0, 0, 0, 0, 0};
  178. for(size_t i = 0; i < current_scene_data->tone_count; i++) {
  179. DTMFDolphinTones tones = current_scene_data->tones[i];
  180. if(tones.pos.row > max_rows[0]) {
  181. max_rows[0] = tones.pos.row;
  182. }
  183. if(tones.pos.col > max_cols[0]) {
  184. max_cols[0] = tones.pos.col;
  185. }
  186. tmp_rowspan[tones.pos.row] += tones.pos.span;
  187. if(tmp_rowspan[tones.pos.row] > max_span[0]) max_span[0] = tmp_rowspan[tones.pos.row];
  188. }
  189. max_rows[0]++;
  190. max_cols[0]++;
  191. }
  192. uint8_t dtmf_dolphin_get_tone_span(uint8_t row, uint8_t col) {
  193. for(size_t i = 0; i < current_scene_data->tone_count; i++) {
  194. DTMFDolphinTones tones = current_scene_data->tones[i];
  195. if(tones.pos.row == row && tones.pos.col == col) {
  196. return tones.pos.span;
  197. }
  198. }
  199. return 0;
  200. }