Subversion Repositories group.electronics

Rev

Rev 137 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 137 Rev 139
Line 4... Line 4...
4
#include <stdio.h>
4
#include <stdio.h>
5
#include <stdlib.h>
5
#include <stdlib.h>
6
#include <string.h>
6
#include <string.h>
7
#include <usb.h>
7
#include <usb.h>
8
 
8
 
-
 
9
#define DISPLAYS_ATTACHED 1
9
 
10
 
10
static int usbGetDescriptorString(usb_dev_handle *dev, int index, int langid, char *buf, int buflen);
11
static int usbGetDescriptorString(usb_dev_handle *dev, int index, int langid, char *buf, int buflen);
11
static usb_dev_handle * usbOpenDevice(int vendor, char *vendorName, int product, char *productName);
12
static usb_dev_handle * usbOpenDevice(int vendor, char *vendorName, int product, char *productName);
-
 
13
char sendDigit(char dis, char dig, char val, char dp);
12
char sendDigit(char dis, char dig, char val);
14
char sendShort(char dis, char dig, short val);
-
 
15
char sendLatch(char dis);
-
 
16
char getInput(char dis);
13
 
17
 
14
char* getBCD(char maxLen);
18
char* getBCD(char maxLen);
15
short getHex();
19
short getHex();
16
void printBCD(char* data);
20
void printBCD(char* data);
17
void printB(char *data);
21
void printB(char *data);
18
 
22
 
-
 
23
void drawScreen();
-
 
24
 
19
usb_dev_handle *handle = NULL;
25
usb_dev_handle *handle = NULL;
-
 
26
char usbReplyBuf[64];
-
 
27
 
-
 
28
typedef struct display {
-
 
29
	char digits[10];
-
 
30
	char rotary;
-
 
31
	char buttons;
-
 
32
} display_t;
-
 
33
 
-
 
34
typedef struct controller_t {
-
 
35
	display_t* dis[2];
-
 
36
} controller_t;
-
 
37
 
-
 
38
typedef struct cursor_t {
-
 
39
	char dis;
-
 
40
	char dig;
-
 
41
	char val;
-
 
42
	char dp;
-
 
43
} cursor_t;
-
 
44
 
-
 
45
controller_t controller;
-
 
46
cursor_t cursor;
20
 
47
 
21
main() {
48
main() {
22
 
49
 
23
 
50
 
24
	handle = usbOpenDevice(0x20a0, "newioit.com.au", 0x4236, "NIT Comm/Nav");
51
	handle = usbOpenDevice(0x20a0, "newioit.com.au", 0x4236, "NIT Comm/Nav");
Line 30... Line 57...
30
 
57
 
31
	initscr();
58
	initscr();
32
	raw();
59
	raw();
33
	keypad(stdscr, TRUE);
60
	keypad(stdscr, TRUE);
34
	noecho();
61
	noecho();
-
 
62
	nodelay(stdscr, TRUE);
35
 
63
 
-
 
64
	controller.dis[0]->buttons = 0;
-
 
65
	controller.dis[0]->rotary = 0;
36
 
66
 
37
 
-
 
38
	char dis = 0x00;
67
	cursor.dis = 0x00;
39
	char dig = 0x03;
68
	cursor.dig = 0x00;
40
	short val = 0x02;
69
	cursor.val = 0x0a;
-
 
70
	cursor.dp = 0x00;
41
 
71
 
42
	char cont = 1;
72
	char cont = 1;
43
 
73
 
44
	//char display[] = {
74
	//char display[] = {
45
 
75
 
46
	while (cont) {
76
	while (cont) {
47
		clear();
77
		clear();
48
 
78
 
-
 
79
 
49
		printw("\nCursor: ");
80
		printw("\nCursor: ");
50
		printw("Dis: %x ", dis);
81
		printw("Dis: %x ", cursor.dis);
51
		printw("Dig %x ", dig);
82
		printw("Dig %x ", cursor.dig);
52
		printw("Val %x \n", val);
83
		printw("Val %x ", cursor.val);
-
 
84
		printw("Dp %x ", cursor.dp);
-
 
85
		printw("\n");
-
 
86
 
-
 
87
		printw("But: %02X ", controller.dis[0]->buttons & 0xff);
-
 
88
		printw("Rot: %02X ", controller.dis[0]->rotary & 0xff);
-
 
89
		printw("\n");
-
 
90
		//printw("\nCursor: ");
53
 
91
 
54
		char key = 0x00;
92
		char key = 0x00;
-
 
93
		while ((key == getch() != ERR)) {
55
		key = getch();
94
			if (key == 'q') {
-
 
95
				cont = 0;
-
 
96
			}
-
 
97
		}
-
 
98
 
-
 
99
 
56
 
100
 
57
 
101
 
-
 
102
 
-
 
103
	}
-
 
104
 
-
 
105
		/*
58
		if (key >= 0x30 && key <= 0x39) {
106
		if (key >= 0x30 && key <= 0x39) {
59
			val = key - '0';
107
			val = key - '0';
60
		} else if  (key == 'w') {
108
		} else if  (key == 'w') {
61
			if (val != 10)
109
			if (val != 10)
62
				val++;
110
				val++;
63
		} else if (key == 's') {
111
		} else if (key == 's') {
64
			if (val != 0)
112
			if (val != 0)
65
				val--;
113
				val--;
66
		} else if (key == 'd') {
114
		} else if (key == 'a') {
67
			if (dig!=0)
115
			if (dig!=0)
68
				dig--;
116
				dig--;
69
		} else if (key == 'a') {
117
		} else if (key == 'd') {
70
			if (dig != 4)
118
			if (dig != 9)
71
				dig++;
119
				dig++;
72
		} else if (key == 'q') {
120
		} else if (key == 'q') {
73
			if (dis != 1)
121
			if (dis != DISPLAYS_ATTACHED)
74
				dis++;
122
				dis++;
75
		} else if (key == 'e') {
123
		} else if (key == 'e') {
76
			if (dis != 0)
124
			if (dis != 0)
77
				dis--;
125
				dis--;
-
 
126
		} else if (key == '.') {
-
 
127
			dp = 1 - dp;
-
 
128
		} else if (key == 'g') {
-
 
129
			getInput(0);
-
 
130
			but = usbReplyBuf[0];
-
 
131
			rot = usbReplyBuf[1];
-
 
132
 
-
 
133
		} else if (key == 'p') {
-
 
134
			unsigned short send = 1000;
-
 
135
			sendShort(dis, dig, send);
78
		} else if (key == 'l') {
136
		} else if (key == 'l') {
-
 
137
			sendLatch(0);
-
 
138
		} else if (key == 'j') {
79
			printw(":");
139
			printw(":");
80
			char* data = getBCD(5);
140
			char* data = getBCD(10);
81
			char i;
141
			char i;
82
			char n = 4;
-
 
83
			for (i=0; i<5; i++) {
142
			for (i=0; i<10; i++) {
84
				sendDigit(dis, i, data[n]);
143
				sendDigit(dis, i, data[i], 0);
85
				n--;
-
 
86
			}
144
			}
87
			free(data);
145
			free(data);
88
		} else if (key == 'k') {
146
		} else if (key == 'k') {
89
			printw("k");
147
			printw("k");
90
			char data1[5] = {0x0a, 0x0a, 0x0a, 0x0a, 0x0a};
-
 
91
			char data2[5] = {0x0a, 0x0a, 0x0a, 0x0a, 0x0a};
-
 
92
			char i;
148
			char i;
93
			for (i=0; i<5; i++) {
149
			for (i=0; i<10; i++) {
94
				sendDigit(0, i, data1[i]);
150
				sendDigit(0, i, 0x0a, 0);
95
			}
-
 
96
			for (i=0; i<5; i++) {
-
 
97
				sendDigit(1, i, data2[i]);
-
 
98
			}
151
			}
-
 
152
			sendLatch(0);
99
		} else if (key == 0x0a) {
153
		} else if (key == 0x0a) {
100
			sendDigit(dis, dig, val);
154
			sendDigit(dis, dig, val, dp);
-
 
155
			sendLatch(0);
101
		} else if (key == 0x1b) {
156
		} else if (key == 0x1b) {
102
			cont = 0;
157
			cont = 0;
103
		}
158
		}
104
	}
159
		*/
105
 
160
 
106
	printw("\nPress key to exit\n");
161
	printw("\nPress key to exit\n");
107
	getch();
162
	getch();
-
 
163
	echo();
-
 
164
	nodelay(stdscr, false);
108
	endwin();
165
	endwin();
109
 
166
 
110
	usb_close(handle);
167
	usb_close(handle);
111
 
168
 
112
	return 0;
169
	return 0;
113
}
170
}
114
 
171
 
-
 
172
void drawScreen() {
-
 
173
	printw("\nCursor: ");
-
 
174
	printw("Dis: %x ", cursor.dis);
-
 
175
	printw("Dig %x ", cursor.dig);
-
 
176
	printw("Val %x ", cursor.val);
-
 
177
	printw("Dp %x ", cursor.dp);
-
 
178
	printw("\n");
-
 
179
 
-
 
180
	printw("But: %02X ", controller.dis[0]->buttons & 0xff);
-
 
181
	printw("Rot: %02X ", controller.dis[0]->rotary & 0xff);
-
 
182
	printw("\n");
-
 
183
}
-
 
184
 
-
 
185
char getInput(char dis) {
-
 
186
	char nBytes = 0;
-
 
187
 
-
 
188
	nBytes = usb_control_msg(handle,
-
 
189
		USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN,
-
 
190
		30,
-
 
191
		dis,
-
 
192
		0,
-
 
193
		(char*)usbReplyBuf,
-
 
194
		sizeof(usbReplyBuf),
-
 
195
		5000);
-
 
196
 
-
 
197
	return nBytes;
-
 
198
}
-
 
199
 
115
char sendDigit(char dis, char dig, char val) {
200
char sendLatch(char dis) {
116
	char nBytes = 0;
201
	char nBytes = 0;
117
	char* usbReplyBuf[64];
-
 
118
 
202
 
119
	nBytes = usb_control_msg(handle,
203
	nBytes = usb_control_msg(handle,
120
		USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN,
204
		USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN,
121
		20,
205
		20,
-
 
206
		dis,
-
 
207
		0,
-
 
208
		(char*)usbReplyBuf,
-
 
209
		sizeof(usbReplyBuf),
-
 
210
		5000);
-
 
211
 
-
 
212
	return nBytes;
-
 
213
}
-
 
214
 
-
 
215
char sendDigit(char dis, char dig, char val, char dp) {
-
 
216
	char nBytes = 0;
-
 
217
 
-
 
218
	nBytes = usb_control_msg(handle,
-
 
219
		USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN,
-
 
220
		21,
-
 
221
		(short)dis<<8 | dig,
-
 
222
		dp << 8 | val,
-
 
223
		(char*)usbReplyBuf,
-
 
224
		sizeof(usbReplyBuf),
-
 
225
		5000);
-
 
226
}
-
 
227
 
-
 
228
char sendShort(char dis, char dig, short val) {
-
 
229
	char nBytes = 0;
-
 
230
 
-
 
231
	nBytes = usb_control_msg(handle,
-
 
232
		USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN,
-
 
233
		50,
122
		(short)dis<<8 | dig,
234
		(short)dis<<8 | dig,
123
		val,
235
		val,
124
		*usbReplyBuf,
236
		(char*)usbReplyBuf,
125
		sizeof(usbReplyBuf),
237
		sizeof(usbReplyBuf),
126
		5000);
238
		5000);
-
 
239
	return nBytes;
127
}
240
}
128
 
241
 
129
char* getBCD(char maxLen) {
242
char* getBCD(char maxLen) {
130
	if (maxLen > 8) maxLen == 8;
243
	if (maxLen > 10) maxLen == 10;
131
	char* buffer = malloc(sizeof(char) * maxLen);
244
	char* buffer = malloc(sizeof(char) * maxLen);
132
	char len = 0;
245
	char len = 0;
133
 
246
 
134
 
-
 
-
 
247
	nodelay(stdscr, false);
135
	while (1) {
248
	while (1) {
136
		char key = 0x00;
249
		char key = 0x00;
137
		key = getch();
250
		key = getch();
138
		if ((key >= 0x30 && key <= 0x39) && len < maxLen) {
251
		if ((key >= 0x30 && key <= 0x39) && len <= maxLen) {
139
			buffer[len] = key - '0';
252
			buffer[len] = key - '0';
140
			len++;
253
			len++;
141
			printw("%c", key);
254
			printw("%c", key);
142
		} else if (key == 0x07) {
255
		} else if (key == 0x07) {
143
			delch();
256
			delch();
Line 151... Line 264...
151
		} else if (key == 0x71) {
264
		} else if (key == 0x71) {
152
 
265
 
153
		}
266
		}
154
 
267
 
155
	}
268
	}
-
 
269
	nodelay(stdscr, false);
156
}
270
}
157
 
271
 
158
 
272
 
159
 
273
 
160
/* Used to get descriptor strings for device identification */
274
/* Used to get descriptor strings for device identification */
Line 242... Line 356...
242
		}
356
		}
243
	}
357
	}
244
 
358
 
245
	return NULL;
359
	return NULL;
246
}
360
}
247
 
-
 
248
 
-
 
249
/*******************************************************/
-
 
250
/*
-
 
251
char* getBCD(char maxLen) {
-
 
252
	if (maxLen > 8) maxLen == 8;
-
 
253
	char* buffer = malloc(sizeof(char) * maxLen);
-
 
254
	char len = 0;
-
 
255
 
-
 
256
 
-
 
257
	while (1) {
-
 
258
		char key = 0x00;
-
 
259
		key = getch();
-
 
260
		if ((key >= 0x30 && key <= 0x38) && len < maxLen) {
-
 
261
			buffer[len] = key - '0';
-
 
262
			len++;
-
 
263
			printw("%c", key);
-
 
264
		} else if (key == 0x08) {
-
 
265
			delch();
-
 
266
			len--;
-
 
267
			buffer[len] = 0x00;
-
 
268
		} else if  (key == 0x0a) {
-
 
269
			return buffer;
-
 
270
		} else if (key == 0x1b) {
-
 
271
			return malloc(sizeof(char));
-
 
272
		} else if (key == 0x71) {
-
 
273
 
-
 
274
		}
-
 
275
 
-
 
276
	}
-
 
277
}
-
 
278
*/
-