-
Notifications
You must be signed in to change notification settings - Fork 0
/
rfidVisual.c
237 lines (177 loc) · 7.14 KB
/
rfidVisual.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: rfidVisual.c
* Author: Matthew Bennett <[email protected]>
*
* Created on 30 March 2019, 09:34
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gtk-3.0/gtk/gtk.h>
#include "rfidVisual.h"
#include "lib_rfid/inc/rfid.h"
//ToDo: Mode in the Mode Box needs to be centralised and smaller, allowing version to be wider.
//ToDo: Mode selection pictures needs to include words, and have only 1 selected, not all 3!
//ToDo: How do I all the user to set the value for polling delay?
/*
* function to open and configure the serial port
*/
void open_serial_port( struct app_widgets *widget) {
//ToDo: Actually open the serial port!
// Open the serial port
widget->conn = setupComms();
printf("Opened the serial port:%d\n", widget->conn);
return;
}
/*
* Functions called by GUI
*/
// called when window is closed
void on_main_application_window_destroy() {
printf("In on window main destroy\n");
gtk_main_quit();
exit(0);
}
void on_menu_file_connect(struct app_widgets *widget) {
printf("In On Menu File connect\n");
open_serial_port(widget);
get_version_info(widget);
get_mode_info(widget);
}
void on_btn_reset_clicked(GtkButton *button, struct app_widgets *widget) {
int status;
printf("Reset button has been clicked\n");
status = resetReader(widget->conn);
if (status ==0 ) {
printf("Factory Reset Complete\n");
}
else {
printf("Factory Reset failed\n");
}
return;
}
void on_radiobutton_toggled(GtkButton *button, struct app_widgets *widget) {
char mode;
mode = '\0';
printf("Radiobuttons for mode has changed\n");
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget->w_radbut_mode_a_pg2))) {
printf("Mode a selected\n");
mode = 'A';
}
else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget->w_radbut_mode_b_pg2))) {
printf("Mode b selected\n");
mode = 'B';
}
else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget->w_radbut_mode_c_pg2))) {
printf("Mode C selected\n");
mode = 'C';
}
setReaderMode(widget->conn, mode);
return;
}
void get_version_info(struct app_widgets *widget) {
//Maybe: change version from a char to a gchar
char version[100];
int count = 0;
int connection;
GtkTextBuffer *buffer;
version[0] = '\0';
//ToDo: Check this routine with different sizes of strings
connection = widget->conn;
do {
strcpy(version,readVersion(connection));
// check length of version
//
printf("size of Version: %d\n", sizeof(version)/sizeof(version[0])); // returns 100
printf("Version Information: >>%s<<\n", version);
count ++;
// ToDo: improve the checking for a valid response
} while ((count < 5) & (strlen(version) < 1));
if (strlen(version) > 0) {
printf("status is zero\n");
// Get and then set the buffer
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (widget->w_txt_version_info_box));
printf("Got the buffer\n");
gtk_text_buffer_set_text(buffer, version, -1);
printf("set the text\n");
}
return;
}
void get_mode_info(struct app_widgets *widget) {
char mode[1];
int count = 0;
int connection;
mode[0] = '\0';
//ToDo: Check this routine with different sizes of strings
connection = widget->conn;
do {
strcpy(mode,readMode(connection));
// check length of version
//
printf("Mode Information: >>%s<<\n", mode);
count ++;
// ToDo: improve the checking for a valid response
} while ((count < 5) & (strlen(mode) < 1));
if (strlen(mode) > 0) {
printf("status is zero\n");
gtk_entry_set_text(GTK_ENTRY(widget->w_txt_mode_box), mode);
printf("set the text\n");
}
return;
}
/*
*
*/
int main(int argc, char** argv) {
GtkBuilder *builder;
GtkWidget *window;
GError *err = NULL; // holds any error that occurs within GTK
// instantiate structure, allocating memory for it
struct app_widgets *widgets = g_slice_new(struct app_widgets);
// initialise GTK library and pass it in command line parameters
gtk_init(&argc, &argv);
// build the gui
builder = gtk_builder_new();
gtk_builder_add_from_file (builder, "gui/main_window.glade", &err);
//Bug: If the application is run from the build directory, it doesn't find the glade file.
// Does this mean that the XML file is not incorporated into the executable??
// check if the GUI has opened.
if (err != NULL) {
fprintf (stderr, "Unable to read file: %s\n", err->message);
g_error_free(err);
return 1;
}
window = GTK_WIDGET(gtk_builder_get_object(builder, "main_application_window"));
// build the structure of widget pointers
widgets->w_txt_tag_id_pg0 = GTK_WIDGET(gtk_builder_get_object(builder, "txt_tag_id_pg0"));
widgets->w_txt_view_page_block_info_pg0 = GTK_WIDGET(gtk_builder_get_object(builder, "txt_view_page_block_info_pg01"));
widgets->w_radbut_tag_present_pg0 = GTK_WIDGET(gtk_builder_get_object(builder, "radbut_tag_present_pg0"));
widgets->w_txt_tag_id_pg1 = GTK_WIDGET(gtk_builder_get_object(builder, "txt_tag_id_pg1"));
widgets->w_txt_view_page_block_info_pg1 = GTK_WIDGET(gtk_builder_get_object(builder, "txt_view_page_block_info_pg1"));
widgets->w_radbut_tag_present_pg1 = GTK_WIDGET(gtk_builder_get_object(builder, "radbut_tag_present_pg1"));
widgets->w_radbut_mode_a_pg2 = GTK_WIDGET(gtk_builder_get_object(builder, "radbut_mode_a_pg2"));
widgets->w_radbut_mode_b_pg2 = GTK_WIDGET(gtk_builder_get_object(builder, "radbut_mode_b_pg2"));
widgets->w_radbut_mode_c_pg2 = GTK_WIDGET(gtk_builder_get_object(builder, "radbut_mode_c_pg2"));
widgets->w_but_factory_reset = GTK_WIDGET(gtk_builder_get_object(builder, "but_factory_reset"));
widgets->w_txt_version_info_box = GTK_WIDGET(gtk_builder_get_object(builder, "txt_version_info_box"));
widgets->w_txt_mode_box = GTK_WIDGET(gtk_builder_get_object(builder, "txt_mode_box"));
// connect the widgets to the signal handler
gtk_builder_connect_signals(builder, widgets); // note: second parameter points to widgets
g_object_unref(builder);
// Set the status of the various boxes etc.
//ToDo: need to set the txt_version_info box to not editable.
//gtk_text_view_set_editable(GtkTextView (widgets->w_txt_version_info_box), FALSE);
// ToDo: need to get this to try and if fail, report to the user. Maybe have it only run by the menu item rather than automatic.
on_menu_file_connect(widgets);
gtk_widget_show(window);
gtk_main();
// free up memory used by widget structure, probably not necessary as OS will
// reclaim memory from application after it exits
g_slice_free(struct app_widgets, widgets);
return (EXIT_SUCCESS);
}