Subversion Repositories group.electronics

Rev

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

Rev 152 Rev 154
Line 16... Line 16...
16
#ifndef NULL
16
#ifndef NULL
17
#define NULL    ((void *)0)
17
#define NULL    ((void *)0)
18
#endif
18
#endif
19
 
19
 
20
#define DISPLAYS_ATTACHED 2
20
#define DISPLAYS_ATTACHED 2
21
#define INPUT_REFRESH 5
21
#define INPUT_REFRESH 50
22
 
22
 
23
#define I2C_GET_VERSION			0x01
23
#define I2C_GET_VERSION			0x01
24
#define I2C_SET_DEBUG			0x03
24
#define I2C_SET_DEBUG			0x03
25
#define I2C_SET_DIGITS			0x05
25
#define I2C_SET_DIGITS			0x05
26
#define I2C_SET_DECIMAL_PTS		0x08
26
#define I2C_SET_DECIMAL_PTS		0x08
Line 138... Line 138...
138
	i2cbb_Start();
138
	i2cbb_Start();
139
	i2cbb_Write( display[dis].address << 1 );
139
	i2cbb_Write( display[dis].address << 1 );
140
	i2cbb_Write( I2C_GET_VERSION );
140
	i2cbb_Write( I2C_GET_VERSION );
141
	i2cbb_Stop();
141
	i2cbb_Stop();
142
 
142
 
143
	// Receive rotary data
-
 
144
	i2cbb_Start();
143
	i2cbb_Start();
145
	i2cbb_Write( (display[dis].address << 1) + 1 );
144
	i2cbb_Write( (display[dis].address << 1) + 1 );
146
	hw += (int8_t)i2cbb_Read(1);
145
	hw += (int8_t)i2cbb_Read(1);
147
	sw += (int8_t)i2cbb_Read(1);
146
	sw += (int8_t)i2cbb_Read(1);
148
	i2cbb_Stop();
147
	i2cbb_Stop();
Line 196... Line 195...
196
//  which might affect the user input data tasks
195
//  which might affect the user input data tasks
197
static void updateDisplay(uint8_t dis) {
196
static void updateDisplay(uint8_t dis) {
198
    cbi(PORTB, PB0);
197
    cbi(PORTB, PB0);
199
 
198
 
200
    // Send the display buffer to display board
199
    // Send the display buffer to display board
-
 
200
    uint8_t update = 0;
-
 
201
    uint8_t n;
-
 
202
    for (n=0; n<10; n++) {
-
 
203
    	if (rbi(display[dis].value[n], 7)) {
-
 
204
    		update = 1;
-
 
205
    		break;
-
 
206
    	}
-
 
207
    }
-
 
208
    if (!update) return;
-
 
209
 
201
    i2cbb_Init();
210
    i2cbb_Init();
202
    i2cbb_Start();
211
    i2cbb_Start();
203
    i2cbb_Write( display[dis].address << 1);
212
    i2cbb_Write( display[dis].address << 1);
204
    i2cbb_Write( I2C_SET_DIGITS );
213
    i2cbb_Write( I2C_SET_DIGITS );
205
    uint8_t n;
214
 
206
    for (n=0; n<10; n++) {
215
    for (n=0; n<10; n++) {
-
 
216
    	if (rbi(display[dis].value[n], 7)) {
-
 
217
    		cbi(display[dis].value[n], 7);
207
    	uint8_t send = (n << 4) | display[dis].value[n];
218
    		uint8_t send = (n << 4) | display[dis].value[n];
208
    	i2cbb_Write( send );
219
    		i2cbb_Write( send );
-
 
220
    	}
209
    }
221
    }
210
    i2cbb_Stop();
222
    i2cbb_Stop();
211
 
223
 
212
 
224
 
213
    // Send the decimal point
225
    // Send the decimal point
-
 
226
    if (rbi(display[dis].decpts, 15)) {
214
	i2cbb_Init();
227
		i2cbb_Init();
215
	i2cbb_Start();
228
		i2cbb_Start();
216
	i2cbb_Write( display[dis].address << 1 );
229
		i2cbb_Write( display[dis].address << 1 );
217
	i2cbb_Write( I2C_SET_DECIMAL_PTS );
230
		i2cbb_Write( I2C_SET_DECIMAL_PTS );
218
	i2cbb_Write((uint8_t)(display[dis].decpts>>8));
231
		i2cbb_Write((uint8_t)(display[dis].decpts>>8));
219
	i2cbb_Write((uint8_t)display[dis].decpts);
232
		i2cbb_Write((uint8_t)display[dis].decpts);
220
	i2cbb_Stop();
233
		i2cbb_Stop();
-
 
234
    }
221
 
235
 
222
 
236
 
223
    sbi(PORTB, PB0);
237
    sbi(PORTB, PB0);
224
}
238
}
225
 
239
 
Line 240... Line 254...
240
		case USB_SET_DISPLAY1: {
254
		case USB_SET_DISPLAY1: {
241
			uint8_t dis = rq->wValue.bytes[1];
255
			uint8_t dis = rq->wValue.bytes[1];
242
			uint8_t dig = rq->wValue.bytes[0];
256
			uint8_t dig = rq->wValue.bytes[0];
243
			uint8_t dp = rq->wIndex.bytes[1];
257
			uint8_t dp = rq->wIndex.bytes[1];
244
			uint8_t val = rq->wIndex.bytes[0];
258
			uint8_t val = rq->wIndex.bytes[0];
245
			display[dis].value[dig] = val;
-
 
246
 
259
 
-
 
260
 
-
 
261
			if ((display[dis].value[dig] & 0x0f) != val) {
-
 
262
				display[dis].value[dig] = val;
-
 
263
				sbi(display[dis].value[dig], 7);
-
 
264
			}
-
 
265
 
247
			if (dp)
266
			if (dp) {
248
				sbi(display[dis].decpts, 1 << dig);
267
				sbi(display[dis].decpts, 1 << dig);
249
			else
268
			} else {
250
				cbi(display[dis].decpts, 1 << dig);
269
				cbi(display[dis].decpts, 1 << dig);
251
 
270
			}
252
			//display[dis].decpts |= dp << dig;
-
 
253
 
271
 
254
			break;
272
			break;
255
		}
273
		}
256
 
274
 
257
		// Return the user input data all at once. Its populated from
275
		// Return the user input data all at once. Its populated from