aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2019-04-13 15:46:03 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2019-04-13 15:46:03 +0200
commiteab1a72287410908349edca76702faed7ac0e348 (patch)
treea9e75b5dd576434494d33cf3463519f4dcd0f4c5 /src
parent74f34510c6f51b5510a80431369fe61c384c72c1 (diff)
downloadglutte-o-matic-eab1a72287410908349edca76702faed7ac0e348.tar.gz
glutte-o-matic-eab1a72287410908349edca76702faed7ac0e348.tar.bz2
glutte-o-matic-eab1a72287410908349edca76702faed7ac0e348.zip
Enable FAX mode when DTMF sequence detected
Diffstat (limited to 'src')
-rw-r--r--src/common/includes/Audio/tone.h1
-rw-r--r--src/common/includes/GPIO/pio.h3
-rw-r--r--src/common/src/Audio/tone.c42
-rw-r--r--src/common/src/Core/main.c4
-rw-r--r--src/glutt-o-logique/pio.c34
5 files changed, 71 insertions, 13 deletions
diff --git a/src/common/includes/Audio/tone.h b/src/common/includes/Audio/tone.h
index a4692df..294fe54 100644
--- a/src/common/includes/Audio/tone.h
+++ b/src/common/includes/Audio/tone.h
@@ -47,6 +47,7 @@ void tone_detector_enable(int enable);
/* Return 1 when 1750 detected, 0 otherwise */
int tone_1750_status(void);
+/* The FAX status is 1 if the recently decoded DTMF is the 0-7-* sequence. */
int tone_fax_status(void);
/* Update all tone detection status */
diff --git a/src/common/includes/GPIO/pio.h b/src/common/includes/GPIO/pio.h
index a9a506d..e118fc8 100644
--- a/src/common/includes/GPIO/pio.h
+++ b/src/common/includes/GPIO/pio.h
@@ -35,6 +35,9 @@ void pio_set_tx(int on);
void pio_set_mod_off(int mod_off);
void pio_set_qrp(int on);
void pio_set_gps_epps(int on);
+void pio_set_fax(int on);
+void pio_set_det_1750(int on);
+void pio_set_sq2(int on);
void pio_set_fsm_signals(struct fsm_input_signals_t* sig);
diff --git a/src/common/src/Audio/tone.c b/src/common/src/Audio/tone.c
index ebfa5ee..29e2936 100644
--- a/src/common/src/Audio/tone.c
+++ b/src/common/src/Audio/tone.c
@@ -81,28 +81,48 @@ static uint64_t dtmf_last_seen_at = 0;
#define DTMF_MAX_TONE_INTERVAL 1500
static enum dtmf_code dtmf_sequence[NUM_DTMF_SEQ];
+static char* dtmf_to_str(enum dtmf_code code)
+{
+ char *codestr;
+ switch (code) {
+ case DTMF_0: codestr = "0"; break;
+ case DTMF_7: codestr = "7"; break;
+ case DTMF_8: codestr = "8"; break;
+ case DTMF_STAR: codestr = "*"; break;
+ case DTMF_NONE: codestr = "x"; break;
+ }
+ return codestr;
+}
+
static inline void push_dtmf_code(enum dtmf_code code)
{
for (int i = 0; i < NUM_DTMF_SEQ-1; i++) {
dtmf_sequence[i] = dtmf_sequence[i+1];
}
dtmf_sequence[NUM_DTMF_SEQ-1] = code;
+
+ usart_debug("DTMF: [%s, %s, %s]\r\n",
+ dtmf_to_str(dtmf_sequence[0]),
+ dtmf_to_str(dtmf_sequence[1]),
+ dtmf_to_str(dtmf_sequence[2]));
}
-const int thresh = 400; // TODO: Does that depend on TONE_N?
+// TODO: Does that depend on TONE_N?
+const int thresh_dtmf = 200;
+const int thresh_1750 = 200;
static void analyse_dtmf()
{
// Bits 0 to 9 are numbers, bit 10 to 13 letters, bit 14 is star, 15 is hash
const uint16_t pattern =
- ((normalised_results[DET_COL_1] > thresh &&
- normalised_results[DET_ROW_7] > thresh) ? (1 << 7) : 0) +
- ((normalised_results[DET_COL_2] > thresh &&
- normalised_results[DET_ROW_7] > thresh) ? (1 << 8) : 0) +
- ((normalised_results[DET_COL_1] > thresh &&
- normalised_results[DET_ROW_STAR] > thresh) ? (1 << 14) : 0) +
- ((normalised_results[DET_COL_2] > thresh &&
- normalised_results[DET_ROW_STAR] > thresh) ? (1 << 0) : 0);
+ ((normalised_results[DET_COL_1] > thresh_dtmf &&
+ normalised_results[DET_ROW_7] > thresh_dtmf) ? (1 << 7) : 0) +
+ ((normalised_results[DET_COL_2] > thresh_dtmf &&
+ normalised_results[DET_ROW_7] > thresh_dtmf) ? (1 << 8) : 0) +
+ ((normalised_results[DET_COL_1] > thresh_dtmf &&
+ normalised_results[DET_ROW_STAR] > thresh_dtmf) ? (1 << 14) : 0) +
+ ((normalised_results[DET_COL_2] > thresh_dtmf &&
+ normalised_results[DET_ROW_STAR] > thresh_dtmf) ? (1 << 0) : 0);
// Match patterns exactly to exclude multiple simultaneous DTMF codes.
if (pattern == (1 << 0)) {
@@ -137,7 +157,7 @@ static void analyse_dtmf()
dtmf_last_seen = DTMF_STAR;
dtmf_last_seen_at = timestamp_now();
}
- else if (dtmf_last_seen_at + DTMF_MAX_TONE_INTERVAL > timestamp_now()) {
+ else if (dtmf_last_seen_at + DTMF_MAX_TONE_INTERVAL < timestamp_now()) {
// Flush out all codes
push_dtmf_code(DTMF_NONE);
@@ -283,7 +303,7 @@ void tone_detect_push_samples(const int16_t *samples, int len)
>> 4; // divide by 16
}
- tone_1750_detected = (normalised_results[DET_1750] > thresh);
+ tone_1750_detected = (normalised_results[DET_1750] > thresh_1750);
analyse_dtmf();
static int printcounter = 0;
diff --git a/src/common/src/Core/main.c b/src/common/src/Core/main.c
index 44d7e9c..1ed6088 100644
--- a/src/common/src/Core/main.c
+++ b/src/common/src/Core/main.c
@@ -585,7 +585,9 @@ static void exercise_fsm(void __attribute__ ((unused))*pvParameters)
gui_in_tone_1750 =
#endif
fsm_input.det_1750 = tone_1750_status();
- fsm_input.fax_mode = 0;
+ pio_set_det_1750(fsm_input.det_1750);
+ fsm_input.fax_mode = tone_fax_status();
+ pio_set_fax(fsm_input.fax_mode);
fsm_input.swr_high = swr_error_flag;
fsm_input.hour_is_even = hour_is_even;
diff --git a/src/glutt-o-logique/pio.c b/src/glutt-o-logique/pio.c
index 1069886..ba52282 100644
--- a/src/glutt-o-logique/pio.c
+++ b/src/glutt-o-logique/pio.c
@@ -317,5 +317,37 @@ void pio_set_gps_epps(int on)
}
}
-#warning "TODO: add output functions for SQ2, DET 1750 and FAX"
+void pio_set_fax(int on)
+{
+ if (on) {
+ GPIO_SetBits(GPIOC, GPIOC_PIN_FAX);
+ }
+ else {
+ GPIO_ResetBits(GPIOC, GPIOC_PIN_FAX);
+ }
+}
+
+void pio_set_det_1750(int on)
+{
+ if (on) {
+ GPIO_ResetBits(GPIOA, GPIOA_PIN_DET_1750);
+ }
+ else {
+ GPIO_SetBits(GPIOA, GPIOA_PIN_DET_1750);
+ }
+}
+
+void pio_set_sq2(int on)
+{
+ if (on) {
+ GPIO_SetBits(GPIOC, GPIOC_PIN_SQ2);
+ }
+ else {
+ GPIO_ResetBits(GPIOC, GPIOC_PIN_SQ2);
+ }
+}
+
+#warning "TODO Test SQ2 out"
+#warning "TODO Test 1750 out"
+#warning "TODO Test FAX out"