dtmf_dolphin_data.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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, 3, 2}, 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, 4}, 1, 66, 0},
  71. {"Dime", 1700.0, 2200.0, {1, 0, 4}, 2, 66, 66},
  72. {"Quarter", 1700.0, 2200.0, {2, 0, 4}, 5, 33, 33},
  73. {"Dollar", 1700.0, 2200.0, {3, 0, 4}, 1, 650, 0},
  74. }
  75. };
  76. DTMFDolphinSceneData DTMFDolphinSceneDataRedboxUK = {
  77. .name = "Redbox (UK)",
  78. .block = DTMF_DOLPHIN_TONE_BLOCK_REDBOX_UK,
  79. .tone_count = 2,
  80. .tones = {
  81. {"10p", 1000.0, 0.0, {0, 0, 3}, 1, 200, 0},
  82. {"50p", 1000.0, 0.0, {1, 0, 3}, 1, 350, 0},
  83. }
  84. };
  85. DTMFDolphinSceneData DTMFDolphinSceneDataMisc = {
  86. .name = "Misc",
  87. .block = DTMF_DOLPHIN_TONE_BLOCK_MISC,
  88. .tone_count = 3,
  89. .tones = {
  90. {"CCITT 11", 700.0, 1700.0, {0, 0, 4}, 0, 0, 0},
  91. {"CCITT 12", 900.0, 1700.0, {1, 0, 4}, 0, 0, 0},
  92. {"CCITT KP2", 1300.0, 1700.0, {2, 0, 4}, 0, 0, 0},
  93. }
  94. };
  95. DTMFDolphinToneSection current_section;
  96. DTMFDolphinSceneData *current_scene_data;
  97. void dtmf_dolphin_data_set_current_section(DTMFDolphinToneSection section) {
  98. current_section = section;
  99. switch (current_section)
  100. {
  101. case DTMF_DOLPHIN_TONE_BLOCK_BLUEBOX:
  102. current_scene_data = &DTMFDolphinSceneDataBluebox;
  103. break;
  104. case DTMF_DOLPHIN_TONE_BLOCK_REDBOX_US:
  105. current_scene_data = &DTMFDolphinSceneDataRedboxUS;
  106. break;
  107. case DTMF_DOLPHIN_TONE_BLOCK_REDBOX_UK:
  108. current_scene_data = &DTMFDolphinSceneDataRedboxUK;
  109. break;
  110. case DTMF_DOLPHIN_TONE_BLOCK_MISC:
  111. current_scene_data = &DTMFDolphinSceneDataMisc;
  112. break;
  113. default: // DTMF_DOLPHIN_TONE_BLOCK_DIALER:
  114. current_scene_data = &DTMFDolphinSceneDataDialer;
  115. break;
  116. }
  117. }
  118. DTMFDolphinToneSection dtmf_dolphin_data_get_current_section() {
  119. return current_section;
  120. }
  121. DTMFDolphinSceneData *dtmf_dolphin_data_get_current_scene_data() {
  122. return current_scene_data;
  123. }
  124. bool dtmf_dolphin_data_get_tone_frequencies(float *freq1, float *freq2, uint8_t row, uint8_t col) {
  125. for (size_t i = 0; i < current_scene_data->tone_count; i++) {
  126. DTMFDolphinTones tones = current_scene_data->tones[i];
  127. if (tones.pos.row == row && tones.pos.col == col) {
  128. freq1[0] = tones.frequency_1;
  129. freq2[0] = tones.frequency_2;
  130. return true;
  131. }
  132. }
  133. return false;
  134. }
  135. const char* dtmf_dolphin_data_get_tone_name(uint8_t row, uint8_t col) {
  136. for (size_t i = 0; i < current_scene_data->tone_count; i++) {
  137. DTMFDolphinTones tones = current_scene_data->tones[i];
  138. if (tones.pos.row == row && tones.pos.col == col) {
  139. return tones.name;
  140. }
  141. }
  142. return NULL;
  143. }
  144. const char* dtmf_dolphin_data_get_current_section_name() {
  145. if (current_scene_data) {
  146. return current_scene_data->name;
  147. }
  148. return NULL;
  149. }
  150. void dtmf_dolphin_tone_get_max_pos(uint8_t* max_rows, uint8_t* max_cols, uint8_t* max_span) {
  151. max_rows[0] = 0;
  152. max_cols[0] = 0;
  153. max_span[0] = 0;
  154. uint8_t tmp_rowspan[5] = { 0, 0, 0, 0, 0 };
  155. for (size_t i = 0; i < current_scene_data->tone_count; i++) {
  156. DTMFDolphinTones tones = current_scene_data->tones[i];
  157. if (tones.pos.row > max_rows[0]) {
  158. max_rows[0] = tones.pos.row;
  159. }
  160. if (tones.pos.col > max_cols[0]) {
  161. max_cols[0] = tones.pos.col;
  162. }
  163. tmp_rowspan[tones.pos.row] += tones.pos.span;
  164. if (tmp_rowspan[tones.pos.row] > max_span[0])
  165. max_span[0] = max_span[tones.pos.row];
  166. }
  167. max_rows[0]++;
  168. max_cols[0]++;
  169. }
  170. uint8_t dtmf_dolphin_get_tone_span(uint8_t row, uint8_t col) {
  171. for (size_t i = 0; i < current_scene_data->tone_count; i++) {
  172. DTMFDolphinTones tones = current_scene_data->tones[i];
  173. if (tones.pos.row == row && tones.pos.col == col) {
  174. return tones.pos.span;
  175. }
  176. }
  177. return 0;
  178. }