Subversion Repositories group.electronics

Rev

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

Rev 109 Rev 110
Line 74... Line 74...
74
} buttons[BUTTONS];
74
} buttons[BUTTONS];
75
 
75
 
76
volatile struct {
76
volatile struct {
77
	uint8_t direction;
77
	uint8_t direction;
78
	uint8_t timer;
78
	uint8_t timer;
79
} rotary;
79
} rotary[2];
80
 
80
 
81
int main(void) {
81
int main(void) {
82
	
82
	
83
	setup();
83
	setup();
84
	
84
	
Line 104... Line 104...
104
		PB4	- Input, Pullup		- Function select
104
		PB4	- Input, Pullup		- Function select
105
		PB5	- Input, Pullup		- Function select
105
		PB5	- Input, Pullup		- Function select
106
	*/
106
	*/
107
	DDRB	= 0B00001111;
107
	DDRB	= 0B00001111;
108
	PORTB 	= 0B00111111;
108
	PORTB 	= 0B00111111;
-
 
109
	
-
 
110
	/*
-
 
111
		PB2	- Input, Pullup, PCINT16	- Rotary 2a
-
 
112
		PB3	- Input, Pullup, PCINT16	- Rotary 2b
-
 
113
	*/
-
 
114
	DDRC	= 0B00000000;
-
 
115
	PORTC 	= 0B00000011;	
109
 
116
 
110
	/*
117
	/*
111
		PD0	- Input, Pullup, PCINT16	- Rotary 1a
118
		PD0	- Input, Pullup, PCINT16	- Rotary 1a
112
		PD1	- Input, Pullup, PCINT17	- Rotary 1b
119
		PD1	- Input, Pullup, PCINT17	- Rotary 1b
113
 
120
 
Line 117... Line 124...
117
		PD6	- Input, Pullup		- Keypad 1
124
		PD6	- Input, Pullup		- Keypad 1
118
		PD7	- Input, Pullup		- Keypad 5
125
		PD7	- Input, Pullup		- Keypad 5
119
	*/
126
	*/
120
	DDRD	= 0B00010000;
127
	DDRD	= 0B00010000;
121
	PORTD	= 0B11110011;
128
	PORTD	= 0B11110011;
122
 
129
	
-
 
130
	// Pin Change Interrupts
-
 
131
	PCMSK1 |= (( 1 << PCINT10 ) | ( 1 << PCINT11 )); //Rotary Encoder 2
123
	PCMSK2 |= (( 1 << PCINT16 ) | ( 1 << PCINT17 )); //enable encoder pins interrupt sources
132
	PCMSK2 |= (( 1 << PCINT16 ) | ( 1 << PCINT17 )); //Rotary Encoder 1
124
	PCICR |= ( 1 << PCIE2 ); //enable pin change interrupts
133
	PCICR |= ((1 << PCIE1 ) | (1 << PCIE2)); 
125
	
134
	
126
	analogInit();
135
	analogInit();
127
	sysclockInit();
136
	sysclockInit();
128
	
137
	
129
	reportKeyboard.report_id = 1;
138
	reportKeyboard.report_id = 1;
Line 199... Line 208...
199
	}
208
	}
200
	return key;
209
	return key;
201
}
210
}
202
 
211
 
203
void checkRotarys() {
212
void checkRotarys() {
-
 
213
	uint8_t i = 0;
-
 
214
	for (i=0; i<=1; i++) {
-
 
215
		// If our rotary timer has run out, turn direction
-
 
216
		//   off and set the cool down period
204
	if (rotary.direction && rotary.timer == 0) {
217
		if (rotary[i].direction && rotary[i].timer == 0) {
205
		rotary.direction = 0x00;
218
			rotary[i].direction = 0x00;
206
		rotary.timer = ROTARY_OFF_TIME;
219
			rotary[i].timer = ROTARY_OFF_TIME;
207
	}
220
		}
208
	
221
		
-
 
222
		// If timer is still going, set the correct button
-
 
223
		//   of the joystick to press
209
	if (rotary.timer != 0) {
224
		if (rotary[i].timer != 0) {
210
		if (rotary.direction == 1) {
225
			if (rotary[i].direction == 1) {
-
 
226
				switch (i) {
211
			reportJoystick.rot1a = 1; 
227
					case 0: reportJoystick.rot1a = 1; break;
-
 
228
					case 1: reportJoystick.rot2a = 1; break;
-
 
229
				}
-
 
230
				 
212
		} else if (rotary.direction == 2) {
231
			} else if (rotary[i].direction == 2) {
-
 
232
				switch (i) {
213
			reportJoystick.rot1b = 1; 
233
					case 0: reportJoystick.rot1b = 1; break;
-
 
234
					case 1: reportJoystick.rot2b = 1; break;
-
 
235
				} 
-
 
236
			}
214
		}
237
		}
215
	}
238
	}
216
 
-
 
217
}
239
}
218
 
240
 
219
void checkButtons() {
241
void checkButtons() {
220
 
242
 
221
	uint8_t key = getKey();
243
	uint8_t key = getKey();
Line 302... Line 324...
302
        pcInt[pcint].mask = pcInt[pcint].current ^ pcInt[pcint].last;
324
        pcInt[pcint].mask = pcInt[pcint].current ^ pcInt[pcint].last;
303
        pcInt[pcint].last = pcInt[pcint].current;
325
        pcInt[pcint].last = pcInt[pcint].current;
304
 
326
 
305
 
327
 
306
        //  Dont continue if we already have a button press going out
328
        //  Dont continue if we already have a button press going out
307
        if (rotary.direction != 0 && rotary.timer == 0) {
329
        //if (rotary.direction != 0 && rotary.timer == 0) {
308
                pcInt[pcint].mask = 0;
330
        //        pcInt[pcint].mask = 0;
309
                return;
331
        //        return;
-
 
332
        //}
-
 
333
		
-
 
334
		// For Each rotary:
-
 
335
        // 		Check which pin caused the interrupt. If they both
-
 
336
        //  		equal 0, the pin that interrupted is the direction
-
 
337
		
-
 
338
		// Rotary 0
-
 
339
        if (rbi(pcInt[pcint].current, PCINT10) == 0 
-
 
340
                && rbi(pcInt[pcint].current, PCINT11) == 0 
-
 
341
                && rbi(pcInt[pcint].mask, PCINT10) ) {
-
 
342
				
-
 
343
					if (rotary[0].timer == 0 && rotary[0].direction == 0) {
-
 
344
                        rotary[0].direction = 1;
-
 
345
						rotary[0].timer = ROTARY_ON_TIME;
-
 
346
					}
-
 
347
        } else if (rbi(pcInt[pcint].current, PCINT10) == 0 
-
 
348
                && rbi(pcInt[pcint].current, PCINT11) == 0 
-
 
349
                && rbi(pcInt[pcint].mask, PCINT11) ) {
-
 
350
					
-
 
351
					if (rotary[0].timer == 0 && rotary[0].direction == 0) {
-
 
352
                        rotary[0].direction = 2;
-
 
353
						rotary[0].timer = ROTARY_ON_TIME;
-
 
354
					}
310
        }
355
        }
-
 
356
		
311
        // Check which pin caused the interrupt. If they both
357
		// Rotary 1
312
        //  equal 0, the pin that interrupted is the direction
-
 
313
        if (rbi(pcInt[pcint].current, PCINT16) == 0 
358
        if (rbi(pcInt[pcint].current, PCINT16) == 0 
314
                && rbi(pcInt[pcint].current, PCINT17) == 0 
359
                && rbi(pcInt[pcint].current, PCINT17) == 0 
315
                && rbi(pcInt[pcint].mask, PCINT16) ) {
360
                && rbi(pcInt[pcint].mask, PCINT16) ) {
316
				
361
				
317
					if (rotary.timer == 0) {
362
					if (rotary[0].timer == 0 && rotary[0].direction == 0) {
318
                        rotary.direction = 1;
363
                        rotary[0].direction = 1;
319
						rotary.timer = ROTARY_ON_TIME;
364
						rotary[0].timer = ROTARY_ON_TIME;
320
					}
365
					}
321
 
-
 
322
 
-
 
323
        } else if (rbi(pcInt[pcint].current, PCINT16) == 0 
366
        } else if (rbi(pcInt[pcint].current, PCINT16) == 0 
324
                && rbi(pcInt[pcint].current, PCINT17) == 0 
367
                && rbi(pcInt[pcint].current, PCINT17) == 0 
325
                && rbi(pcInt[pcint].mask, PCINT17) ) {
368
                && rbi(pcInt[pcint].mask, PCINT17) ) {
326
					
369
					
327
					if (rotary.timer == 0) {
370
					if (rotary[0].timer == 0 && rotary[0].direction == 0) {
328
                        rotary.direction = 2;
371
                        rotary[0].direction = 2;
329
						rotary.timer = ROTARY_ON_TIME;
372
						rotary[0].timer = ROTARY_ON_TIME;
330
					}
373
					}
331
 
-
 
332
        }
374
        }
333
 
375
 
334
        // Clear the mask so we know we've delth with it
376
        // Clear the mask so we know we've delth with it
335
        pcInt[pcint].mask = 0;
377
        pcInt[pcint].mask = 0;
336
}
378
}
Line 340... Line 382...
340
	if (tmr0_ovf >= sys_ovf_tick) {
382
	if (tmr0_ovf >= sys_ovf_tick) {
341
		systime++;
383
		systime++;
342
		tmr0_ovf = 0;
384
		tmr0_ovf = 0;
343
		//millis_tick();	// Not working, taking too long to call?
385
		//millis_tick();	// Not working, taking too long to call?
344
 
386
 
-
 
387
		// Decrease our various millisecond timers
-
 
388
 
345
		if (buttons[0].timer)
389
		if (buttons[0].timer)
346
			buttons[0].timer--;
390
			buttons[0].timer--;
347
			
391
			
348
		if (lcdTimer)
392
		if (lcdTimer)
349
			lcdTimer--;
393
			lcdTimer--;
350
			
394
		
-
 
395
		uint8_t i = 0;
-
 
396
		for (i=0; i<=1; i++) {
351
		if (rotary.timer)
397
			if (rotary[i].timer)
352
			rotary.timer--;
398
				rotary[i].timer--;
-
 
399
		}
353
 
400
 
354
	}
401
	}
355
}
402
}
356
 
403
 
357
ISR(PCINT0_vect) {
404
ISR(PCINT0_vect) {