Subversion Repositories group.electronics

Rev

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

Rev 35 Rev 36
Line 115... Line 115...
115
	PB0	- Output 		- Keypad 1
115
	PB0	- Output 		- Keypad 1
116
	PB1	- Output 		- Keypad 2
116
	PB1	- Output 		- Keypad 2
117
	PB2	- Output 		- Keypad 3
117
	PB2	- Output 		- Keypad 3
118
	PB3	- Output 		- Keypad 4
118
	PB3	- Output 		- Keypad 4
119
	PB4	- Input, Pullup		- Function select
119
	PB4	- Input, Pullup		- Function select
-
 
120
	PB5	- Input, Pullup		- Function select
120
  */
121
  */
121
  DDRB		= 0B00001111;
122
  DDRB		= 0B00001111;
122
  PORTB 	= 0B00011111;
123
  PORTB 	= 0B00111111;
123
 
124
 
124
  /*
125
  /*
125
	PD0	- Input, Pullup, PCINT16	- Rotary 1a
126
	PD0	- Input, Pullup, PCINT16	- Rotary 1a
126
	PD1	- Input, Pullup, PCINT17	- Rotary 1b
127
	PD1	- Input, Pullup, PCINT17	- Rotary 1b
127
 
128
 
Line 159... Line 160...
159
    usbPoll();
160
    usbPoll();
160
 
161
 
161
    if(usbInterruptIsReady()){
162
    if(usbInterruptIsReady()){
162
	reportJoystick.data1[0] = (-128 + analogRead(0));
163
	reportJoystick.data1[0] = (-128 + analogRead(0));
163
	reportJoystick.data1[1] = (-128 + analogRead(1));
164
	reportJoystick.data1[1] = (-128 + analogRead(1));
164
	reportJoystick.data2 = 0x0000;
165
	reportJoystick.data2 = 0x0000;				// Clear all the buttons
165
 
166
 
-
 
167
	reportKeyboard.keycode = 0x00;
-
 
168
	reportKeyboard.modifier = 0x00;
166
 
169
 
167
	uint8_t key = getKey();
170
	uint8_t key = getKey();
168
	if (rbi(PINB, PB5)) {
171
	if (rbi(PINB, PB5)) {
169
		cbi(PORTD, PD5);
172
		cbi(PORTD, PD4);
170
		// Keypad is joystick
173
		// Keypad is joystick
171
		if (key > 0)
174
		if (key > 0)
172
			reportJoystick.data2 |= (1 << (key -1));
175
			reportJoystick.data2 |= (1 << (key -1));
173
	} else {
176
	} else {
174
		sbi(PORTD, PD5);
177
		sbi(PORTD, PD4);
175
		// Keypad is keyboard
178
		// Keypad is keyboard
176
		if (key > 0) {
179
		if (key > 0) {
177
			reportKeyboard.modifier = 0x00;
180
			key--;
178
			if (key==10 || key==12)
181
			//if (key==10 || key==12)
179
				reportKeyboard.modifier |= (1<<1);	//Left shif
182
			//	reportKeyboard.modifier |= (1<<1);	//Left shif
180
			reportKeyboard.keycode = keyMap[key];
183
			//reportKeyboard.keycode = keyMap[key];
-
 
184
			reportKeyboard.keycode = 0x30;
-
 
185
 
181
		}
186
		}
182
	}
187
	}
183
 
188
 
184
	// Now work out what rotary to send, if any
189
	// Now work out what rotary to send, if any
185
	// Also record if we sent a positive response, 
190
	// Also record if we sent a positive response, 
Line 206... Line 211...
206
 
211
 
207
	        if (rbi(PINB, PB4))
212
	        if (rbi(PINB, PB4))
208
        	        rotdata[rot][SENT] = 0;
213
        	        rotdata[rot][SENT] = 0;
209
	}
214
	}
210
 
215
 
211
/*	
-
 
212
	if (rot_stat[0] == 0x01 && rot_sent[0] == 0) {
-
 
213
		report.rot1a = 1;
-
 
214
		rot_sent[0] = 1;
-
 
215
	} else if (rot_stat[0] == 0x02 && rot_sent[0] == 0) {
-
 
216
		report.rot1b = 1;
-
 
217
		rot_sent[0] = 1;
-
 
218
	} else {
-
 
219
		rot_sent[0] = 0;
-
 
220
	}
-
 
221
 
-
 
222
	// Reset our stat so ready for next turn
-
 
223
	rot_stat[0] = 0;
-
 
224
 
-
 
225
	// If our function select is set, dont bother
-
 
226
	//  sending a 'o' between consequtive 1's.
-
 
227
	if (rbi(PINB, PB4))
-
 
228
		rot_sent[0] = 0;
-
 
229
*/
-
 
230
 
-
 
231
      /* called after every poll of the interrupt endpoint */
216
      /* called after every poll of the interrupt endpoint */
232
      usbSetInterrupt(&reportKeyboard, sizeof(reportKeyboard));
217
      usbSetInterrupt(&reportKeyboard, sizeof(reportKeyboard));
233
      usbSetInterrupt(&reportJoystick, sizeof(reportJoystick));
218
      usbSetInterrupt(&reportJoystick, sizeof(reportJoystick));
234
    }
219
    }
235
  }
220
  }