Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add wireless (wireless over OpenWrt router) configure code

  • Loading branch information...
commit 260e2d0e6765e3335f55d28c240446c64f3ee4dc 1 parent 6f21cf4
Xiangfu Liu authored May 14, 2012
5  src/Makefile
@@ -42,7 +42,7 @@ LDFLAGS = -mbarrel-shift-enabled -mmultiply-enabled -mdivide-enabled \
42 42
 	  -msign-extend-enabled -B$(RTEMS_MAKEFILE_PATH)/lib \
43 43
 	  -specs bsp_specs -qrtems
44 44
 LIBS = -lnfs -lftpd -ltelnetd -lyaffs2 -lmtk -llop -lfpvm -lpng -ljpeg \
45  
-      -lcurl -lexpat -lz -lm
  45
+      -lcurl -lexpat -ljansson -lz -lm
46 46
 OBJDIR = obj
47 47
 BINDIR = bin
48 48
 
@@ -53,7 +53,8 @@ OBJS += $(addprefix pixbuf/,dither.o loaderjpeg.o loaderpng.o manager.o)
53 53
 OBJS += $(addprefix gui/,messagebox.o filedialog.o resmgr.o guirender.o \
54 54
 	performance.o cp.o keyboard.o ir.o audio.o midi.o oscsettings.o \
55 55
 	dmxspy.o dmxdesk.o dmx.o videoin.o rsswall.o patcheditor.o monitor.o \
56  
-	firstpatch.o filemanager.o sysettings.o about.o flash.o shutdown.o)
  56
+	firstpatch.o filemanager.o sysettings.o about.o flash.o shutdown.o \
  57
+	wireless.o )
57 58
 ifeq ($(WITH_PDF),1)
58 59
 	OBJS += $(addprefix gui/,pdfreader.o)
59 60
 	CFLAGS += -DWITH_PDF
9  src/gui/sysettings.c
@@ -24,6 +24,7 @@
24 24
 #include "../sysconfig.h"
25 25
 #include "filedialog.h"
26 26
 #include "sysettings.h"
  27
+#include "wireless.h"
27 28
 
28 29
 static int appid;
29 30
 static struct filedialog *browse_wallpaper_dlg;
@@ -68,6 +69,11 @@ static void dhcp_callback(mtk_event *e, void *arg)
68 69
 	update_network();
69 70
 }
70 71
 
  72
+static void wireless_callback(mtk_event *e, void *arg)
  73
+{
  74
+	open_wireless_window();
  75
+}
  76
+
71 77
 static int current_asmode;
72 78
 
73 79
 static void asmode_callback(mtk_event *e, void *arg)
@@ -206,8 +212,10 @@ void init_sysettings(void)
206 212
 		"g_network1 = new Grid()",
207 213
 		"l_dhcp = new Label(-text \"DHCP client:\")",
208 214
 		"b_dhcp = new Button(-text \"Enable\")",
  215
+		"b_wireless = new Button(-text \"Wireless over Ethernet\")",
209 216
 		"g_network1.place(l_dhcp, -column 1 -row 1)",
210 217
 		"g_network1.place(b_dhcp, -column 2 -row 1)",
  218
+		"g_network1.place(b_wireless, -column 3 -row 1)",
211 219
 		"g_network2 = new Grid()",
212 220
 		"l_ip = new Label(-text \"IP address:\")",
213 221
 		"e_ip = new Entry()",
@@ -314,6 +322,7 @@ void init_sysettings(void)
314 322
 	mtk_bind(appid, "b_kbd_german", "press", layout_callback, (void *)SC_KEYBOARD_LAYOUT_GERMAN);
315 323
 
316 324
 	mtk_bind(appid, "b_dhcp", "press", dhcp_callback, NULL);
  325
+	mtk_bind(appid, "b_wireless", "press", wireless_callback, NULL);
317 326
 
318 327
 	mtk_bind(appid, "b_asmode_none", "press", asmode_callback, (void *)SC_AUTOSTART_NONE);
319 328
 	mtk_bind(appid, "b_asmode_simple", "press", asmode_callback, (void *)SC_AUTOSTART_SIMPLE);
612  src/gui/wireless.c
... ...
@@ -0,0 +1,612 @@
  1
+/*
  2
+ * Flickernoise
  3
+ * Copyright (C) 2012 Xiangfu Liu
  4
+ *
  5
+ * This program is free software: you can redistribute it and/or modify
  6
+ * it under the terms of the GNU General Public License as published by
  7
+ * the Free Software Foundation, version 3 of the License.
  8
+ *
  9
+ * This program is distributed in the hope that it will be useful,
  10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12
+ * GNU General Public License for more details.
  13
+ *
  14
+ * You should have received a copy of the GNU General Public License
  15
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16
+ */
  17
+
  18
+#include <bsp.h>
  19
+#include <sys/types.h>
  20
+#include <sys/stat.h>
  21
+#include <stdio.h>
  22
+#include <stdlib.h>
  23
+#include <string.h>
  24
+#include <dirent.h>
  25
+#include <unistd.h>
  26
+#include <assert.h>
  27
+#include <mtklib.h>
  28
+#include <curl/curl.h>
  29
+#include <jansson.h>
  30
+
  31
+#include "../util.h"
  32
+#include "../input.h"
  33
+#include "../config.h"
  34
+#include "cp.h"
  35
+#include "messagebox.h"
  36
+
  37
+#include "wireless.h"
  38
+
  39
+static int appid;
  40
+static int w_open;
  41
+
  42
+static char *wireless[20][3];
  43
+static char wireless_buf[32768];
  44
+static int wireless_index;
  45
+
  46
+struct data_buffer {
  47
+	void		*buf;
  48
+	size_t		len;
  49
+};
  50
+
  51
+struct upload_buffer {
  52
+	const void	*buf;
  53
+	size_t		len;
  54
+};
  55
+
  56
+static void databuf_free(struct data_buffer *db)
  57
+{
  58
+	if(!db)
  59
+		return;
  60
+
  61
+	free(db->buf);
  62
+
  63
+	memset(db, 0, sizeof(*db));
  64
+}
  65
+
  66
+static size_t all_data_cb(const void *ptr, size_t size, size_t nmemb,
  67
+			  void *user_data)
  68
+{
  69
+	struct data_buffer *db = user_data;
  70
+	size_t len = size * nmemb;
  71
+	size_t oldlen, newlen;
  72
+	void *newmem;
  73
+	static const unsigned char zero = 0;
  74
+
  75
+	oldlen = db->len;
  76
+	newlen = oldlen + len;
  77
+
  78
+	newmem = realloc(db->buf, newlen + 1);
  79
+	if(!newmem)
  80
+		return 0;
  81
+
  82
+	db->buf = newmem;
  83
+	db->len = newlen;
  84
+	memcpy(db->buf + oldlen, ptr, len);
  85
+	memcpy(db->buf + newlen, &zero, 1);	/* null terminate */
  86
+
  87
+	return len;
  88
+}
  89
+
  90
+static size_t upload_data_cb(void *ptr, size_t size, size_t nmemb,
  91
+			     void *user_data)
  92
+{
  93
+	struct upload_buffer *ub = user_data;
  94
+	unsigned int len = size * nmemb;
  95
+
  96
+	if(len > ub->len)
  97
+		len = ub->len;
  98
+
  99
+	if(len) {
  100
+		memcpy(ptr, ub->buf, len);
  101
+		ub->buf += len;
  102
+		ub->len -= len;
  103
+	}
  104
+
  105
+	return len;
  106
+}
  107
+
  108
+static json_t *json_rpc_call(CURL *curl, const char *url,
  109
+		     const char *userpass, const char *rpc_req, int timeout)
  110
+{
  111
+	json_t *val, *err_val, *res_val;
  112
+	int rc;
  113
+	struct data_buffer all_data = {NULL, 0};
  114
+	struct upload_buffer upload_data;
  115
+	json_error_t err;
  116
+	struct curl_slist *headers = NULL;
  117
+	char len_hdr[64];
  118
+	char curl_err_str[CURL_ERROR_SIZE];
  119
+	char *s;
  120
+
  121
+	memset(&err, 0, sizeof(err));
  122
+
  123
+	/* it is assumed that 'curl' is freshly [re]initialized at this pt */
  124
+	curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
  125
+
  126
+#if 0 /* Disable curl debugging since it spews to stderr */
  127
+	curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
  128
+#endif
  129
+	curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
  130
+	curl_easy_setopt(curl, CURLOPT_URL, url);
  131
+	curl_easy_setopt(curl, CURLOPT_ENCODING, "");
  132
+	curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
  133
+	curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "");
  134
+
  135
+	/* Shares are staggered already and delays in submission can be costly
  136
+	 * so do not delay them */
  137
+	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, all_data_cb);
  138
+	curl_easy_setopt(curl, CURLOPT_WRITEDATA, &all_data);
  139
+	curl_easy_setopt(curl, CURLOPT_READFUNCTION, upload_data_cb);
  140
+	curl_easy_setopt(curl, CURLOPT_READDATA, &upload_data);
  141
+	curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_err_str);
  142
+	curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
  143
+	curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_TRY);
  144
+	if(userpass) {
  145
+		curl_easy_setopt(curl, CURLOPT_USERPWD, userpass);
  146
+		curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  147
+	}
  148
+	curl_easy_setopt(curl, CURLOPT_POST, 1);
  149
+
  150
+	upload_data.buf = rpc_req;
  151
+	upload_data.len = strlen(rpc_req);
  152
+
  153
+	sprintf(len_hdr, "Content-Length: %lu",
  154
+		(unsigned long) upload_data.len);
  155
+
  156
+	headers = curl_slist_append(headers,
  157
+		"Content-type: application/json");
  158
+	headers = curl_slist_append(headers, len_hdr);
  159
+	headers = curl_slist_append(headers, "Expect:");/* disable Expect hdr*/
  160
+
  161
+	curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
  162
+
  163
+	rc = curl_easy_perform(curl);
  164
+	if(rc) {
  165
+		printf("HTTP request failed: %s\n", curl_err_str);
  166
+		messagebox("Wireless settings", "Cannot reach wireless gadget");
  167
+		goto err_out;
  168
+	}
  169
+
  170
+	if(!all_data.buf) {
  171
+		printf("Empty data received in json_rpc_call.");
  172
+		goto err_out;
  173
+	}
  174
+
  175
+	val = json_loads(all_data.buf, 0, &err);
  176
+	if(!val) {
  177
+		printf("JSON decode failed(%d): %s", err.line, err.text);
  178
+		printf("JSON protocol response:\n%s", (char *)all_data.buf);
  179
+		goto err_out;
  180
+	}
  181
+
  182
+	/* JSON-RPC valid response returns a non-null 'result',
  183
+	 * and a null 'error'.
  184
+	 */
  185
+	res_val = json_object_get(val, "result");
  186
+	err_val = json_object_get(val, "error");
  187
+
  188
+	if(!res_val || json_is_null(res_val) ||
  189
+	    (err_val && !json_is_null(err_val))) {
  190
+		if(err_val)
  191
+			s = json_dumps(err_val, JSON_INDENT(3));
  192
+		else
  193
+			s = strdup("(unknown reason)");
  194
+
  195
+		printf("JSON-RPC call failed: %s\n", s);
  196
+		free(s);
  197
+
  198
+		goto err_out;
  199
+	}
  200
+
  201
+	databuf_free(&all_data);
  202
+	curl_slist_free_all(headers);
  203
+	curl_easy_reset(curl);
  204
+
  205
+	return val;
  206
+
  207
+err_out:
  208
+	databuf_free(&all_data);
  209
+	curl_slist_free_all(headers);
  210
+	curl_easy_reset(curl);
  211
+	curl_easy_setopt(curl, CURLOPT_FRESH_CONNECT, 1);
  212
+
  213
+	return NULL;
  214
+}
  215
+
  216
+static char *jget_key(const json_t *obj, const char *key, int required)
  217
+{
  218
+	char *str;
  219
+	json_t *tmp;
  220
+
  221
+	tmp = json_object_get(obj, key);
  222
+	if(!tmp) {
  223
+		if(required)
  224
+			printf("JSON key '%s' not found", key);
  225
+		return NULL;
  226
+	}
  227
+
  228
+	str = json_string_value(tmp);
  229
+	if(!str) {
  230
+		printf("JSON key '%s' is not a string", key);
  231
+		return NULL;
  232
+	}
  233
+
  234
+	return str;
  235
+}
  236
+
  237
+static int update_list(const char *str)
  238
+{
  239
+	char lst[32768];
  240
+	char *p, *pch;
  241
+	char *wireless_l[20];
  242
+	int i, j, l;
  243
+
  244
+	memset(wireless_buf, 0, sizeof(wireless_buf));
  245
+	strcpy(wireless_buf, str);
  246
+	l = strlen(wireless_buf) - 1;
  247
+	if(l < 2) {
  248
+		mtk_cmdf(appid, "lst_wireless.set(-text \"%s\" -selection 0)", "No wireless found");
  249
+		return 0;
  250
+	}
  251
+	while(wireless_buf[l] == '\n' || wireless_buf[l] == ' ')
  252
+		wireless_buf[l--] = 0;
  253
+
  254
+	i = 0;
  255
+	pch = strtok(wireless_buf, "\n");
  256
+	while(pch) {
  257
+		wireless_l[i] = pch;
  258
+		pch = strtok(NULL, "\n");
  259
+		i++;
  260
+	}
  261
+	wireless_l[i] = NULL;
  262
+
  263
+	i = 0;
  264
+	while(wireless_l[i]) {
  265
+		j = 0;
  266
+		pch = strtok(wireless_l[i], ",");
  267
+		while(pch) {
  268
+			wireless[i][j] = pch;
  269
+			pch = strtok(NULL, ",");
  270
+			j++;
  271
+		}
  272
+		i++;
  273
+	}
  274
+
  275
+	i = 0;
  276
+	p = lst;
  277
+	while(wireless_l[i]) {
  278
+		p += sprintf(p, "%s    %s\n", wireless[i][0], wireless[i][1]);
  279
+		i++;
  280
+	}
  281
+
  282
+	if(p != lst) {
  283
+		p--;
  284
+		*p = 0;
  285
+	}
  286
+
  287
+	mtk_cmdf(appid, "lst_wireless.set(-text \"%s\" -selection 0)", lst);
  288
+	wireless_index = 0;
  289
+
  290
+	return 0;
  291
+}
  292
+
  293
+static void selchange_callback(mtk_event *e, void *arg)
  294
+{
  295
+	wireless_index = mtk_req_i(appid, "lst_wireless.selection");
  296
+}
  297
+
  298
+static char *rpc_req_login = "{"
  299
+	"\"jsonrpc\":\"1.0\","
  300
+	"\"method\" :\"login\","
  301
+	"\"params\" :[\"root\", \"\"],"
  302
+	"\"id\":0"
  303
+	"}";
  304
+static char *rpc_req_scan =
  305
+	"{"
  306
+	"\"jsonrpc\":\"1.0\","
  307
+	"\"method\" :\"exec\","
  308
+	"\"params\" :[\"/opt/m1-wireless.sh get\"],"
  309
+	"\"id\"     :0"
  310
+	"}";
  311
+static char *rpc_req_status =
  312
+	"{"
  313
+	"\"jsonrpc\":\"1.0\","
  314
+	"\"method\" :\"exec\","
  315
+	"\"params\" :[\"/opt/m1-wireless.sh status\"],"
  316
+	"\"id\"     :0"
  317
+	"}";
  318
+
  319
+#define URL_703N "http://192.168.42.1/cgi-bin/luci/rpc"
  320
+
  321
+static void scan_callback(mtk_event *e, void *arg)
  322
+{
  323
+	const char *url = URL_703N"/auth";
  324
+	const char *userpass = NULL;
  325
+
  326
+	CURL *curl;
  327
+	json_t *val;
  328
+	char *key, *url_token;
  329
+
  330
+	curl = curl_easy_init();
  331
+
  332
+	val = json_rpc_call(curl, url, userpass, rpc_req_login, 5);
  333
+	if(!val)
  334
+		return;
  335
+
  336
+
  337
+	key = jget_key(val, "result", 0);
  338
+	if(!key)
  339
+		return;
  340
+		
  341
+	url_token = malloc(100);
  342
+	strcpy(url_token, URL_703N"/sys?auth=\0");
  343
+	url_token = strcat(url_token, key);
  344
+
  345
+	json_decref(val);
  346
+
  347
+	val = json_rpc_call(curl, (char *)url_token, userpass, rpc_req_scan, 10);
  348
+	if(!val)
  349
+		goto free_url;
  350
+	key = jget_key(val, "result", 0);
  351
+	if(!key)
  352
+		goto free_url;
  353
+	update_list(key);
  354
+	json_decref(val);
  355
+
  356
+free_url:
  357
+	free(url_token);
  358
+
  359
+	curl_easy_cleanup(curl);
  360
+}
  361
+
  362
+static int status(void)
  363
+{
  364
+	const char *url = URL_703N"/auth";
  365
+	const char *userpass = NULL;
  366
+
  367
+	CURL *curl;
  368
+	json_t *val;
  369
+	char *key, *url_token;
  370
+	char *essid, *ip, *tmp;
  371
+	int ret = 1;
  372
+
  373
+	curl = curl_easy_init();
  374
+
  375
+	val = json_rpc_call(curl, (char *)url, userpass, rpc_req_login, 5);
  376
+	if(!val)
  377
+		return ret;
  378
+
  379
+	url_token = malloc(100);
  380
+
  381
+	key = jget_key(val, "result", 0);
  382
+	strcpy(url_token, URL_703N"/sys?auth=");
  383
+	url_token = strcat(url_token, key);
  384
+
  385
+	json_decref(val);
  386
+
  387
+	val = json_rpc_call(curl, (char *)url_token, userpass, rpc_req_status, 30);
  388
+	if(!val)
  389
+		goto free_url;
  390
+
  391
+	key = jget_key(val, "result", 0);
  392
+
  393
+	essid = strdup(key);
  394
+	if(!essid) {
  395
+		mtk_cmd(appid, "l_essid.set(-text \"Disconnect\")");
  396
+		mtk_cmd(appid, "l_ip.set(-text \"0.0.0.0\")");
  397
+		goto free_url;
  398
+	}
  399
+
  400
+	ip = strchr(essid, '\n');
  401
+	if(ip) *ip = 0;
  402
+	ip++;
  403
+
  404
+	tmp = strchr(ip, '\n');
  405
+	if(tmp) *tmp = 0;
  406
+
  407
+	mtk_cmdf(appid, "l_essid.set(-text \"%s\")", essid);
  408
+	mtk_cmdf(appid, "l_ip.set(-text \"%s\")", ip);
  409
+	free(essid);
  410
+
  411
+	json_decref(val);
  412
+
  413
+	ret = 0;
  414
+free_url:
  415
+	free(url_token);
  416
+	curl_easy_cleanup(curl);
  417
+
  418
+	return ret;
  419
+}
  420
+
  421
+static void status_callback(mtk_event *e, void *arg)
  422
+{
  423
+	status();
  424
+}
  425
+
  426
+static void connect_callback(mtk_event *e, void *arg)
  427
+{
  428
+	const char *url = URL_703N"/auth";
  429
+	const char *userpass = NULL;
  430
+	char rpc_req_set[256];
  431
+
  432
+	CURL *curl;
  433
+	json_t *val;
  434
+	char *key, *url_token;
  435
+
  436
+	char passwd[384];
  437
+
  438
+	if(!wireless[wireless_index][1] || !wireless[wireless_index][2]) {
  439
+		messagebox("Error", "No network select");
  440
+		return;
  441
+	}
  442
+
  443
+	if(!strcmp(wireless[wireless_index][2], "none")) {
  444
+		strcpy(passwd, "none");
  445
+	} else {
  446
+		mtk_req(appid, passwd, sizeof(passwd), "e_password.text");
  447
+		if(passwd[0] == 0) {
  448
+			messagebox("Error", "Not OPEN wireless, input password");
  449
+			return;
  450
+		}
  451
+	}
  452
+
  453
+	curl = curl_easy_init();
  454
+
  455
+	val = json_rpc_call(curl, (char *)url, userpass, rpc_req_login, 5);
  456
+	if(!val) {
  457
+		messagebox("Error", "Cannot reach wireless gadget");
  458
+		return;
  459
+	}
  460
+
  461
+	url_token = malloc(100);
  462
+	if(!url_token) {
  463
+		messagebox("Error", "Out of memory");
  464
+		return;
  465
+	}
  466
+
  467
+	key = jget_key(val, "result", 0);
  468
+	strcpy(url_token, URL_703N"/sys?auth=\0");
  469
+	url_token = strcat(url_token, key);
  470
+
  471
+	json_decref(val);
  472
+
  473
+	sprintf(rpc_req_set, "{"
  474
+		"\"jsonrpc\":\"1.0\","
  475
+		"\"method\" :\"exec\","
  476
+		"\"params\" :[\"/opt/m1-wireless.sh set %s %s %s\"],"
  477
+		"\"id\"     :0"
  478
+		"}",
  479
+		wireless[wireless_index][1], passwd,
  480
+		wireless[wireless_index][2]);
  481
+
  482
+	val = json_rpc_call(curl, (char *)url_token, userpass, rpc_req_set, 30);
  483
+	if(!val) {
  484
+		messagebox("Error", "Cannot reach wireless gadget");
  485
+		goto free_url;
  486
+	}
  487
+	json_decref(val);
  488
+
  489
+	status();
  490
+
  491
+free_url:
  492
+	free(url_token);
  493
+
  494
+	curl_easy_cleanup(curl);
  495
+}
  496
+
  497
+static void close_window(void)
  498
+{
  499
+	mtk_cmd(appid, "w.close()");
  500
+	w_open = 0;
  501
+}
  502
+
  503
+static void ok_callback(mtk_event *e, void *arg)
  504
+{
  505
+	close_window();
  506
+}
  507
+
  508
+static void cancel_callback(mtk_event *e, void *arg)
  509
+{
  510
+	close_window();
  511
+}
  512
+
  513
+void init_wireless(void)
  514
+{
  515
+	appid = mtk_init_app("WIRELESS");
  516
+
  517
+	mtk_cmd_seq(appid,
  518
+		"g = new Grid()",
  519
+
  520
+		"g_status = new Grid()",
  521
+		"l_status = new Label(-text \"Status\" -font \"title\")",
  522
+		"s_status1 = new Separator(-vertical no)",
  523
+		"s_status2 = new Separator(-vertical no)",
  524
+		"g_status.place(s_status1, -column 1 -row 1)",
  525
+		"g_status.place(l_status, -column 2 -row 1)",
  526
+		"g_status.place(s_status2, -column 3 -row 1)",
  527
+
  528
+		"g_status1 = new Grid()",
  529
+		"l_ESSID = new Label(-text \"ESSID:\")",
  530
+		"l_IP    = new Label(-text \"IP:\")",
  531
+		"l_essid = new Label(-text \"\")",
  532
+		"l_ip    = new Label(-text \"\")",
  533
+		"g_status1.place(l_ESSID, -column 1 -row 1)",
  534
+		"g_status1.place(l_essid, -column 2 -row 1)",
  535
+		"g_status1.place(l_IP, -column 1 -row 2)",
  536
+		"g_status1.place(l_ip, -column 2 -row 2)",
  537
+		"g_status1.columnconfig(1, -size 100)",
  538
+
  539
+		"g_wirelesslist = new Grid()",
  540
+		"l_wireless = new Label(-text \"Wireless networks\" -font \"title\")",
  541
+		"s_wireless1 = new Separator(-vertical no)",
  542
+		"s_wireless2 = new Separator(-vertical no)",
  543
+		"g_wirelesslist.place(s_wireless1, -column 1 -row 1)",
  544
+		"g_wirelesslist.place(l_wireless, -column 2 -row 1)",
  545
+		"g_wirelesslist.place(s_wireless2, -column 3 -row 1)",
  546
+		"lst_wireless = new List()",
  547
+		"lst_wirelessf = new Frame(-content lst_wireless -scrollx no -scrolly yes)",
  548
+
  549
+		"g_connect = new Grid()",
  550
+		"s_connects = new Separator(-vertical no)",
  551
+		"g_connect.place(s_connects, -column 1 -row 1)",
  552
+
  553
+		"g_connect1 = new Grid()",
  554
+		"l_password = new Label(-text \"Password:\")",
  555
+		"e_password = new Entry()",
  556
+		"b_connect  = new Button(-text \"Connect\")",
  557
+		"g_connect1.place(l_password, -column 1 -row 2)",
  558
+		"g_connect1.place(e_password, -column 2 -row 2)",
  559
+		"g_connect1.place(b_connect,  -column 3 -row 2)",
  560
+		"g_connect1.columnconfig(2, -size 150)",
  561
+
  562
+		"b_scan = new Button(-text \"Scan\")",
  563
+		"b_status = new Button(-text \"Status\")",
  564
+
  565
+		"g.place(g_status, -column 1 -row 1)",
  566
+		"g.place(g_status1, -column 1 -row 2)",
  567
+		"g.place(b_status, -column 1 -row 3)",
  568
+
  569
+		"g.place(g_wirelesslist, -column 1 -row 4)",
  570
+		"g.place(lst_wirelessf, -column 1 -row 5)",
  571
+		"g.rowconfig(5, -size 130)",
  572
+		"g.place(g_connect, -column 1 -row 6)",
  573
+		"g.place(b_scan, -column 1 -row 7)",
  574
+		"g.place(g_connect1, -column 1 -row 8)",
  575
+
  576
+		"g_btn = new Grid()",
  577
+		"b_ok = new Button(-text \"OK\")",
  578
+		"b_cancel = new Button(-text \"Cancel\")",
  579
+		"g_btn.columnconfig(1, -size 200)",
  580
+		"g_btn.place(b_ok, -column 2 -row 1)",
  581
+		"g_btn.place(b_cancel, -column 3 -row 1)",
  582
+
  583
+		"g.rowconfig(9, -size 10)",
  584
+		"g.place(g_btn, -column 1 -row 10)",
  585
+
  586
+		"w = new Window(-content g -title \"Wireless settings\" -workx 10)",
  587
+		0);
  588
+
  589
+	mtk_bind(appid, "lst_wireless", "selchange", selchange_callback, NULL);
  590
+	mtk_bind(appid, "lst_wireless", "selcommit", selchange_callback, NULL);
  591
+
  592
+	mtk_bind(appid, "b_scan", "commit", scan_callback, NULL);
  593
+	mtk_bind(appid, "b_connect", "commit", connect_callback, NULL);
  594
+	mtk_bind(appid, "b_status", "commit", status_callback, NULL);
  595
+	mtk_bind(appid, "b_ok", "commit", ok_callback, NULL);
  596
+	mtk_bind(appid, "b_cancel", "commit", cancel_callback, NULL);
  597
+
  598
+	mtk_bind(appid, "w", "close", cancel_callback, NULL);
  599
+}
  600
+
  601
+void open_wireless_window(void)
  602
+{
  603
+	if(w_open) return;
  604
+	if(status()) return;
  605
+
  606
+	mtk_cmd(appid, "lst_wireless.set(-text \"\" -selection 0)");
  607
+	wireless[0][0] = wireless[0][1] = wireless[0][2] = 0;
  608
+	wireless_index = 0;
  609
+
  610
+	w_open = 1;
  611
+	mtk_cmd(appid, "w.open()");
  612
+}
24  src/gui/wireless.h
... ...
@@ -0,0 +1,24 @@
  1
+/*
  2
+ * Flickernoise
  3
+ * Copyright (C) 2012 Xiangfu Liu
  4
+ *
  5
+ * This program is free software: you can redistribute it and/or modify
  6
+ * it under the terms of the GNU General Public License as published by
  7
+ * the Free Software Foundation, version 3 of the License.
  8
+ *
  9
+ * This program is distributed in the hope that it will be useful,
  10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12
+ * GNU General Public License for more details.
  13
+ *
  14
+ * You should have received a copy of the GNU General Public License
  15
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16
+ */
  17
+
  18
+#ifndef __WIRELESS_H
  19
+#define __WIRELESS_H
  20
+
  21
+void init_wireless(void);
  22
+void open_wireless_window(void);
  23
+
  24
+#endif /* __MIDI_H */
2  src/main.c
@@ -85,6 +85,7 @@
85 85
 #include "gui/about.h"
86 86
 #include "gui/flash.h"
87 87
 #include "gui/filedialog.h"
  88
+#include "gui/wireless.h"
88 89
 
89 90
 static rtems_task gui_task(rtems_task_argument argument)
90 91
 {
@@ -120,6 +121,7 @@ static rtems_task gui_task(rtems_task_argument argument)
120 121
 	init_about();
121 122
 	init_flash();
122 123
 	init_shutdown();
  124
+	init_wireless();
123 125
 
124 126
 	cp_autostart();
125 127
 	

0 notes on commit 260e2d0

Please sign in to comment.
Something went wrong with that request. Please try again.