Subversion Repositories group.electronics

Rev

Rev 104 | Rev 106 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 104 Rev 105
Line 21... Line 21...
21
#include "lcd.h"
21
#include "lcd.h"
22
#include "wire.h"
22
#include "wire.h"
23
#include "hiddesc.h"
23
#include "hiddesc.h"
24
 
24
 
25
#define BUTTONS	 		1
25
#define BUTTONS	 		1
26
#define ROTARYS			1
-
 
27
 
26
 
28
#define LCD_UPDATE		11
27
#define LCD_UPDATE		11
29
#define	ROTARY_UPDATE	5
-
 
30
 
28
 
31
void pcInterrupt(uint8_t);
29
void pcInterrupt(uint8_t);
32
uint8_t getKey(void);
30
uint8_t getKey(void);
33
void updateLcd();
31
void updateLcd();
34
void checkRotarys();
32
void checkRotarys();
35
void checkButtons(void);
33
void checkButtons(void);
36
 
34
 
37
 
35
 
38
// * = 0x25, #=0x20
36
// * = 0x25, #=0x20, 0 = 0x27
39
// F9 = 0x42, F12 = 0x45
37
// F9 = 0x42, F12 = 0x45, ` = 0x35
40
uint8_t keyMap[] = { 	0x1E, 0x1F, 0x20,
38
uint8_t keyMap[] = { 	0x1E, 0x1F, 0x20,	// 1, 2, 3
41
						0x21, 0x22, 0x23,
39
						0x21, 0x22, 0x23,	// 4, 5, 6
42
						0x24, 0x25, 0x26,
40
						0x24, 0x25, 0x26,	// 7, 8, 9
43
						0x42, 0x27, 0x45 };
41
						0x42, 0x35, 0x45 };	// F9, `, F12
44
 
42
 
45
uint8_t lcdRectangle[] = {   
43
uint8_t lcdRectangle[] = {   
46
	0B00011111,
44
	0B00011111,
47
	0B00010001,
45
	0B00010001,
48
	0B00010001,
46
	0B00010001,
Line 57... Line 55...
57
uint8_t keySelect = 1;
55
uint8_t keySelect = 1;
58
 
56
 
59
// Start these of at different times, so they
57
// Start these of at different times, so they
60
//  don't kick of it the same loop run
58
//  don't kick of it the same loop run
61
volatile uint8_t lcdTimer = 8;
59
volatile uint8_t lcdTimer = 8;
62
volatile uint8_t rotaryTimer = 5;
-
 
63
 
60
 
64
volatile struct {
61
volatile struct {
65
        uint8_t current;
62
        uint8_t current;
66
        uint8_t last;
63
        uint8_t last;
67
        uint8_t mask;
64
        uint8_t mask;
Line 72... Line 69...
72
	uint8_t timer;
69
	uint8_t timer;
73
	uint8_t waitup;
70
	uint8_t waitup;
74
} buttons[BUTTONS];
71
} buttons[BUTTONS];
75
 
72
 
76
volatile struct {
73
volatile struct {
77
	union {
-
 
78
		uint8_t data;
74
	uint8_t direction;
79
		struct {
-
 
80
			uint8_t stat:4;
75
	uint8_t timer;
81
			uint8_t sent:4;
-
 
82
		};
-
 
83
	};
-
 
84
} rotary[ROTARYS];
76
} rotary;
85
 
77
 
86
int main(void) {
78
int main(void) {
87
	
79
	
88
	setup();
80
	setup();
89
	
81
	
Line 204... Line 196...
204
	}
196
	}
205
	return key;
197
	return key;
206
}
198
}
207
 
199
 
208
void checkRotarys() {
200
void checkRotarys() {
209
	uint8_t rot = 0;
-
 
210
	//for (rot=0; rot<=(ROTARYS - 1); rot++) {
-
 
211
		if (rotary[rot].stat == 0x01 && rotary[rot].sent == 0) {
201
	if (rotary.direction && rotary.timer == 0)
212
			rotary[rot].sent = 1;
202
		rotary.direction = 0x00;
213
			switch (rot) {
-
 
214
				case(0):        reportJoystick.rot1a = 1; break;
-
 
215
				//case(1):        reportJoystick.rot2a = 1; break;
-
 
216
			}
203
 
217
		} else if (rotary[rot].stat == 0x02 && rotary[rot].sent == 0) {
-
 
218
			rotary[rot].sent = 1;
204
	if (rotary.direction == 1) {
219
			switch (rot) {
-
 
220
				case(0):      reportJoystick.rot1b = 1; break;
205
		reportJoystick.rot1a = 1; 
221
				//case(1):      reportJoystick.rot2b = 1; break;
206
	} else if (rotary.direction == 2) {
222
			}
-
 
223
		} else {
-
 
224
			rotary[rot].sent = 0;
207
		reportJoystick.rot1b = 1; 
225
		}
208
	}
226
		rotary[rot].stat = 0;
-
 
227
 
209
 
228
		// Config setting for a pause between sending
-
 
229
		//if (rbi(PINB, PB4))
-
 
230
			rotary[rot].sent = 0;
-
 
231
	//}
-
 
232
}
210
}
233
 
211
 
234
void checkButtons() {
212
void checkButtons() {
235
 
213
 
236
	uint8_t key = getKey();
214
	uint8_t key = getKey();
Line 315... Line 293...
315
        }*/
293
        }*/
316
        pcInt[pcint].current = PIND;
294
        pcInt[pcint].current = PIND;
317
        pcInt[pcint].mask = pcInt[pcint].current ^ pcInt[pcint].last;
295
        pcInt[pcint].mask = pcInt[pcint].current ^ pcInt[pcint].last;
318
        pcInt[pcint].last = pcInt[pcint].current;
296
        pcInt[pcint].last = pcInt[pcint].current;
319
 
297
 
320
        // Select what rotary we are dealing with
-
 
321
        //   based on the pc interrupt that fired.
-
 
322
        uint8_t rot = 0;
-
 
323
        //if (pcint == 1) 
-
 
324
        //        rot = 1;
-
 
325
 
298
 
326
        // If rot stat is not 0, we havn't sent
299
        // If rot stat is not 0, we havn't sent
327
        //  our last results yet. Skip this click.
300
        //  our last results yet. Skip this click.
328
        if (rotary[rot].stat != 0) {
301
        if (rotary.direction != 0) {
329
                pcInt[pcint].mask = 0;
302
                pcInt[pcint].mask = 0;
330
                return;
303
                return;
331
        }
304
        }
332
        // Check which pin caused the interrupt. If they both
305
        // Check which pin caused the interrupt. If they both
333
        //  equal 0, the pin that interrupted is the direction
306
        //  equal 0, the pin that interrupted is the direction
334
        if (rbi(pcInt[pcint].current, PCINT17) == 0 
307
        if (rbi(pcInt[pcint].current, PCINT17) == 0 
335
                && rbi(pcInt[pcint].current, PCINT17) == 0 
308
                && rbi(pcInt[pcint].current, PCINT17) == 0 
336
                && rbi(pcInt[pcint].mask, PCINT16) ) {
309
                && rbi(pcInt[pcint].mask, PCINT16) ) {
-
 
310
				
-
 
311
					if (rotary.timer == 0) {
337
                        rotary[rot].stat = 1;
312
                        rotary.direction = 1;
-
 
313
						rotary.timer = 5;
-
 
314
					}
-
 
315
						
338
        } else if (rbi(pcInt[pcint].current, PCINT16) == 0 
316
        } else if (rbi(pcInt[pcint].current, PCINT16) == 0 
339
                && rbi(pcInt[pcint].current, PCINT17) == 0 
317
                && rbi(pcInt[pcint].current, PCINT17) == 0 
340
                && rbi(pcInt[pcint].mask, PCINT17) ) {
318
                && rbi(pcInt[pcint].mask, PCINT17) ) {
-
 
319
					
-
 
320
					if (rotary.timer == 0) {
341
                        rotary[rot].stat = 2;
321
                        rotary.direction = 2;
-
 
322
						rotary.timer = 5;
-
 
323
					}
-
 
324
						
342
        }
325
        }
343
 
326
 
344
        // Clear the mask so we know we've delth with it
327
        // Clear the mask so we know we've delth with it
345
        pcInt[pcint].mask = 0;
328
        pcInt[pcint].mask = 0;
346
}
329
}
Line 356... Line 339...
356
			buttons[0].timer--;
339
			buttons[0].timer--;
357
			
340
			
358
		if (lcdTimer)
341
		if (lcdTimer)
359
			lcdTimer--;
342
			lcdTimer--;
360
			
343
			
361
		//if (rotaryTimer)
344
		if (rotary.timer)
362
		//	rotaryTimer--;
345
			rotary.timer--;
363
 
346
 
364
	}
347
	}
365
}
348
}
366
 
349
 
367
ISR(PCINT0_vect) {
350
ISR(PCINT0_vect) {