aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2019-04-19 18:22:04 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2019-04-19 18:22:04 +0200
commitf8a64c9dd13d69deadff4c094d407a3bc68e221f (patch)
treed19c6bba452d5d3dfc51bb1d6f8aa16eea7431ce
parentdaa4301da2981fadb6999c694754c16e5d82d781 (diff)
downloadglutte-o-matic-f8a64c9dd13d69deadff4c094d407a3bc68e221f.tar.gz
glutte-o-matic-f8a64c9dd13d69deadff4c094d407a3bc68e221f.tar.bz2
glutte-o-matic-f8a64c9dd13d69deadff4c094d407a3bc68e221f.zip
Fix simulator compilation
-rw-r--r--src/common/includes/Audio/audio_in.h7
-rw-r--r--src/common/includes/Audio/tone.h4
-rw-r--r--src/common/src/Audio/tone.c19
-rw-r--r--src/glutt-o-logique/audio_in.c2
-rw-r--r--src/simulator/src/Audio/audio_in.c32
-rw-r--r--src/simulator/src/GPIO/pio.c15
-rw-r--r--src/simulator/src/Gui/gui.c50
7 files changed, 56 insertions, 73 deletions
diff --git a/src/common/includes/Audio/audio_in.h b/src/common/includes/Audio/audio_in.h
index d2e8378..97a0f29 100644
--- a/src/common/includes/Audio/audio_in.h
+++ b/src/common/includes/Audio/audio_in.h
@@ -35,7 +35,6 @@ void audio_in_initialize(void);
/* Enable or disable the audio input */
void audio_in_enable(int enable);
-// After calling this function, *buffer will point to new audio data.
-// Returns the number of times filling the internal buffer failed.
-int32_t audio_in_get_buffer(int16_t **buffer /*of length AUDIO_IN_BUF_LEN*/ );
-
+/* The audio input layer must call tone_detect_push_sample() to
+ * send the samples
+ */
diff --git a/src/common/includes/Audio/tone.h b/src/common/includes/Audio/tone.h
index 272fcb9..e88cae2 100644
--- a/src/common/includes/Audio/tone.h
+++ b/src/common/includes/Audio/tone.h
@@ -43,7 +43,7 @@ int tone_fax_status(void);
/* Must be called by task to do the analysis */
void tone_do_analysis(void);
-/* Push a sample from the ADC ISR */
-void tone_detect_push_sample_from_irq(const uint16_t sample);
+/* Push a sample from the ADC ISR or Pulseaudio task */
+void tone_detect_push_sample(const uint16_t sample, int is_irq);
#endif
diff --git a/src/common/src/Audio/tone.c b/src/common/src/Audio/tone.c
index b8bebf8..9298b15 100644
--- a/src/common/src/Audio/tone.c
+++ b/src/common/src/Audio/tone.c
@@ -238,7 +238,7 @@ void tone_detector_enable(int enable)
}
}
-void tone_detect_push_sample_from_irq(const uint16_t sample)
+void tone_detect_push_sample(const uint16_t sample, int is_irq)
{
num_samples_analysed++;
@@ -273,10 +273,19 @@ void tone_detect_push_sample_from_irq(const uint16_t sample)
}
BaseType_t require_context_switch = 0;
- int success = xQueueSendToBackFromISR(
- m_squared_queue,
- &m_squared,
- &require_context_switch);
+ int success;
+ if (is_irq) {
+ success = xQueueSendToBackFromISR(
+ m_squared_queue,
+ &m_squared,
+ &require_context_switch);
+ }
+ else {
+ success = xQueueSendToBack(
+ m_squared_queue,
+ &m_squared,
+ 0);
+ }
if (success == pdFALSE) {
lost_results++;
diff --git a/src/glutt-o-logique/audio_in.c b/src/glutt-o-logique/audio_in.c
index 19c54d3..fa3b8bb 100644
--- a/src/glutt-o-logique/audio_in.c
+++ b/src/glutt-o-logique/audio_in.c
@@ -63,7 +63,7 @@ void ADC_IRQHandler()
ADC_ClearITPendingBit(ADC2, ADC_IT_EOC);
- tone_detect_push_sample_from_irq(value);
+ tone_detect_push_sample(value, 1);
}
else if (ADC_GetFlagStatus(ADC2, ADC_FLAG_STRT) == SET) {
// This sometimes happens...
diff --git a/src/simulator/src/Audio/audio_in.c b/src/simulator/src/Audio/audio_in.c
index 45e53ba..19cd5f4 100644
--- a/src/simulator/src/Audio/audio_in.c
+++ b/src/simulator/src/Audio/audio_in.c
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
- * Copyright (c) 2018 Maximilien Cuony
+ * Copyright (c) 2019 Matthias P. Braendli, Maximilien Cuony
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -33,28 +33,21 @@
pa_simple *s_in = NULL;
-static int16_t buffers[2][AUDIO_IN_BUF_LEN];
-static int current_buffer = 0;
+static int16_t buffer[AUDIO_IN_BUF_LEN];
static int enabled = 0; // TODO concurrent access: must be protected by a mutex :-/
-static QueueHandle_t adc2_values_queue;
-
static void audio_buffer_reader(void __attribute__((unused))*args)
{
while (1) {
- pa_simple_read(s_in, buffers[current_buffer], AUDIO_IN_BUF_LEN * sizeof(int16_t), NULL);
+ pa_simple_read(s_in, buffer, AUDIO_IN_BUF_LEN * sizeof(int16_t), NULL);
if (enabled) {
- int success = xQueueSendToBack(
- adc2_values_queue,
- &current_buffer,
- portMAX_DELAY);
- assert(success);
+ for (int i = 0; i < AUDIO_IN_BUF_LEN; i++) {
+ tone_detect_push_sample(buffer[i] + (INT16_MAX >> 1), 0);
+ }
}
- current_buffer = (current_buffer + 1) % 2;
-
taskYIELD();
}
}
@@ -74,9 +67,6 @@ void audio_in_initialize() {
s_in = pa_simple_new(NULL, "GlutteR", PA_STREAM_RECORD, NULL, "record", &ss, NULL, NULL, &error);
assert(s_in);
- adc2_values_queue = xQueueCreate(4, sizeof(current_buffer));
- assert(adc2_values_queue);
-
TaskHandle_t task_handle;
xTaskCreate(
audio_buffer_reader,
@@ -92,13 +82,3 @@ void audio_in_enable(int enable)
enabled = enable;
}
-int32_t audio_in_get_buffer(int16_t **buffer /*of length AUDIO_IN_BUF_LEN*/ )
-{
- int last_written_buffer = 0;
- while (!xQueueReceive(adc2_values_queue, &last_written_buffer, portMAX_DELAY)) {}
-
- *buffer = buffers[last_written_buffer];
-
- return 0;
-}
-
diff --git a/src/simulator/src/GPIO/pio.c b/src/simulator/src/GPIO/pio.c
index 75c8705..13cf453 100644
--- a/src/simulator/src/GPIO/pio.c
+++ b/src/simulator/src/GPIO/pio.c
@@ -38,6 +38,9 @@ extern int gui_in_d;
extern int gui_in_replie;
extern int gui_in_fax_n;
extern char led_gps;
+extern char led_fax;
+extern char led_det_1750;
+extern char led_sq2;
void pio_init(void) {
}
@@ -58,6 +61,18 @@ void pio_set_gps_epps(int on) {
led_gps = on;
}
+void pio_set_fax(int on) {
+ led_fax = on;
+}
+
+void pio_set_det_1750(int on) {
+ led_det_1750 = on;
+}
+
+void pio_set_sq2(int on) {
+ led_sq2 = on;
+}
+
void pio_set_fsm_signals(struct fsm_input_signals_t* sig) {
sig->button_1750 = gui_in_1750_n ? 0 : 1;
sig->qrp = gui_in_qrp_n ? 0 : 1;
diff --git a/src/simulator/src/Gui/gui.c b/src/simulator/src/Gui/gui.c
index f6f9ab9..498fd9a 100644
--- a/src/simulator/src/Gui/gui.c
+++ b/src/simulator/src/Gui/gui.c
@@ -86,6 +86,9 @@ char led_green = 0;
char led_orange = 0;
char led_red = 0;
char led_gps = 0;
+char led_fax = 0;
+char led_det_1750 = 0;
+char led_sq2 = 0;
/**
* GPS
@@ -458,16 +461,12 @@ void main_gui() {
nk_end(ctx);
- if (nk_begin(ctx, &layout, "LEDs", nk_rect(50, 390, 150, 155), NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) {
+ if (nk_begin(ctx, &layout, "LEDs", nk_rect(50, 390, 150, 155), NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) {
nk_layout_row_static(ctx, 20, 20, 5);
-
struct nk_color color;
- nk_text(ctx, "", 0, NK_TEXT_LEFT);
-
color.r = 255; color.g = 165; color.b = 0;
-
if (led_orange == 1) {
color.a = 255;
} else {
@@ -475,15 +474,7 @@ void main_gui() {
}
nk_button_color(ctx, color, NK_BUTTON_DEFAULT);
-
- nk_text(ctx, "", 0, NK_TEXT_LEFT);
- nk_text(ctx, "", 0, NK_TEXT_LEFT);
- nk_text(ctx, "", 0, NK_TEXT_LEFT);
-
- /**/
-
color.r = 0; color.g = 255; color.b = 0;
-
if (led_green == 1) {
color.a = 255;
} else {
@@ -491,10 +482,7 @@ void main_gui() {
}
nk_button_color(ctx, color, NK_BUTTON_DEFAULT);
- nk_text(ctx, "", 0, NK_TEXT_LEFT);
-
color.r = 255; color.g = 0; color.b = 0;
-
if (led_red == 1) {
color.a = 255;
} else {
@@ -502,23 +490,7 @@ void main_gui() {
}
nk_button_color(ctx, color, NK_BUTTON_DEFAULT);
- nk_text(ctx, "", 0, NK_TEXT_LEFT);
-
- color.r = 0; color.g = 255; color.b = 255;
-
- if (led_gps == 1) {
- color.a = 255;
- } else {
- color.a = 30;
- }
- nk_button_color(ctx, color, NK_BUTTON_DEFAULT);
-
- /**/
-
- nk_text(ctx, "", 0, NK_TEXT_LEFT);
-
color.r = 0; color.g = 0; color.b = 255;
-
if (led_blue == 1) {
color.a = 255;
} else {
@@ -526,9 +498,17 @@ void main_gui() {
}
nk_button_color(ctx, color, NK_BUTTON_DEFAULT);
- nk_text(ctx, "", 0, NK_TEXT_LEFT);
- nk_text(ctx, "", 0, NK_TEXT_LEFT);
- nk_text(ctx, "", 0, NK_TEXT_LEFT);
+#define SW_LED(var, name) \
+ nk_layout_row_static(ctx, 20, 20, 5); \
+ color.r = 0; color.g = 255; color.b = 255; \
+ if (var == 1) { color.a = 255; } else { color.a = 30; } \
+ nk_button_color(ctx, color, NK_BUTTON_DEFAULT); \
+ nk_label(ctx, name, NK_TEXT_LEFT);
+
+ SW_LED(led_gps, "GPS")
+ SW_LED(led_fax, "FAX")
+ SW_LED(led_det_1750, "TONE")
+ SW_LED(led_sq2, "SQ2")
}
nk_end(ctx);