From 85f228fe9ee3ff618e08b7ec9fc8144eb734261b Mon Sep 17 00:00:00 2001 From: Steffen Pohle Date: Sun, 29 Jan 2023 17:23:07 +0100 Subject: [PATCH] adding error message diablog --- Makefile | 2 +- error.cc | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ error.h | 20 +++++++++++++++++++ gui.cc | 14 ------------- gui.h | 11 +++++++---- posctl.cc | 8 ++++++-- 6 files changed, 93 insertions(+), 21 deletions(-) create mode 100644 error.cc create mode 100644 error.h diff --git a/Makefile b/Makefile index e46c355..a1ae7d6 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ APP = simpleskycam -include Makefile.rules -OBJECTS := $(OBJECTS) gui.oo main.oo \ +OBJECTS := $(OBJECTS) gui.oo main.oo error.oo \ video.oo videoframe.oo \ videodev.oo videodev-v4l2.oo videodev-dumpfile.oo \ convert.oo filter.oo detect.oo histogram.oo pid.oo \ diff --git a/error.cc b/error.cc new file mode 100644 index 0000000..1c5ef10 --- /dev/null +++ b/error.cc @@ -0,0 +1,59 @@ +/*************************************************************************************** + * + * error.h is part of SimpleSkyCam. + * + *****************************************************************************************/ + +#include +#include +#include +#include +#include +#include "gui.h" +#include "error.h" +#include "configuration.h" + +extern GtkBuilder *_builder_; // work around for threads + +gboolean errormessage_thread (gpointer data) { + struct ErrorMessage *em = (struct ErrorMessage*) data; + GtkWidget *window = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), + em->window)); + + if (window == NULL) window = GTK_WIDGET(gtk_builder_get_object (GTK_BUILDER(_builder_), + "window-main")); + + GtkWidget *dialog; + dialog = gtk_message_dialog_new(GTK_WINDOW(window), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_OK, + "%s", em->message); + gtk_window_set_title(GTK_WINDOW(dialog), em->title); + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); + + free (em); + + return false; +}; + + +void errormessage_display (char *window, char *title, char *fmt,...) { + struct ErrorMessage *em = (struct ErrorMessage *) malloc (sizeof (struct ErrorMessage)); + + va_list args; + char buffer[ERRORMSG_LEN]; + + va_start (args, fmt); + vsnprintf (buffer, (ERRORMSG_LEN-1), fmt, args); + va_end (args); + buffer[ERRORMSG_LEN-1] = 0; + strncpy(em->title, title, ERRORMSG_LEN); em->title[ERRORMSG_LEN-1] = 0; + strncpy(em->message, buffer, ERRORMSG_LEN); em->message[ERRORMSG_LEN-1] = 0; + strncpy(em->window, window, ERRORMSG_LEN); em->window[ERRORMSG_LEN-1] = 0; + + gdk_threads_add_idle(errormessage_thread, em); +}; + + diff --git a/error.h b/error.h new file mode 100644 index 0000000..11343e3 --- /dev/null +++ b/error.h @@ -0,0 +1,20 @@ +/*************************************************************************************** + * + * error.h is part of SimpleSkyCam. + * + *****************************************************************************************/ + + +#ifndef _ERROR_H_ +#define _ERROR_H_ + +#define ERRORMSG_LEN 2048 +struct ErrorMessage { + char window[ERRORMSG_LEN]; + char title[ERRORMSG_LEN]; + char message[ERRORMSG_LEN]; +}; + +void errormessage_display (char *windowname, char *title, char *fmt,...); + +#endif // _ERROR_H_ diff --git a/gui.cc b/gui.cc index 2f9b122..434e5cb 100644 --- a/gui.cc +++ b/gui.cc @@ -91,20 +91,6 @@ void cb_menu_set_rgbenc (GtkCheckMenuItem *checkmenuitem, gpointer user_data) { } -void displayerror (std::string error) { - GtkWidget *dialog; - GtkWidget *window = GTK_WIDGET (gtk_builder_get_object (_builder_, "main-window")); - dialog = gtk_message_dialog_new(GTK_WINDOW(window), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_OK, - "%s", error.c_str()); - gtk_window_set_title(GTK_WINDOW(dialog), "Error"); - gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); -}; - - //data // callback from filter thread. Data will point to the output VideoFrame. // Access to this data must be Locked before use. diff --git a/gui.h b/gui.h index 352c052..291e2c8 100644 --- a/gui.h +++ b/gui.h @@ -45,8 +45,6 @@ struct { float dy; } typedef detect_movement; -void displayerror (std::string error); - void draw_text (cairo_t *cr, int x, int y, float border, std::string text); #ifdef __cplusplus @@ -134,13 +132,18 @@ G_MODULE_EXPORT void cb_posctl_axis_draw(GtkWidget *area, cairo_t *cr, int w, in G_MODULE_EXPORT void cb_posctl_change_entry (GtkWidget *widget, gpointer data); G_MODULE_EXPORT void cb_posctl_btn_axismove (GtkWidget *widget, gpointer data); - - // // menu elements G_MODULE_EXPORT void cb_menu_set_rgbenc (GtkCheckMenuItem *checkmenuitem, gpointer user_data); G_MODULE_EXPORT void cb_menu_set_histlog (GtkCheckMenuItem *checkmenuitem, gpointer user_data); +// +// error handling +G_MODULE_EXPORT gboolean errormessage_thread (gpointer data); +G_MODULE_EXPORT void errormessage_cb_btnok (GtkWidget *widget, gpointer data); + + + #ifdef __cplusplus } #endif diff --git a/posctl.cc b/posctl.cc index 50e2f15..9911605 100644 --- a/posctl.cc +++ b/posctl.cc @@ -18,6 +18,7 @@ #include "video.h" #include "videodev.h" #include "histogram.h" +#include "error.h" extern PosCtl posctl; @@ -620,6 +621,8 @@ void PosCtl::OutputOpen() { if (device_fd < 0) { printf ("%s:%d could not open device:%s Error:%s\n", __FILE__, __LINE__, device.c_str(), strerror(errno)); + errormessage_display ((char *)"window-posctl", (char *)"OutputOpen", + (char*)"%s:%d could not open device:%s Error:%s\n", __FILE__, __LINE__, device.c_str(), strerror(errno)); } }; @@ -636,8 +639,9 @@ void PosCtl::OutputWriteValue (int axis, double value) { std::string s = setlocale(LC_ALL, NULL); setlocale (LC_ALL, "C"); - if (axis == 0) snprintf(outbuf, 254, "RA:%08.4f#\n", value); - else snprintf(outbuf, 254, "RR:%08.4f#\n", value); + snprintf(outbuf, 254, "R%c%c%08.4f#\n", (axis == 0 ? 'A' : 'R'), + (value < 0 ? '-' : '+'), + value); outbuf[254] = 0; // reset language setting to default