Subversion Repositories group.electronics

Rev

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

Rev 102 Rev 103
Line 72... Line 72...
72
	uint8_t timer;
72
	uint8_t timer;
73
	uint8_t waitup;
73
	uint8_t waitup;
74
} buttons[BUTTONS];
74
} buttons[BUTTONS];
75
 
75
 
76
volatile struct {
76
volatile struct {
77
	
-
 
78
	union {
77
	union {
79
		uint8_t data;
78
		uint8_t data;
80
		struct {
79
		struct {
81
			uint8_t stat:4;
80
			uint8_t stat:4;
82
			uint8_t sent:4;
81
			uint8_t sent:4;
83
		};
82
		};
84
	};
83
	};
85
} rotary[ROTARYS];
84
} rotary[ROTARYS];
86
 
85
 
87
int main(void)
86
int main(void)
88
{
87
{1234567890
89
	
88
	
90
	setup();
89
	setup();
91
	
90
	
92
    while(1)
91
    while(1)
93
    {
92
    {
Line 167... Line 166...
167
	if (lcdTimer==0) {
166
	if (lcdTimer==0) {
168
		updateLcd();
167
		updateLcd();
169
		lcdTimer = LCD_UPDATE;
168
		lcdTimer = LCD_UPDATE;
170
	}
169
	}
171
	
170
	
-
 
171
	reportJoystick.data1[0] = (-128 + analogRead(0));
-
 
172
	reportJoystick.data1[1] = (-128 + analogRead(1));
-
 
173
	reportJoystick.data2 = 0x0000;		// Clear all the buttons
172
	
174
 
173
	if (rotaryTimer==0) {
175
	reportKeyboard.modifier = 0x00;
174
		checkRotarys();
-
 
175
		rotaryTimer = ROTARY_UPDATE;
176
	reportKeyboard.keycode = 0x00;	
176
	}
-
 
177
	
177
	
178
	
178
	
179
	checkButtons();
179
	checkButtons();
-
 
180
	checkRotarys();
180
 
181
	
181
 
182
 
182
	if(usbInterruptIsReady()){
183
	if(usbInterruptIsReady()){
183
	    usbSendHidReport((uchar*)&reportKeyboard, sizeof(reportKeyboard));
184
	    usbSendHidReport((uchar*)&reportKeyboard, sizeof(reportKeyboard));
184
	    usbSendHidReport((uchar*)&reportJoystick, sizeof(reportJoystick));
185
	    usbSendHidReport((uchar*)&reportJoystick, sizeof(reportJoystick));
185
    }	
186
    }	
Line 205... Line 206...
205
	return key;
206
	return key;
206
}
207
}
207
 
208
 
208
void checkRotarys() {
209
void checkRotarys() {
209
	uint8_t rot = 0;
210
	uint8_t rot = 0;
210
	for (rot=0; rot<=(ROTARYS - 1); rot++) {
211
	//for (rot=0; rot<=(ROTARYS - 1); rot++) {
211
		if (rotary[rot].stat == 0x01 && rotary[rot].sent == 0) {
212
		if (rotary[rot].stat == 0x01 && rotary[rot].sent == 0) {
212
			rotary[rot].sent = 1;
213
			rotary[rot].sent = 1;
213
			switch (rot) {
214
			switch (rot) {
214
				case(0):        reportJoystick.rot1a = 1; break;
215
				case(0):        reportJoystick.rot1a = 1; break;
215
				case(1):        reportJoystick.rot2a = 1; break;
216
				//case(1):        reportJoystick.rot2a = 1; break;
216
			}
217
			}
217
		} else if (rotary[rot].stat == 0x02 && rotary[rot].sent == 0) {
218
		} else if (rotary[rot].stat == 0x02 && rotary[rot].sent == 0) {
218
			rotary[rot].sent = 1;
219
			rotary[rot].sent = 1;
219
			switch (rot) {
220
			switch (rot) {
220
				case(0):      reportJoystick.rot1b = 1; break;
221
				case(0):      reportJoystick.rot1b = 1; break;
221
				case(1):      reportJoystick.rot2b = 1; break;
222
				//case(1):      reportJoystick.rot2b = 1; break;
222
			}
223
			}
223
		} else {
224
		} else {
224
			rotary[rot].sent = 0;
225
			rotary[rot].sent = 0;
225
		}
226
		}
226
		rotary[rot].stat = 0;
227
		rotary[rot].stat = 0;
227
 
228
 
228
		// tha fuck is this?
229
		// Config setting for a pause between sending
229
		//if (rbi(PINB, PB4))
230
		//if (rbi(PINB, PB4))
230
		//	rotary[rot].sent = 0;
231
			rotary[rot].sent = 0;
231
	}
232
	//}
232
}
233
}
233
 
234
 
234
void checkButtons() {
235
void checkButtons() {
235
 
236
 
236
	reportJoystick.data1[0] = (-128 + analogRead(0));
-
 
237
	reportJoystick.data1[1] = (-128 + analogRead(1));
-
 
238
	reportJoystick.data2 = 0x0000;				// Clear all the buttons
-
 
239
 
-
 
240
	reportKeyboard.modifier = 0x00;
-
 
241
	reportKeyboard.keycode = 0x00;
-
 
242
 
-
 
243
	uint8_t key = getKey();
237
	uint8_t key = getKey();
244
	if (rbi(keySelect, 0)) {
238
	if (rbi(keySelect, 0)) {
245
		// Keypad is joystick
239
		// Keypad is joystick
246
		if (key > 0)
240
		if (key > 0)
247
			reportJoystick.data2 |= (1 << (--key));
241
			reportJoystick.data2 |= (1 << (--key));
Line 312... Line 306...
312
 * Process the Pin Change Interrupt.
306
 * Process the Pin Change Interrupt.
313
 * pcint provides what bank caused the interrupt
307
 * pcint provides what bank caused the interrupt
314
 *
308
 *
315
 */
309
 */
316
void pcInterrupt(uint8_t pcint) {
310
void pcInterrupt(uint8_t pcint) {
317
 
311
		pcint = 1;
318
        switch (pcint) {
312
        /*switch (pcint) {
319
                case 0: pcInt[pcint].current = PINB; break;
313
                case 0: pcInt[pcint].current = PINB; break;
320
                case 1: pcInt[pcint].current = PIND; break;
314
                case 1: pcInt[pcint].current = PIND; break;
321
                case 2: pcInt[pcint].current = PINC; break;
315
                case 2: pcInt[pcint].current = PINC; break;
322
        }
316
        }*/
323
        //pcInt[pcint].current = PIND;
317
        pcInt[pcint].current = PIND;
324
        pcInt[pcint].mask = pcInt[pcint].current ^ pcInt[pcint].last;
318
        pcInt[pcint].mask = pcInt[pcint].current ^ pcInt[pcint].last;
325
        pcInt[pcint].last = pcInt[pcint].current;
319
        pcInt[pcint].last = pcInt[pcint].current;
326
 
320
 
327
        // Select what rotary we are dealing with
321
        // Select what rotary we are dealing with
328
        //   based on the pc interrupt that fired.
322
        //   based on the pc interrupt that fired.
329
        uint8_t rot = 0;
323
        uint8_t rot = 0;
330
        if (pcint == 1) 
324
        //if (pcint == 1) 
331
                rot = 1;
325
        //        rot = 1;
332
 
326
 
333
        // If rot stat is not 0, we havn't sent
327
        // If rot stat is not 0, we havn't sent
334
        //  our last results yet. Skip this click.
328
        //  our last results yet. Skip this click.
335
        if (rotary[rot].stat != 0) {
329
        if (rotary[rot].stat != 0) {
336
                pcInt[pcint].mask = 0;
330
                pcInt[pcint].mask = 0;
Line 363... Line 357...
363
			buttons[0].timer--;
357
			buttons[0].timer--;
364
			
358
			
365
		if (lcdTimer)
359
		if (lcdTimer)
366
			lcdTimer--;
360
			lcdTimer--;
367
			
361
			
368
		if (rotaryTimer)
362
		//if (rotaryTimer)
369
			rotaryTimer--;
363
		//	rotaryTimer--;
370
 
364
 
371
	}
365
	}
372
}
366
}
373
 
367
 
374
ISR(PCINT0_vect) {
368
ISR(PCINT0_vect) {