Subversion Repositories HomeAutomation

Rev

Rev 645 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 645 Rev 647
Line 5... Line 5...
5
 * Contains no intelligence. It just prints what it is told to.
5
 * Contains no intelligence. It just prints what it is told to.
6
 *
6
 *
7
 * @date    2007-10-01
7
 * @date    2007-10-01
8
 * @author  Martin Norden
8
 * @author  Martin Norden
9
 *
9
 *
-
 
10
 * TODO: put rotary encoder in external library, same with s16/u16tostr, cleanup, read external sensors... a lot basically.
-
 
11
 * Assume all sensor conversion done on the sensorcard, use canstandard here
10
 */
12
 */
11
 
13
 
12
/*-----------------------------------------------------------------------------
14
/*-----------------------------------------------------------------------------
13
 * Includes
15
 * Includes
14
 *---------------------------------------------------------------------------*/
16
 *---------------------------------------------------------------------------*/
Line 74... Line 76...
74
#define SCR_RPM         0x03
76
#define SCR_RPM         0x03
75
#define SCR_VOLTAGE     0x04
77
#define SCR_VOLTAGE     0x04
76
#define LAST_SCREEN     0x04
78
#define LAST_SCREEN     0x04
77
void standardScreen(char* text, uint16_t value, uint16_t maxvalue);
79
void standardScreen(char* text, uint16_t value, uint16_t maxvalue);
78
 
80
 
-
 
81
void numtoascii( int16_t num, char **str );
-
 
82
void rattoascii( int16_t num, uint8_t decimalplace, char *string); //decimalplace is number ofjah
-
 
83
 
-
 
84
uint8_t *parsetemperature(int16_t value, uint8_t *str,uint8_t decimal,uint8_t options);
79
uint8_t *io_s16toStr(int16_t value, uint8_t *str,uint8_t decimal,uint8_t options);
85
uint8_t *io_s16toStr(int16_t value, uint8_t *str,uint8_t decimal,uint8_t options);
80
uint8_t *io_u16toStr(uint16_t value, uint8_t *str,uint8_t decimal,uint8_t options);
86
uint8_t *io_u16toStr(uint16_t value, uint8_t *str,uint8_t decimal,uint8_t options);
81
 
87
 
82
 
88
 
83
 
89
 
84
/*******************************************************************************
90
/*******************************************************************************
85
 * Sensor Values, Scale factors etc.                                           *
91
 * Sensor Values, Scale factors etc.                                           *
86
 *******************************************************************************/
92
 *******************************************************************************/
87
int16_t sensor_Boost = 120; //Should be set automagically by incoming CAN
93
int16_t sensor_Boost = 120; //Should be set automagically by incoming CAN
88
int16_t sensor_Boost_Max = 200;
94
int16_t sensor_Boost_Max = 200;  //highest boost so far
89
 
95
 
90
uint16_t sensor_RPM = 2573;
96
uint16_t sensor_RPM = 2573;
91
uint8_t sensor_Lambda = 127;
97
uint8_t sensor_Lambda = 127;
92
uint8_t sensor_Voltage = 143;
98
uint8_t sensor_Voltage = 143;
93
 
99
 
94
#define scale_Boost 809 //Read from eeprom later on?
100
#define scale_Boost 200 //see "Representation av storheter"
95
#define scale_BoostOffset 168 //Read from eeprom later on?
-
 
96
#define scale_BoostMAX 200
101
#define scale_BoostMAX 200
97
#define scale_RPMMAX 8000 //Can be set as in eeprom later perhaps?
102
#define scale_RPMMAX 8000 //Can be set as in eeprom later perhaps?
98
#define scale_Voltage 1024
103
#define scale_Voltage 1024
99
#define scale_VoltageMAX 150
104
#define scale_VoltageMAX 150
100
 
105
 
Line 106... Line 111...
106
void can_receive(Can_Message_t *msg){
111
void can_receive(Can_Message_t *msg){
107
    if(!rxMsgFull){
112
    if(!rxMsgFull){
108
        memcpy((void*)&rxMsg, msg, sizeof(rxMsg));
113
        memcpy((void*)&rxMsg, msg, sizeof(rxMsg));
109
        rxMsgFull = 1;
114
        rxMsgFull = 1;
110
    }
115
    }
111
}
116
}
112
 
117
 
113
ISR( PCINT2_vect ){
118
ISR( PCINT2_vect ){
114
// For ROTENC_A and ROTENC_B FIXME Šr inte riktigt rŠtt. Verkar vara bra tycker jag?
119
// For ROTENC_A and ROTENC_B FIXME Šr inte riktigt rŠtt. Verkar vara bra tycker jag?
115
    rotenc();
120
    rotenc();
116
}
121
}
117
 
122
 
118
ISR( PCINT0_vect ){
123
ISR( PCINT0_vect ){
119
// For ROTENC_BTN
124
// For ROTENC_BTN
120
    rotenc();
125
    rotenc();
121
}
126
}
122
 
127
 
Line 177... Line 182...
177
 
182
 
178
    /* main loop */
183
    /* main loop */
179
    while(1){
184
    while(1){
180
        /* check if any messages have been received */
185
        /* check if any messages have been received */
181
        if(rxMsgFull){
186
        if(rxMsgFull){
182
            uint16_t act_type;
187
            uint16_t sns_type;
183
            uint8_t lcdid;
188
            uint8_t snsid;
184
            if ( ((rxMsg.Id & CAN_MASK_CLASS)>>CAN_SHIFT_CLASS) == CAN_ACT){// FIXME ett jŠkla herk, stŠda upp
189
            if ( ((rxMsg.Id & CAN_MASK_CLASS)>>CAN_SHIFT_CLASS) == CAN_SNS){// FIXME ett jŠkla herk, stŠda upp
185
               
190
           
-
 
191
                sns_type = (uint16_t)((rxMsg.Id & CAN_MASK_SNS_TYPE) >> CAN_SHIFT_SNS_TYPE);
-
 
192
                snsid = (uint8_t)((rxMsg.Id & CAN_MASK_SNS_ID) >> CAN_SHIFT_SNS_ID);
186
               
193
               
187
                act_type =(uint16_t)((rxMsg.Id & CAN_MASK_ACT_TYPE) >> CAN_SHIFT_ACT_TYPE);
-
 
188
           
194
               
-
 
195
                if (sns_type == SNS_TYPE_PRESSURE) {
-
 
196
                    sensor_Boost = rxMsg.Data.bytes[0]*256 + rxMsg.Data.bytes[1];
189
                lcdid = (uint8_t)((rxMsg.Id & CAN_MASK_ACT_ID) >> CAN_SHIFT_ACT_ID);               
197
                    if (currentScreen == SCR_BOOST) updateDisplay(SCR_BOOST,0);
190
 
198
                }
191
 
199
 
192
            }
200
            }
193
            rxMsgFull = 0;
201
            rxMsgFull = 0;
194
        }
202
        }
195
    }
203
    }
196
}
204
}
197
 
205
 
198
void send_dimensions(){
206
void send_dimensions(){
199
    Can_Message_t txMsg;
207
    Can_Message_t txMsg;
Line 223... Line 231...
223
    }
231
    }
224
    if (type == BUTTON_PUSH){
232
    if (type == BUTTON_PUSH){
225
 
233
 
226
    }
234
    }
227
    if (type == BUTTON_RELEASE){
235
    if (type == BUTTON_RELEASE){
228
 
236
 
229
    }
237
    }
230
}
238
}
231
 
239
 
232
void updateDisplay(uint8_t screen, uint8_t transition){
240
void updateDisplay(uint8_t screen, uint8_t transition){
233
    char buffer[10];   
241
    char buffer[20];   
234
   
242
   
235
    if (transition){
243
    if (transition){
236
        lcd_clrscr();
244
        lcd_clrscr();
-
 
245
        lcd_setanimation(0);
-
 
246
    } else {
-
 
247
        lcd_setanimation(0);
237
    }
248
    }
238
    switch (screen){
249
    switch (screen){
239
    case SCR_LAMBDA:
250
    case SCR_LAMBDA:
240
        lcd_gotoxy(0,0);
251
        lcd_gotoxy(0,0);
241
        lcd_puts("LEAN Lambda RICH");
252
        lcd_puts("LEAN Lambda RICH");
242
        lcd_gotoxy(0,1);
253
        lcd_gotoxy(0,1);
243
        lcdProgressBar(sensor_Lambda, 255, 16); //TODO: vacker bargraph med bara en plupp i mitten
254
        lcdProgressBar(sensor_Lambda, 255, 16); //TODO: vacker bargraph med bara en plupp i mitten
244
    break;
255
    break;
245
    case SCR_RPM:      
256
    case SCR_RPM:      
246
        lcd_gotoxy(0,0);
257
        lcd_gotoxy(0,0);
247
        itoa(sensor_RPM,buffer,10);
258
        itoa(sensor_RPM,buffer,10);
248
        lcd_puts("RPM: ");
259
        lcd_puts("RPM: ");
249
        lcd_puts(buffer);
260
        lcd_puts(buffer);
Line 254... Line 265...
254
           
265
           
255
        lcd_gotoxy(0,0);
266
        lcd_gotoxy(0,0);
256
        lcd_puts("Boost:");
267
        lcd_puts("Boost:");
257
   
268
   
258
        lcd_gotoxy(7,0);
269
        lcd_gotoxy(7,0);
259
        lcd_puts(io_s16toStr(((int32_t)sensor_Boost*scale_Boost)>>10,buffer,2,1));
270
        //lcd_puts(io_s16toStr(((int32_t)sensor_Boost*scale_Boost)>>10,buffer,2,1));
-
 
271
        rattoascii(sensor_Boost,6,buffer);
-
 
272
        lcd_puts(buffer);
260
   
273
       
261
        lcd_gotoxy(13,0);
274
        //lcd_gotoxy(13,0);
262
        lcd_puts("bar");
275
        lcd_puts(" bar");
263
       
276
       
264
        lcd_gotoxy(0,1);
277
        lcd_gotoxy(0,1);
265
        lcdProgressBar(max(0,sensor_Boost), ((int32_t)scale_BoostMAX)>>10, 16);
278
        lcdProgressBar(max(0,sensor_Boost), scale_BoostMAX, 16);
266
    break;
279
    break;
267
    case SCR_MAXBOOST:
280
    case SCR_MAXBOOST: //currently just a testscreen ffs omg
268
        lcd_gotoxy(0,0);
281
        lcd_gotoxy(0,0);
269
        lcd_puts("Max Boost: ");
282
        lcd_puts("Max Boost: ");
270
        lcd_gotoxy(11,0);
283
        lcd_gotoxy(11,0);
-
 
284
        lcd_gotoxy(0,1);
271
        lcd_puts(io_s16toStr(((int32_t)sensor_Boost_Max*scale_Boost)>>10,buffer,2,1));     
285
        rattoascii(0x0001,6,buffer);
-
 
286
        lcd_puts(buffer);
272
    break;
287
    break;
273
    case SCR_VOLTAGE:
288
    case SCR_VOLTAGE:
274
 
289
 
275
        lcd_gotoxy(0,0);
290
        lcd_gotoxy(0,0);
276
        lcd_puts("Voltage:");
291
        lcd_puts("Voltage:");
277
       
292
       
278
        lcd_gotoxy(9,0);
293
        lcd_gotoxy(9,0);
279
        lcd_puts(io_u16toStr(((uint32_t)sensor_Voltage*scale_Voltage)>>10,buffer,1,0));
294
        //lcd_puts(io_u16toStr(((uint32_t)sensor_Voltage*scale_Voltage)>>10,buffer,1,0));
280
       
295
       
281
        lcd_gotoxy(16,0);
296
        lcd_gotoxy(14,0);
282
        lcd_puts("V");     
297
        lcd_puts("V");     
283
        lcd_puts("spanning!");
298
        lcd_puts("spanning!");
284
       
299
       
285
        lcd_gotoxy(0,1);
300
        lcd_gotoxy(0,1);
286
        lcdProgressBar(sensor_Voltage, scale_VoltageMAX, 16);
301
        lcdProgressBar(sensor_Voltage, scale_VoltageMAX, 16);
287
    break;
302
    break;
288
    }
303
    }
289
}
304
}
290
 
305
 
Line 295... Line 310...
295
    lcd_puts(text);
310
    lcd_puts(text);
296
    lcd_puts(" ");
311
    lcd_puts(" ");
297
    lcd_puts(buffer);
312
    lcd_puts(buffer);
298
    lcd_gotoxy(0,1);
313
    lcd_gotoxy(0,1);
299
    lcdProgressBar(value, maxvalue, 16);
314
    lcdProgressBar(value, maxvalue, 16);
300
}
315
}
301
 
316
 
302
 
317
 
303
 
318
 
304
 
319
 
305
 
320
 
306
 
321
 
307
 
322
 
308
 
323
 
309
 
324
 
310
 
325
 
311
 
326
 
312
 
327
 
313
 
328
 
314
 
329
 
Line 369... Line 384...
369
 
384
 
370
 
385
 
371
 
386
 
372
 
387
 
373
 
388
 
-
 
389
 
-
 
390
 
-
 
391
 
-
 
392
//‡ la pengi
-
 
393
void numtoascii( int16_t num, char **str ) {
-
 
394
    if( num==0 ) return;
-
 
395
    numtoascii( num/10, str );
-
 
396
    **str = '0' + (num%10);
-
 
397
    (*str)++;
-
 
398
}
-
 
399
 
-
 
400
void rattoascii( int16_t num, uint8_t decimalplace, char *string){ //decimalplace is number of decimals
-
 
401
    uint8_t i;
-
 
402
#define ANTAL_NUFFROR 3
-
 
403
    if( num<0 ) {
-
 
404
        *(string++) = '-';
-
 
405
        num = -num;
-
 
406
    }
-
 
407
    numtoascii(num>>decimalplace, &string );
-
 
408
    *(string++) = '.';
-
 
409
    for(i=0;i<ANTAL_NUFFROR;i++) {
-
 
410
        num %= 1<<decimalplace;
-
 
411
        num *= 10;
-
 
412
        *(string++) = '0' + (num>>decimalplace);
-
 
413
    }
-
 
414
    *(string++) = 0;
-
 
415
}
374
 
416
 
375
 
417
 
376
//Supersnodd:
418
//Supersnodd:
377
 
419
 
378
 
420
 
379
 
421
 
380
uint8_t _io_buf[10];
422
uint8_t _io_buf[10];
-
 
423
 
-
 
424
 
-
 
425
/*
-
 
426
uint8_t *parsetemperature(int16_t value,uint8_t *str,uint8_t decimal,uint8_t options){
-
 
427
    uint16_t tmp;
-
 
428
    uint8_t i=0;
-
 
429
   
-
 
430
    //value = 0xfcf4;
-
 
431
    //decimal = 6;
-
 
432
   
-
 
433
    if(value<0) {
-
 
434
        str[i++]='-'; //add negative sign
-
 
435
        tmp=-value>>decimal;
-
 
436
    } else {
-
 
437
        if(options&0x01) str[i++]=' '; //Can the number be negative? Leave space for minussign
-
 
438
        tmp=value>>decimal;
-
 
439
    }  
-
 
440
   
-
 
441
    //Let's start axing up the value to print it beautifully. We have tmp, the integer part of the value
-
 
442
    while(tmp>0) {
-
 
443
        str[i++]='0' + (tmp%10);
-
 
444
        tmp=tmp/10;
-
 
445
    }  
-
 
446
   
-
 
447
    //now we hafve printed all of zat
-
 
448
    str[i++] = '.';
-
 
449
   
-
 
450
    //let's go on to the fractional part... (cwap!)
-
 
451
   
-
 
452
   
-
 
453
    str[i++]=0;
-
 
454
    return(str);
-
 
455
}
-
 
456
*/
381
 
457
 
-
 
458
// nŒn annans rutin som jag inte riktigt fšrstŒr mig pŒ.
382
uint8_t *io_s16toStr(int16_t value,uint8_t *str,uint8_t decimal,uint8_t options) {
459
uint8_t *io_s16toStr(int16_t value,uint8_t *str,uint8_t decimal,uint8_t options) {
383
    uint8_t i=0,j=0,w=0;
460
    uint8_t i=0,j=0,w=0;
384
    uint16_t tmp;
461
    uint16_t tmp;
385
   
462
   
386
    if(value<0) {
463
    if(value<0) {