From 56e25c3802c751c55b890bd26351bec205170e5e Mon Sep 17 00:00:00 2001 From: erdgeist Date: Mon, 2 Apr 2018 01:39:01 +0200 Subject: Major refactoring --- main-sdl.c | 197 ++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 102 insertions(+), 95 deletions(-) (limited to 'main-sdl.c') diff --git a/main-sdl.c b/main-sdl.c index d31f725..3303ea8 100644 --- a/main-sdl.c +++ b/main-sdl.c @@ -17,6 +17,7 @@ #include "config.h" #include "engine.h" #include "calib.h" +#include "menu.h" /*** Global config and status values @@ -32,9 +33,6 @@ enum { int g_harfe_connected = 0; int g_harfe_fd = -1; -int g_importing_config = 0; -ConfigSource g_config_source = source_none; -int g_calibration_running = 0; static char * find_harfe() @@ -259,33 +257,74 @@ config_parse(char *config_file) g_config_source = source_file; } -static void -calib_fetch() { - int default_notes[] = { 60, 62, 64, 65, 67, 69, 71, 72, 74, 76, 77, 79, 81, 83 }; - int i, result_count; - LLine *result = calib_get_results(&result_count); +void config_save() { + const char *homeDir = getenv("HOME"); + char savefile[512], date[32], confdump[512]; + time_t t = time(NULL); + struct tm *tmp = localtime(&t); + int i, fd; + size_t len; + + if (!homeDir) { + struct passwd* pwd = getpwuid(getuid()); + if (pwd) + homeDir = (const char*)pwd->pw_dir; + } + strftime(date, sizeof(date), "%Y-%m-%d-%H-%M-%S", tmp); + snprintf( savefile, sizeof(savefile), "%s/Laserharfe-%s.cfg", homeDir, date); + fd = open(savefile, O_WRONLY | O_CREAT | O_TRUNC, 0644); + + len = config_dumpglobals( confdump, sizeof(confdump)); + write(fd, confdump, len ); + for (i=0; ip0.y > g_min_y) - g_min_y = l->p0.y; - if (l->p1.y < g_max_y) - g_max_y = l->p1.y; +void config_export() { + size_t len; + char confdump[512]; + int i; + if (!g_harfe_connected) { + display_messagebox( "Not connected", "Can't write config if Harfe is not connected."); + return; + } + if ((int)g_config_source < 2) { + display_messagebox( "No changes", "Config is unchanged. Won't write config to Harfe."); + return; + } + write(g_harfe_fd, "E\n", 2); + len = config_dumpglobals( confdump, sizeof(confdump)); + write(g_harfe_fd, confdump, len ); + for (i=0; ipw_dir; - } - strftime(date, sizeof(date), "%Y-%m-%d-%H-%M-%S", tmp); - snprintf( savefile, sizeof(savefile), "%s/Laserharfe-%s.cfg", homeDir, date); - fd = open(savefile, O_WRONLY | O_CREAT | O_TRUNC, 0644); - - len = config_dumpglobals( confdump, sizeof(confdump)); - write(fd, confdump, len ); - for (i=0; i 30 && !g_importing_config) { + if (runtime - g_lastredraw > 30) { g_lastredraw = runtime; if (!g_calibration_running) -- cgit v1.2.3