aboutsummaryrefslogtreecommitdiffstats
path: root/src/simulator
diff options
context:
space:
mode:
authorMaximilien Cuony <maximilien@theglu.org>2016-06-04 00:24:30 +0200
committerMaximilien Cuony <maximilien@theglu.org>2016-06-04 00:24:30 +0200
commitf4a93ecce5813c9ddf9e5dc4a416777681dc04f9 (patch)
tree20f9a258417da24fcabb62819f76bf81e60f0834 /src/simulator
parent53c2afbf719d91f660e815c160e73066ef1ec9e0 (diff)
downloadglutte-o-matic-f4a93ecce5813c9ddf9e5dc4a416777681dc04f9.tar.gz
glutte-o-matic-f4a93ecce5813c9ddf9e5dc4a416777681dc04f9.tar.bz2
glutte-o-matic-f4a93ecce5813c9ddf9e5dc4a416777681dc04f9.zip
Simulator: GPS, Audio, CW
Diffstat (limited to 'src/simulator')
-rw-r--r--src/simulator/Makefile2
-rw-r--r--src/simulator/src/Audio/audio.c140
-rw-r--r--src/simulator/src/Audio/cw.c32
-rw-r--r--src/simulator/src/Core/main.c2
-rw-r--r--src/simulator/src/Gui/gui.c69
5 files changed, 241 insertions, 4 deletions
diff --git a/src/simulator/Makefile b/src/simulator/Makefile
index 511b6e6..663570e 100644
--- a/src/simulator/Makefile
+++ b/src/simulator/Makefile
@@ -70,7 +70,7 @@ CWARNS += -Wmissing-prototypes
CFLAGS += -m32
CFLAGS += -DDEBUG=1
-CFLAGS += -g -DUSE_STDIO=1 -D__GCC_POSIX__=1 -lX11 -lm -lGL -lm -lGLU
+CFLAGS += -g -DUSE_STDIO=1 -D__GCC_POSIX__=1 -lX11 -lm -lGL -lm -lGLU -lpulse-simple -lpulse
ifneq ($(shell uname), Darwin)
CFLAGS += -pthread
endif
diff --git a/src/simulator/src/Audio/audio.c b/src/simulator/src/Audio/audio.c
new file mode 100644
index 0000000..0d21305
--- /dev/null
+++ b/src/simulator/src/Audio/audio.c
@@ -0,0 +1,140 @@
+#include "../../../common/src/Audio/audio.c"
+
+#include <pulse/simple.h>
+#include "FreeRTOS.h"
+#include "task.h"
+
+
+pa_simple *s = NULL;
+
+int current_buffer_length = 0;
+int16_t * current_buffer_samples;
+
+static void audio_buffer_sender(void *args);
+
+extern char gui_audio_on;
+
+void audio_initialize_platform(int plln, int pllr, int i2sdiv, int i2sodd, int rate) {
+
+ int error;
+
+ static pa_sample_spec ss = {
+ .format = PA_SAMPLE_S16LE,
+ .rate = 0,
+ .channels = 1
+ };
+
+ ss.rate = rate;
+
+ if (s = pa_simple_new(NULL, "Glutte", PA_STREAM_PLAYBACK, NULL, "playback", &ss, NULL, NULL, &error)) {
+
+ } else {
+ printf("Pulseaudio playback init error\n");
+ while(1);
+ }
+
+
+ TaskHandle_t task_handle;
+ xTaskCreate(
+ audio_buffer_sender,
+ "Audio buffer sender",
+ configMINIMAL_STACK_SIZE,
+ (void*) NULL,
+ tskIDLE_PRIORITY + 2UL,
+ &task_handle);
+
+}
+
+static void audio_buffer_sender(void *args) {
+
+ while(1) {
+
+ if (current_buffer_length != 0) {
+ pa_simple_write(s, current_buffer_samples, current_buffer_length * 2, NULL);
+ current_buffer_length = 0;
+ audio_buffer_sent();
+ }
+
+ taskYIELD();
+ }
+
+}
+
+void audio_buffer_sent() {
+
+ if (next_buffer_samples) {
+ audio_start_dma_and_request_buffers();
+ } else {
+ dma_running = false;
+ }
+
+}
+
+void audio_on() {
+ gui_audio_on = 1;
+}
+
+void audio_off() {
+ gui_audio_on = 0;
+}
+
+void audio_set_volume(int volume) {
+}
+
+
+void audio_output_sample_without_blocking(int16_t sample) {
+}
+
+void audio_play_with_callback(AudioCallbackFunction *callback, void *context) {
+ audio_stop_dma();
+
+ callback_function = callback;
+ callback_context = context;
+ buffer_number = 0;
+
+ if (callback_function)
+ callback_function(callback_context, buffer_number);
+}
+
+void audio_stop() {
+ audio_stop_dma();
+ callback_function = NULL;
+}
+
+void audio_provide_buffer(void *samples, int numsamples) {
+ while (!audio_provide_buffer_without_blocking(samples, numsamples))
+ __asm__ volatile ("nop");
+}
+
+bool audio_provide_buffer_without_blocking(void *samples, int numsamples) {
+ if (next_buffer_samples)
+ return false;
+
+ next_buffer_samples = samples;
+ next_buffer_length = numsamples;
+
+ if (!dma_running)
+ audio_start_dma_and_request_buffers();
+
+ return true;
+}
+
+static void audio_start_dma_and_request_buffers() {
+
+ current_buffer_length = next_buffer_length;
+ current_buffer_samples = next_buffer_samples;
+
+ // Update state.
+ next_buffer_samples = NULL;
+ buffer_number ^= 1;
+ dma_running = true;
+
+ // Invoke callback if it exists to queue up another buffer.
+ if (callback_function)
+ callback_function(callback_context, buffer_number);
+}
+
+static void audio_stop_dma() {
+ dma_running = false;
+}
+
diff --git a/src/simulator/src/Audio/cw.c b/src/simulator/src/Audio/cw.c
new file mode 100644
index 0000000..0f37be4
--- /dev/null
+++ b/src/simulator/src/Audio/cw.c
@@ -0,0 +1,32 @@
+#include "../../../common/src/Audio/cw.c"
+
+extern char gui_cw_text[4096];
+int gui_cw_text_pointer = 0;
+
+void cw_move_buffer_up() {
+
+ for (int i = 0; i <= 4010; i++) {
+ gui_cw_text[i] = gui_cw_text[i + 10];
+ gui_cw_text[i + 1] = '\0';
+ }
+
+ gui_cw_text_pointer -= 10;
+
+}
+void cw_message_sent(const char* str) {
+
+ while(*str) {
+ gui_cw_text[gui_cw_text_pointer+1] = '\0';
+ gui_cw_text[gui_cw_text_pointer] = *str;
+ gui_cw_text_pointer++;
+
+ if (gui_cw_text_pointer >= 4000) {
+ cw_move_buffer_up();
+ }
+ str++;
+ }
+
+ gui_cw_text[gui_cw_text_pointer+1] = '\0';
+ gui_cw_text[gui_cw_text_pointer] = '\n';
+ gui_cw_text_pointer++;
+}
diff --git a/src/simulator/src/Core/main.c b/src/simulator/src/Core/main.c
index 853ee83..088e344 100644
--- a/src/simulator/src/Core/main.c
+++ b/src/simulator/src/Core/main.c
@@ -58,7 +58,7 @@ char gui_gps_custom_day[4];
int gui_gps_custom_day_len;
char gui_gps_custom_month[4];
int gui_gps_custom_month_len;
-char gui_gps_custom_year[6];
+char gui_gps_custom_year[4];
int gui_gps_custom_year_len;
static void thread_gui_gps(void *arg) {
diff --git a/src/simulator/src/Gui/gui.c b/src/simulator/src/Gui/gui.c
index 58bbb78..cd7e004 100644
--- a/src/simulator/src/Gui/gui.c
+++ b/src/simulator/src/Gui/gui.c
@@ -86,6 +86,14 @@ int gui_gps_custom_month_len = 2;
char gui_gps_custom_year[4] = "16";
int gui_gps_custom_year_len = 2;
+
+/**
+ * Audio
+ **/
+char gui_audio_on = 0;
+char gui_cw_text[4096];
+
+
struct XWindow {
Display *dpy;
Window win;
@@ -314,12 +322,12 @@ int main_gui() {
uart_send_txt_len = 0;
}
- nk_menubar_end(ctx);
nk_layout_row_dynamic(ctx, 25, 1);
-
nk_label(ctx, "UART Output:", NK_TEXT_LEFT);
+ nk_menubar_end(ctx);
+
nk_layout_row_dynamic(ctx, 16, 1);
char * current_pointer = uart_recv_txt;
@@ -400,6 +408,63 @@ int main_gui() {
}
nk_end(ctx);
+ if (nk_begin(ctx, &layout, "Audio", nk_rect(160, 360, 100, 155), NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) {
+
+ nk_layout_row_static(ctx, 20, 20, 3);
+
+ struct nk_color color;
+
+ nk_text(ctx, "", 0, NK_TEXT_LEFT);
+ nk_text(ctx, "", 0, NK_TEXT_LEFT);
+ nk_text(ctx, "", 0, NK_TEXT_LEFT);
+
+ nk_text(ctx, "", 0, NK_TEXT_LEFT);
+
+ color.r = 255; color.g = 255; color.b = 0; color.a = 255;
+
+ if (gui_audio_on == 1) {
+ color.r = 0;
+ } else {
+ color.g = 0;
+ }
+ nk_button_color(ctx, color, NK_BUTTON_DEFAULT);
+ }
+ nk_end(ctx);
+
+
+ if (nk_begin(ctx, &layout, "CW", nk_rect(270, 360, 180, 155), NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) {
+
+ nk_menubar_begin(ctx);
+ nk_layout_row_dynamic(ctx, 25, 1);
+
+ nk_label(ctx, "CW Buffer:", NK_TEXT_LEFT);
+
+ nk_menubar_end(ctx);
+
+ nk_layout_row_dynamic(ctx, 16, 1);
+
+ char * current_pointer = gui_cw_text;
+ int l = 0;
+
+ while (*current_pointer != 0) {
+
+ if (*current_pointer == '\n') {
+ if (l > 1) {
+ nk_text(ctx, current_pointer - l, l, NK_TEXT_LEFT);
+ }
+ current_pointer++;
+ l = 0;
+ }
+ current_pointer++;
+ l++;
+ }
+
+ if (l > 1) {
+ nk_text(ctx, current_pointer - l, l, NK_TEXT_LEFT);
+ }
+ }
+ nk_end(ctx);
+
if (nk_begin(ctx, &layout, "GPS", nk_rect(460, 50, 200, 465), NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) {
nk_layout_row_dynamic(ctx, 30, 1);