variable editing
This commit is contained in:
parent
5c4bf8d3b7
commit
f160148198
3
Makefile
3
Makefile
@ -21,4 +21,7 @@ $(TARGET): $(SRC:.c=.o)
|
||||
clean:
|
||||
rm -rf $(TARGET) *.o *.d
|
||||
|
||||
socat:
|
||||
socat tcp4-listen:5000,fork,reuseaddr /dev/ttyACM0,raw,echo=0,flock-ex-nb
|
||||
|
||||
-include $(shell find -name *.d 2> /dev/null)
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "tdc_store.h"
|
||||
#include "tdc_parser.h"
|
||||
#include "tdc_proto.h"
|
||||
|
||||
enum {
|
||||
@ -14,6 +15,10 @@ enum {
|
||||
|
||||
static GtkListStore *list_store;
|
||||
|
||||
static int viewmode = 0;
|
||||
static int sortmode = GTK_SORT_ASCENDING;
|
||||
static struct tdc_var *current_edited_var;
|
||||
|
||||
static void cell_graph_toggle(GtkCellRendererToggle *cell,
|
||||
gchar *path_string,
|
||||
gpointer user_data)
|
||||
@ -48,12 +53,38 @@ static gboolean header_toggle_update(GtkTreeModel *model,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void cell_value_edited(GtkCellRendererText *cell,
|
||||
gchar *path_string,
|
||||
gchar *new_text,
|
||||
static void value_edit_started(GtkCellRenderer *renderer,
|
||||
GtkCellEditable *editable,
|
||||
gchar *path,
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkTreeIter it;
|
||||
gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(list_store), &it, path);
|
||||
gtk_tree_model_get(GTK_TREE_MODEL(list_store), &it, COL_VALUE, ¤t_edited_var, -1);
|
||||
}
|
||||
|
||||
static void value_edit_canceled(GtkCellRenderer *renderer, gpointer user_data)
|
||||
{
|
||||
current_edited_var = NULL;
|
||||
}
|
||||
|
||||
static void value_edit_done(GtkCellRendererText *cell,
|
||||
gchar *path,
|
||||
gchar *text,
|
||||
gpointer user_data)
|
||||
{
|
||||
printf("cell_value_edited\n");
|
||||
GtkTreeIter it;
|
||||
gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(list_store), &it, path);
|
||||
|
||||
struct tdc_var *var;
|
||||
gtk_tree_model_get(GTK_TREE_MODEL(list_store), &it, COL_VALUE, &var, -1);
|
||||
|
||||
if (tdcvar_parse_value(var, text) >= 0) {
|
||||
// FIXME: assuming board 1
|
||||
tdcparser_send_setvalue(1, var->id);
|
||||
}
|
||||
|
||||
current_edited_var = NULL;
|
||||
}
|
||||
|
||||
static gint sort_by_name_func(GtkTreeModel *model,
|
||||
@ -80,9 +111,6 @@ static gint sort_by_name_func(GtkTreeModel *model,
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int viewmode = 0;
|
||||
static int sortmode = GTK_SORT_ASCENDING;
|
||||
|
||||
static void header_name_toggle(GtkTreeViewColumn *treeviewcolumn,
|
||||
gpointer user_data)
|
||||
{
|
||||
@ -147,7 +175,10 @@ gint gui_vartab_init(GtkNotebook *notebook)
|
||||
g_object_set(col, "clickable", TRUE, NULL);
|
||||
g_signal_connect(col, "clicked", (GCallback)header_value_toggle, NULL);
|
||||
renderer = gtk_cell_renderer_text_new();
|
||||
g_signal_connect(renderer, "edited", (GCallback)cell_value_edited, NULL);
|
||||
g_signal_connect(renderer, "edited", (GCallback)value_edit_done, NULL);
|
||||
g_signal_connect(renderer, "editing-started", (GCallback)value_edit_started, NULL);
|
||||
g_signal_connect(renderer, "editing-canceled", (GCallback)value_edit_canceled, NULL);
|
||||
|
||||
gtk_tree_view_column_pack_start(col, renderer, FALSE);
|
||||
gtk_tree_view_column_add_attribute(col, renderer, "editable", COL_VALUE_EDIT);
|
||||
gtk_tree_view_column_set_cell_data_func(col, renderer, cell_value_func, NULL, NULL);
|
||||
@ -198,6 +229,9 @@ void gui_vartab_add_var(struct tdc_var *var)
|
||||
|
||||
void gui_vartab_update_var(struct tdc_var *var)
|
||||
{
|
||||
if (var == current_edited_var)
|
||||
return;
|
||||
|
||||
/* do a dummy write to update cells */
|
||||
GtkTreeIter *it = (GtkTreeIter *)var->privdata;
|
||||
gtk_list_store_set(list_store, it, -1);
|
||||
|
@ -65,10 +65,10 @@ int tdcparser_send_setvalue(int address, int id)
|
||||
int datasize = (var->flags & TDC_SIZEMASK);
|
||||
|
||||
struct tdc_setvalue_request *pkt;
|
||||
pkt = g_malloc0(sizeof(struct tdc_setvalue_request) + datasize);
|
||||
pkt = g_malloc0(sizeof(*pkt) + datasize);
|
||||
|
||||
pkt->cmd = (address << 4) | TDC_SETVALUE;
|
||||
pkt->size = sizeof(pkt) + datasize;
|
||||
pkt->size = sizeof(*pkt) + datasize;
|
||||
pkt->id = (id & 0xFF);
|
||||
memcpy(pkt->data, &var->data, datasize);
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
@ -152,6 +154,66 @@ void tdcvar_get_type(struct tdc_var *var, char *buf, int size)
|
||||
pos = snprintf(buf + pos, size - pos, " (ro)");
|
||||
}
|
||||
|
||||
int tdcvar_parse_value(struct tdc_var *var, char *data)
|
||||
{
|
||||
struct tdc_var tmp;
|
||||
|
||||
int width = (var->flags & TDC_SIZEMASK);
|
||||
switch (var->flags & TDC_TYPEMASK) {
|
||||
case TDC_UNSIGNED:
|
||||
if (strchr(data, '-') != NULL)
|
||||
return -1;
|
||||
|
||||
errno = 0;
|
||||
if (width < 8)
|
||||
tmp.data_uint32 = strtoul(data, NULL, 0);
|
||||
else
|
||||
tmp.data_uint64 = strtoull(data, NULL, 0);
|
||||
|
||||
if (errno != 0) {
|
||||
errno = 0;
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
|
||||
case TDC_SIGNED:
|
||||
errno = 0;
|
||||
if (width < 8)
|
||||
tmp.data_uint32 = strtol(data, NULL, 0);
|
||||
else
|
||||
tmp.data_uint64 = strtoll(data, NULL, 0);
|
||||
|
||||
if (errno != 0) {
|
||||
errno = 0;
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
|
||||
case TDC_FP:
|
||||
errno = 0;
|
||||
if (width == sizeof(float))
|
||||
tmp.data_float = strtod(data, NULL);
|
||||
else
|
||||
tmp.data_double = strtod(data, NULL);
|
||||
|
||||
if (errno != 0) {
|
||||
errno = 0;
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
|
||||
case TDC_FIXED:
|
||||
return -1;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
memcpy(&var->data, &tmp.data, width);
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct tdc_var * tdcvar_create(int id, uint32_t flags, char *name, int len)
|
||||
{
|
||||
struct tdc_var *var = g_malloc0(sizeof(struct tdc_var) + len + 1);
|
||||
@ -161,7 +223,7 @@ struct tdc_var * tdcvar_create(int id, uint32_t flags, char *name, int len)
|
||||
strncpy(var->name, name, len);
|
||||
var->name[len] = '\0';
|
||||
|
||||
printf("create_var(%d, 0x%x, '%s', %d)\n", var->id, var->flags, var->name, len);
|
||||
// printf("create_var(%d, 0x%x, '%s', %d)\n", var->id, var->flags, var->name, len);
|
||||
return var;
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@ struct tdc_var {
|
||||
|
||||
void tdcvar_get_value(struct tdc_var *var, char *buf, int size, int viewmode);
|
||||
void tdcvar_get_type(struct tdc_var *var, char *buf, int size);
|
||||
int tdcvar_parse_value(struct tdc_var *var, char *data);
|
||||
|
||||
struct tdc_var * tdcvar_create(int id, uint32_t flags, char *name, int len);
|
||||
void tdcvar_update(struct tdc_var *var, uint8_t *data, int len);
|
||||
|
Loading…
Reference in New Issue
Block a user