Rev 647 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 647 | Rev 653 | ||
|---|---|---|---|
| 1 | /** |
1 | /** |
| 2 | * CanCarDisplay. HID for simple carsensor network |
2 | * CanCarDisplay. HID for simple carsensor network |
| 3 | * For HD44780- and KS0073-based LCD displays |
3 | * For HD44780- and KS0073-based LCD displays |
| 4 | * |
4 | * |
| 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. |
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 |
11 | * Assume all sensor conversion done on the sensorcard, use canstandard here |
| 12 | */ |
12 | */ |
| 13 | 13 | ||
| 14 | /*----------------------------------------------------------------------------- |
14 | /*----------------------------------------------------------------------------- |
| 15 | * Includes |
15 | * Includes |
| 16 | *---------------------------------------------------------------------------*/ |
16 | *---------------------------------------------------------------------------*/ |
| 17 | /* system files */ |
17 | /* system files */ |
| 18 | #include <avr/io.h> |
18 | #include <avr/io.h> |
| 19 | #include <inttypes.h> |
19 | #include <inttypes.h> |
| 20 | #include <avr/interrupt.h> |
20 | #include <avr/interrupt.h> |
| 21 | #include <stdio.h> |
21 | #include <stdio.h> |
| 22 | /* lib files */ |
22 | /* lib files */ |
| 23 | #include <bios.h> |
23 | #include <bios.h> |
| 24 | #include <config.h> |
24 | #include <config.h> |
| 25 | #include <drivers/lcd/clcd/lcd_HD44780.h> |
25 | #include <drivers/lcd/clcd/lcd_HD44780.h> |
| 26 | #include <stdlib.h> //for itoa |
26 | #include <stdlib.h> //for itoa |
| 27 | 27 | ||
| 28 | #include <string.h> //for memcpy |
28 | #include <string.h> //for memcpy |
| 29 | 29 | ||
| 30 | 30 | ||
| 31 | /* <SIZE> 8 bits 0xFFL */ |
31 | /* <SIZE> 8 bits 0xFFL */ |
| 32 | #define LCD_SIZE_ALL 0x00L |
32 | #define LCD_SIZE_ALL 0x00L |
| 33 | #define LCD_SIZE_16x2 0x02L |
33 | #define LCD_SIZE_16x2 0x02L |
| 34 | #define LCD_SIZE_20x4 0x10L |
34 | #define LCD_SIZE_20x4 0x10L |
| 35 | 35 | ||
| 36 | 36 | ||
| 37 | //Borde ha en bttre plats. |
37 | //Borde ha en bttre plats. |
| 38 | #define max(a,b) ((a>b)?a:b) |
38 | #define max(a,b) ((a>b)?a:b) |
| 39 | #define min(a,b) ((a<b)?a:b) |
39 | #define min(a,b) ((a<b)?a:b) |
| 40 | 40 | ||
| 41 | 41 | ||
| 42 | /*----------------------------------------------------------------------------- |
42 | /*----------------------------------------------------------------------------- |
| 43 | * Defines |
43 | * Defines |
| 44 | *---------------------------------------------------------------------------*/ |
44 | *---------------------------------------------------------------------------*/ |
| 45 | #define SIZE_X 20 |
45 | #define SIZE_X 20 |
| 46 | #define SIZE_Y 4 |
46 | #define SIZE_Y 4 |
| 47 | #define SIZE_LCD LCD_SIZE_20x4 |
47 | #define SIZE_LCD LCD_SIZE_20x4 |
| 48 | 48 | ||
| 49 | #define BUFFER_SIZE SIZE_X |
49 | #define BUFFER_SIZE SIZE_X |
| 50 | #define TRUE 1 |
50 | #define TRUE 1 |
| 51 | #define FALSE 0 |
51 | #define FALSE 0 |
| 52 | 52 | ||
| 53 | #define LEFT 0x01 |
53 | #define LEFT 0x01 |
| 54 | #define RIGHT 0x02 |
54 | #define RIGHT 0x02 |
| 55 | #define BUTTON_PUSH 0x03 |
55 | #define BUTTON_PUSH 0x03 |
| 56 | #define BUTTON_RELEASE 0x04 |
56 | #define BUTTON_RELEASE 0x04 |
| 57 | 57 | ||
| 58 | volatile Can_Message_t rxMsg; |
58 | volatile Can_Message_t rxMsg; |
| 59 | 59 | ||
| 60 | char incoming_text[ BUFFER_SIZE ]; |
60 | char incoming_text[ BUFFER_SIZE ]; |
| 61 | uint8_t rxMsgFull; |
61 | uint8_t rxMsgFull; |
| 62 | 62 | ||
| 63 | 63 | ||
| 64 | char buffer[ BUFFER_SIZE ]; |
64 | char buffer[ BUFFER_SIZE ]; |
| 65 | 65 | ||
| 66 | void send_dimensions(void); |
66 | void send_dimensions(void); |
| 67 | void rotenc(void); |
67 | void rotenc(void); |
| 68 | void rotenc_action(uint8_t type); |
68 | void rotenc_action(uint8_t type); |
| 69 | 69 | ||
| 70 | 70 | ||
| 71 | void updateDisplay(uint8_t screen, uint8_t transition); |
71 | void updateDisplay(uint8_t screen, uint8_t transition); |
| 72 | 72 | ||
| 73 | #define |
73 | #define SCR_BOOST 0x00 |
| 74 | #define |
74 | #define SCR_MAXBOOST 0x01 |
| 75 | #define |
75 | #define SCR_LAMBDA 0x02 |
| 76 | #define SCR_RPM 0x03 |
76 | #define SCR_RPM 0x03 |
| 77 | #define SCR_VOLTAGE 0x04 |
77 | #define SCR_VOLTAGE 0x04 |
| - | 78 | #define SCR_VELOCITY 0x05 |
|
| - | 79 | #define SCR_FUELCONS 0x06 |
|
| - | 80 | //#define SCR_OILPRESS 0x07 |
|
| - | 81 | //#define SCR_OILTEMP 0x08 |
|
| 78 | #define LAST_SCREEN |
82 | #define LAST_SCREEN 0x06 |
| 79 | void standardScreen(char* text, uint16_t value, uint16_t maxvalue); |
- | |
| 80 | 83 | ||
| 81 | void numtoascii( int16_t num, char **str ); |
84 | void numtoascii( int16_t num, char **str ); |
| 82 | void |
85 | void signedtoascii(int16_t num, uint8_t decimalplace, char *string, uint8_t numberofdecimals); |
| - | 86 | void unsignedtoascii(uint16_t num, uint8_t decimalplace, char *string, uint8_t numberofdecimals); |
|
| 83 | 87 | ||
| 84 | uint8_t *parsetemperature(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); |
- | |
| 86 | uint8_t *io_u16toStr(uint16_t value, uint8_t *str,uint8_t decimal,uint8_t options); |
- | |
| 87 | 88 | ||
| 88 | 89 | ||
| 89 | - | ||
| 90 | /******************************************************************************* |
90 | /******************************************************************************* |
| 91 | * Sensor Values, Scale factors etc. * |
91 | * Sensor Values, Scale factors etc. * |
| 92 | *******************************************************************************/ |
92 | *******************************************************************************/ |
| 93 | int16_t |
93 | int16_t sensor_Boost = 0.001*64; |
| 94 | int16_t sensor_Boost_Max |
94 | int16_t sensor_Boost_Max = 0.92*64; //highest boost so far |
| - | 95 | uint16_t sensor_Lambda = 32000; |
|
| - | 96 | uint16_t sensor_RPM = 3973*(2<<(SNS_DECPOINT_ROTSPEED-1)); |
|
| - | 97 | uint16_t sensor_Voltage = 12.7*(2<<(SNS_DECPOINT_VOLTAGE-1)); |
|
| - | 98 | uint16_t sensor_Velocity = 120*(2<<(SNS_DECPOINT_VELOCITY-1)); |
|
| - | 99 | uint16_t sensor_Fuelcons = 0.78*(2<<(SNS_DECPOINT_FUELCONS-1)); |
|
| 95 | 100 | ||
| - | 101 | #define SCALE_BOOSTMAX 1.2*64 //depending on memory usage later, maybe put these in eeprom? |
|
| 96 |
|
102 | #define SCALE_LAMBDAMAX 65535 |
| 97 |
|
103 | #define SCALE_RPMMAX 8000*(2<<(SNS_DECPOINT_ROTSPEED-1)) |
| 98 |
|
104 | #define SCALE_VOLTAGEMAX 15*(2<<(SNS_DECPOINT_VOLTAGE-1)) |
| - | 105 | #define SCALE_VELOCITYMAX 150*(2<<(SNS_DECPOINT_VELOCITY-1)) |
|
| - | 106 | #define SCALE_FUELCONSMAX 2*(2<<(SNS_DECPOINT_FUELCONS-1)) |
|
| - | 107 | ||
| 99 | 108 | ||
| 100 | #define scale_Boost 200 //see "Representation av storheter" |
- | |
| 101 | #define scale_BoostMAX 200 |
- | |
| 102 | #define scale_RPMMAX 8000 //Can be set as in eeprom later perhaps? |
- | |
| 103 | #define scale_Voltage 1024 |
- | |
| 104 | #define scale_VoltageMAX 150 |
- | |
| 105 | 109 | ||
| - | 110 | /******************************************************************************* |
|
| - | 111 | * Something else.. * |
|
| - | 112 | *******************************************************************************/ |
|
| 106 | 113 | ||
| 107 | uint8_t currentScreen; |
114 | uint8_t currentScreen; //current screen |
| 108 | 115 | ||
| 109 | // CAN message reception callback |
116 | // CAN message reception callback |
| 110 | // This function runs with interrupts disabled, keep it as short as possible |
117 | // This function runs with interrupts disabled, keep it as short as possible |
| 111 | void can_receive(Can_Message_t *msg){ |
118 | void can_receive(Can_Message_t *msg){ |
| 112 | if(!rxMsgFull){ |
119 | if(!rxMsgFull){ |
| 113 | memcpy((void*)&rxMsg, msg, sizeof(rxMsg)); |
120 | memcpy((void*)&rxMsg, msg, sizeof(rxMsg)); |
| 114 | rxMsgFull = 1; |
121 | rxMsgFull = 1; |
| 115 | } |
122 | } |
| 116 | } |
123 | } |
| 117 | 124 | ||
| 118 | ISR( PCINT2_vect ){ |
125 | ISR( PCINT2_vect ){ |
| 119 | // For ROTENC_A and ROTENC_B FIXME r inte riktigt rtt. Verkar vara bra tycker jag? |
126 | // For ROTENC_A and ROTENC_B FIXME r inte riktigt rtt. Verkar vara bra tycker jag? |
| 120 | rotenc(); |
127 | rotenc(); |
| 121 | } |
128 | } |
| 122 | 129 | ||
| 123 | ISR( PCINT0_vect ){ |
130 | ISR( PCINT0_vect ){ |
| 124 | // For ROTENC_BTN |
131 | // For ROTENC_BTN |
| 125 | rotenc(); |
132 | rotenc(); |
| 126 | } |
133 | } |
| 127 | 134 | ||
| 128 | /*----------------------------------------------------------------------------- |
135 | /*----------------------------------------------------------------------------- |
| 129 | * Main Program |
136 | * Main Program |
| 130 | *---------------------------------------------------------------------------*/ |
137 | *---------------------------------------------------------------------------*/ |
| 131 | int main(void) { |
138 | int main(void) { |
| 132 | currentScreen = 0; //init display position |
139 | currentScreen = 0; //init display position |
| 133 | 140 | ||
| 134 | // uint32_t act; not used anymoer |
141 | // uint32_t act; not used anymoer |
| 135 | // uint8_t act_type, lcd_size; not used anymore |
142 | // uint8_t act_type, lcd_size; not used anymore |
| 136 | //uint8_t m, lcd_action; |
143 | //uint8_t m, lcd_action; |
| 137 | 144 | ||
| 138 | sei(); |
145 | sei(); |
| 139 | 146 | ||
| 140 | /* |
147 | /* |
| 141 | * Initialize rotaryencoders and buttons |
148 | * Initialize rotaryencoders and buttons |
| 142 | */ |
149 | */ |
| 143 | // Set as input |
150 | // Set as input |
| 144 | DDRD &= ~(1<<DDD2); |
151 | DDRD &= ~(1<<DDD2); |
| 145 | DDRB &= ~((1<<DDB7)|(1<<DDB0)); |
152 | DDRB &= ~((1<<DDB7)|(1<<DDB0)); |
| 146 | // Enable pull-up |
153 | // Enable pull-up |
| 147 | PORTD |= (1<<PD2); |
154 | PORTD |= (1<<PD2); |
| 148 | PORTB |= (1<<PB7)|(1<<PB0); |
155 | PORTB |= (1<<PB7)|(1<<PB0); |
| 149 | // Enable IO-pin interrupt |
156 | // Enable IO-pin interrupt |
| 150 | PCICR |= (1<<PCIE2)|(1<<PCIE0); |
157 | PCICR |= (1<<PCIE2)|(1<<PCIE0); |
| 151 | // Unmask PB7, PB0 and PD2 |
158 | // Unmask PB7, PB0 and PD2 |
| 152 | PCMSK2 |= (1<<PCINT18); |
159 | PCMSK2 |= (1<<PCINT18); |
| 153 | PCMSK0 |= (1<<PCINT7)|(1<<PCINT0); |
160 | PCMSK0 |= (1<<PCINT7)|(1<<PCINT0); |
| 154 | 161 | ||
| 155 | // Contrast |
162 | // Contrast |
| 156 | TCCR0A |= (1<<COM0B1)|(1<<WGM01)|(1<<WGM00); |
163 | TCCR0A |= (1<<COM0B1)|(1<<WGM01)|(1<<WGM00); |
| 157 | TCCR0B |= (1<<CS00); |
164 | TCCR0B |= (1<<CS00); |
| 158 | OCR0B = 0x10; |
165 | OCR0B = 0x10; |
| 159 | DDRD |= (1<<DDD5); |
166 | DDRD |= (1<<DDD5); |
| 160 | 167 | ||
| 161 | // Backlight |
168 | // Backlight |
| 162 | TCCR1A |= (1<<COM1A1)|(1<<WGM11); |
169 | TCCR1A |= (1<<COM1A1)|(1<<WGM11); |
| 163 | TCCR1B |= (1<<WGM13)|(1<<WGM12)|(1<<CS10); |
170 | TCCR1B |= (1<<WGM13)|(1<<WGM12)|(1<<CS10); |
| 164 | ICR1 = 0xFF; // Make it 8 bits |
171 | ICR1 = 0xFF; // Make it 8 bits |
| 165 | OCR1A = 0xFF; |
172 | OCR1A = 0xFF; |
| 166 | DDRB |= (1<<DDB1); |
173 | DDRB |= (1<<DDB1); |
| 167 | 174 | ||
| 168 | 175 | ||
| 169 | Can_Message_t txMsg; |
176 | Can_Message_t txMsg; |
| 170 | txMsg.ExtendedFlag=1; |
177 | txMsg.ExtendedFlag=1; |
| 171 | txMsg.RemoteFlag=0; |
178 | txMsg.RemoteFlag=0; |
| 172 | // FIXME skicka app startad |
179 | // FIXME skicka app startad |
| 173 | BIOS_CanCallback = &can_receive; |
180 | BIOS_CanCallback = &can_receive; |
| 174 | 181 | ||
| 175 | lcd_init( LCD_DISP_ON ); |
182 | lcd_init( LCD_DISP_ON ); |
| 176 | lcd_clrscr(); |
183 | lcd_clrscr(); |
| 177 | lcd_puts("CarDisplay"); |
184 | lcd_puts("CarDisplay"); |
| 178 | 185 | ||
| 179 | send_dimensions(); |
186 | send_dimensions(); |
| 180 | lcd_gotoxy(0,1); |
187 | lcd_gotoxy(0,1); |
| 181 | lcd_puts("CAN Connected!"); |
188 | lcd_puts("CAN Connected!"); |
| 182 | 189 | ||
| 183 | /* main loop */ |
190 | /* main loop */ |
| 184 | while(1){ |
191 | while(1){ |
| 185 | /* check if any messages have been received */ |
192 | /* check if any messages have been received */ |
| 186 | if(rxMsgFull){ |
193 | if(rxMsgFull){ |
| 187 | uint16_t sns_type; |
194 | uint16_t sns_type; |
| 188 | uint8_t snsid; |
195 | uint8_t snsid; |
| 189 | if ( ((rxMsg.Id & CAN_MASK_CLASS)>>CAN_SHIFT_CLASS) == CAN_SNS){// FIXME ett jkla herk, stda upp |
196 | if ( ((rxMsg.Id & CAN_MASK_CLASS)>>CAN_SHIFT_CLASS) == CAN_SNS){// FIXME ett jkla herk, stda upp |
| 190 | 197 | ||
| 191 | sns_type = (uint16_t)((rxMsg.Id & CAN_MASK_SNS_TYPE) >> CAN_SHIFT_SNS_TYPE); |
198 | 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); |
199 | snsid = (uint8_t)((rxMsg.Id & CAN_MASK_SNS_ID) >> CAN_SHIFT_SNS_ID); |
| 193 | 200 | ||
| 194 | 201 | switch(sns_type){ |
|
| 195 |
|
202 | case SNS_TYPE_PRESSURE: |
| 196 | sensor_Boost = rxMsg.Data.bytes[0]*256 + rxMsg.Data.bytes[1]; |
203 | sensor_Boost = rxMsg.Data.bytes[0]*256 + rxMsg.Data.bytes[1]; |
| - | 204 | sensor_Boost_Max = max(sensor_Boost,sensor_Boost_Max); |
|
| 197 | if (currentScreen == SCR_BOOST) updateDisplay(SCR_BOOST,0); |
205 | if (currentScreen == SCR_BOOST) updateDisplay(SCR_BOOST,0); |
| - | 206 | break; |
|
| - | 207 | case SNS_TYPE_ROTSPEED: |
|
| - | 208 | sensor_RPM = rxMsg.Data.bytes[0]*256 + rxMsg.Data.bytes[1]; |
|
| - | 209 | if (currentScreen == SCR_RPM) updateDisplay(SCR_RPM,0); |
|
| - | 210 | break; |
|
| - | 211 | case SNS_TYPE_VOLTAGE: |
|
| - | 212 | sensor_Voltage = rxMsg.Data.bytes[0]*256 + rxMsg.Data.bytes[1]; |
|
| - | 213 | if (currentScreen == SCR_VOLTAGE) updateDisplay(SCR_VOLTAGE,0); |
|
| 198 | } |
214 | } |
| 199 | 215 | ||
| 200 | } |
216 | } |
| 201 | rxMsgFull = 0; |
217 | rxMsgFull = 0; |
| 202 | } |
218 | } |
| 203 | } |
219 | } |
| 204 | } |
220 | } |
| 205 | 221 | ||
| 206 | void send_dimensions(){ |
222 | void send_dimensions(){ |
| 207 | Can_Message_t txMsg; |
223 | Can_Message_t txMsg; |
| 208 | 224 | ||
| 209 | txMsg.ExtendedFlag=1; |
225 | txMsg.ExtendedFlag=1; |
| 210 | txMsg.RemoteFlag=0; |
226 | txMsg.RemoteFlag=0; |
| 211 | txMsg.Id=0xA000001; |
227 | txMsg.Id=0xA000001; |
| 212 | txMsg.Data.bytes[0] = SIZE_X; |
228 | txMsg.Data.bytes[0] = SIZE_X; |
| 213 | txMsg.Data.bytes[1] = SIZE_Y; |
229 | txMsg.Data.bytes[1] = SIZE_Y; |
| 214 | txMsg.DataLength = 2; |
230 | txMsg.DataLength = 2; |
| 215 | 231 | ||
| 216 | BIOS_CanSend(&txMsg); |
232 | BIOS_CanSend(&txMsg); |
| 217 | } |
233 | } |
| 218 | 234 | ||
| 219 | void rotenc_action(uint8_t type){ |
235 | void rotenc_action(uint8_t type){ |
| 220 | //Let's do something with something! |
236 | //Let's do something with something! |
| 221 |
|
237 | |
| 222 | if (type == LEFT){ |
238 | if (type == LEFT){ |
| 223 | if (currentScreen == 0) currentScreen = LAST_SCREEN+1; |
239 | if (currentScreen == 0) currentScreen = LAST_SCREEN+1; |
| 224 | currentScreen--; |
240 | currentScreen--; |
| 225 | updateDisplay(currentScreen,1); |
241 | updateDisplay(currentScreen,1); |
| 226 | } |
242 | } |
| 227 | if (type == RIGHT){ |
243 | if (type == RIGHT){ |
| 228 | currentScreen++; |
244 | currentScreen++; |
| 229 | if (currentScreen > LAST_SCREEN) currentScreen = 0; |
245 | if (currentScreen > LAST_SCREEN) currentScreen = 0; |
| 230 | updateDisplay(currentScreen,1); |
246 | updateDisplay(currentScreen,1); |
| 231 | } |
247 | } |
| 232 | if (type == BUTTON_PUSH){ |
248 | if (type == BUTTON_PUSH){ |
| 233 | 249 | ||
| 234 | } |
250 | } |
| 235 | if (type == BUTTON_RELEASE){ |
251 | if (type == BUTTON_RELEASE){ |
| 236 | 252 | ||
| 237 | } |
253 | } |
| 238 | } |
254 | } |
| 239 | 255 | ||
| 240 | void updateDisplay(uint8_t screen, uint8_t transition){ |
256 | void updateDisplay(uint8_t screen, uint8_t transition){ |
| 241 | char buffer[20]; |
257 | char buffer[20]; |
| 242 | 258 | ||
| 243 | if (transition){ |
259 | if (transition){ |
| 244 | lcd_clrscr(); |
260 | lcd_clrscr(); |
| 245 | lcd_setanimation( |
261 | lcd_setanimation(1); |
| 246 | } else { |
262 | } else { |
| 247 | lcd_setanimation(0); |
263 | lcd_setanimation(0); |
| 248 | } |
264 | } |
| 249 | switch (screen){ |
265 | switch (screen){ |
| 250 | case SCR_LAMBDA: |
266 | case SCR_LAMBDA: |
| 251 | lcd_gotoxy(0,0); |
267 | lcd_gotoxy(0,0); |
| 252 | lcd_puts("LEAN Lambda RICH"); |
268 | lcd_puts("LEAN Lambda RICH"); |
| 253 | lcd_gotoxy(0,1); |
269 | lcd_gotoxy(0,1); |
| 254 | lcdProgressBar(sensor_Lambda, |
270 | lcdProgressBar(sensor_Lambda, SCALE_LAMBDAMAX, SIZE_X); //TODO: vacker bargraph med bara en plupp i mitten |
| 255 | break; |
271 | break; |
| 256 | case SCR_RPM: |
272 | case SCR_RPM: |
| 257 | lcd_gotoxy(0,0); |
273 | lcd_gotoxy(0,0); |
| 258 | itoa(sensor_RPM,buffer,10); |
- | |
| 259 | lcd_puts("RPM: "); |
274 | lcd_puts("RPM: "); |
| - | 275 | unsignedtoascii(sensor_RPM,SNS_DECPOINT_ROTSPEED,buffer,0); |
|
| 260 | lcd_puts(buffer); |
276 | lcd_puts(buffer); |
| 261 | lcd_gotoxy(0,1); |
277 | lcd_gotoxy(0,1); |
| 262 | lcdProgressBar(sensor_RPM, |
278 | lcdProgressBar(sensor_RPM, SCALE_RPMMAX, SIZE_X); |
| 263 | break; |
279 | break; |
| 264 | case SCR_BOOST: |
280 | case SCR_BOOST: |
| 265 | - | ||
| 266 | lcd_gotoxy(0,0); |
281 | lcd_gotoxy(0,0); |
| 267 | lcd_puts("Boost:"); |
282 | lcd_puts("Boost: "); |
| 268 | - | ||
| 269 | lcd_gotoxy(7,0); |
- | |
| 270 | //lcd_puts(io_s16toStr(((int32_t)sensor_Boost*scale_Boost)>>10,buffer,2,1)); |
- | |
| 271 |
|
283 | signedtoascii(sensor_Boost,SNS_DECPOINT_PRESSURE,buffer,2); |
| 272 | lcd_puts(buffer); |
284 | lcd_puts(buffer); |
| - | 285 | lcd_puts(" bar "); |
|
| 273 | 286 | ||
| 274 | //lcd_gotoxy(13,0); |
- | |
| 275 | lcd_puts(" bar"); |
- | |
| 276 | - | ||
| 277 | lcd_gotoxy(0,1); |
287 | lcd_gotoxy(0,1); |
| 278 | lcdProgressBar(max(0,sensor_Boost), |
288 | lcdProgressBar(max(0,sensor_Boost), SCALE_BOOSTMAX, SIZE_X); |
| 279 | break; |
289 | break; |
| 280 | case SCR_MAXBOOST: //currently just a testscreen ffs omg |
290 | case SCR_MAXBOOST: //currently just a testscreen ffs omg |
| 281 | lcd_gotoxy(0,0); |
291 | lcd_gotoxy(0,0); |
| 282 | lcd_puts("Max Boost: "); |
292 | lcd_puts("Max Boost: "); |
| 283 | lcd_gotoxy(11,0); |
- | |
| 284 | lcd_gotoxy(0,1); |
- | |
| 285 |
|
293 | signedtoascii(sensor_Boost_Max ,SNS_DECPOINT_PRESSURE,buffer,2); |
| 286 | lcd_puts(buffer); |
294 | lcd_puts(buffer); |
| - | 295 | lcd_puts(" bar"); |
|
| 287 | break; |
296 | break; |
| 288 | case SCR_VOLTAGE: |
297 | case SCR_VOLTAGE: |
| 289 | - | ||
| 290 | lcd_gotoxy(0,0); |
298 | lcd_gotoxy(0,0); |
| 291 | lcd_puts("Voltage:"); |
299 | lcd_puts("Voltage: "); |
| 292 | - | ||
| 293 | lcd_gotoxy(9,0); |
- | |
| 294 |
|
300 | unsignedtoascii(sensor_Voltage,SNS_DECPOINT_VOLTAGE,buffer,2); |
| 295 | - | ||
| 296 |
|
301 | lcd_puts(buffer); |
| 297 | lcd_puts("V"); |
302 | lcd_puts(" V"); |
| 298 | lcd_puts("spanning!"); |
- | |
| 299 | - | ||
| 300 | lcd_gotoxy(0,1); |
303 | lcd_gotoxy(0,1); |
| 301 | lcdProgressBar(sensor_Voltage, |
304 | lcdProgressBar(max(0,sensor_Voltage), SCALE_VOLTAGEMAX, SIZE_X); |
| 302 | break; |
305 | break; |
| 303 | } |
- | |
| 304 | } |
- | |
| 305 | - | ||
| 306 |
|
306 | case SCR_FUELCONS: |
| 307 | lcd_gotoxy(0,0); |
307 | lcd_gotoxy(0,0); |
| - | 308 | lcd_puts("Fuel: "); |
|
| - | 309 | unsignedtoascii(sensor_Fuelcons,SNS_DECPOINT_FUELCONS,buffer,2); |
|
| 308 |
|
310 | lcd_puts(buffer); |
| - | 311 | lcd_puts(" L/10km"); |
|
| 309 |
|
312 | lcd_gotoxy(0,1); |
| - | 313 | lcdProgressBar(max(0,sensor_Fuelcons), SCALE_FUELCONSMAX, SIZE_X); |
|
| - | 314 | break; |
|
| - | 315 | case SCR_VELOCITY: |
|
| 310 |
|
316 | lcd_gotoxy(0,0); |
| 311 | lcd_puts |
317 | lcd_puts("Speed: "); |
| - | 318 | unsignedtoascii(sensor_Velocity,SNS_DECPOINT_VELOCITY,buffer,0); |
|
| 312 | lcd_puts(buffer); |
319 | lcd_puts(buffer); |
| - | 320 | lcd_puts(" km/h"); |
|
| 313 | lcd_gotoxy(0,1); |
321 | lcd_gotoxy(0,1); |
| 314 | lcdProgressBar |
322 | lcdProgressBar(max(0,sensor_Velocity), SCALE_VELOCITYMAX, SIZE_X); |
| - | 323 | break; |
|
| - | 324 | } |
|
| 315 | } |
325 | } |
| 316 | - | ||
| 317 | - | ||
| 318 | 326 | ||
| 319 | 327 | ||
| 320 | 328 | ||
| 321 | 329 | ||
| 322 | 330 | ||
| 323 | 331 | ||
| 324 | 332 | ||
| 325 | 333 | ||
| 326 | 334 | ||
| 327 | 335 | ||
| 328 | 336 | ||
| 329 | 337 | ||
| 330 | 338 | ||
| 331 | 339 | ||
| 332 | void rotenc(){ |
340 | void rotenc(){ |
| 333 | uint8_t rot_data = 0; |
341 | uint8_t rot_data = 0; |
| 334 | static uint8_t rot_lastdir = 0, rot_laststate = 0, btn_laststate = 0; |
342 | static uint8_t rot_lastdir = 0, rot_laststate = 0, btn_laststate = 0; |
| 335 | 343 | ||
| 336 | Can_Message_t txMsg; |
344 | Can_Message_t txMsg; |
| 337 | txMsg.ExtendedFlag=1; |
345 | txMsg.ExtendedFlag=1; |
| 338 | txMsg.RemoteFlag=0; |
346 | txMsg.RemoteFlag=0; |
| 339 | //txMsg.Id = ( CLASS_SNS<<CLASS_MASK_BITS )|( SNS_ACT_BUTTON<<SNS_TYPE_BITS )|( 0x01<<SNS_ID_BITS )| NODE_ID;//FIXME: borttaget |
347 | //txMsg.Id = ( CLASS_SNS<<CLASS_MASK_BITS )|( SNS_ACT_BUTTON<<SNS_TYPE_BITS )|( 0x01<<SNS_ID_BITS )| NODE_ID;//FIXME: borttaget |
| 340 | txMsg.DataLength=2; |
348 | txMsg.DataLength=2; |
| 341 | 349 | ||
| 342 | //Take care of button push |
350 | //Take care of button push |
| 343 | if ((PINB&(1<<PB7)) != btn_laststate){ //The buttonstate has changed! Let's send a message! |
351 | if ((PINB&(1<<PB7)) != btn_laststate){ //The buttonstate has changed! Let's send a message! |
| 344 | btn_laststate = (PINB&(1<<PB7)); |
352 | btn_laststate = (PINB&(1<<PB7)); |
| 345 | txMsg.Data.bytes[0] = 5; |
353 | txMsg.Data.bytes[0] = 5; |
| 346 | txMsg.Data.bytes[1] = (btn_laststate)?0:1; |
354 | txMsg.Data.bytes[1] = (btn_laststate)?0:1; |
| 347 | txMsg.DataLength=2; |
355 | txMsg.DataLength=2; |
| 348 | BIOS_CanSend(&txMsg); |
356 | BIOS_CanSend(&txMsg); |
| 349 | rotenc_action((btn_laststate)?BUTTON_RELEASE:BUTTON_PUSH); |
357 | rotenc_action((btn_laststate)?BUTTON_RELEASE:BUTTON_PUSH); |
| 350 | } |
358 | } |
| 351 | 359 | ||
| 352 | //Take care of rotary encoder movement |
360 | //Take care of rotary encoder movement |
| 353 | if(PINB&(1<<PB0)){ |
361 | if(PINB&(1<<PB0)){ |
| 354 | rot_data |= 0x01; |
362 | rot_data |= 0x01; |
| 355 | } |
363 | } |
| 356 | if(PIND&(1<<PD2)){ |
364 | if(PIND&(1<<PD2)){ |
| 357 | rot_data |= 0x02; |
365 | rot_data |= 0x02; |
| 358 | } |
366 | } |
| 359 | 367 | ||
| 360 | if( rot_data==0 || rot_data==3 ){ // Are both signals high or low? |
368 | if( rot_data==0 || rot_data==3 ){ // Are both signals high or low? |
| 361 | if( rot_data==0 && rot_laststate!=rot_data ){ // Are both signals low? In that case we are finished with one turn and should print out the direction it went. |
369 | if( rot_data==0 && rot_laststate!=rot_data ){ // Are both signals low? In that case we are finished with one turn and should print out the direction it went. |
| 362 | if( rot_lastdir&0x01 ){ |
370 | if( rot_lastdir&0x01 ){ |
| 363 | // Moving right |
371 | // Moving right |
| 364 | txMsg.Data.bytes[0]=RIGHT; |
372 | txMsg.Data.bytes[0]=RIGHT; |
| 365 | txMsg.Data.bytes[1] = (PINB&(1<<PB7))?0:1; |
373 | txMsg.Data.bytes[1] = (PINB&(1<<PB7))?0:1; |
| 366 | txMsg.DataLength=2; |
374 | txMsg.DataLength=2; |
| 367 | BIOS_CanSend(&txMsg); |
375 | BIOS_CanSend(&txMsg); |
| 368 | rotenc_action(RIGHT); |
376 | rotenc_action(RIGHT); |
| 369 | }else{ |
377 | }else{ |
| 370 | // Moving left |
378 | // Moving left |
| 371 | txMsg.Data.bytes[0]=LEFT; |
379 | txMsg.Data.bytes[0]=LEFT; |
| 372 | txMsg.Data.bytes[1] = (PINB&(1<<PB7))?0:1; |
380 | txMsg.Data.bytes[1] = (PINB&(1<<PB7))?0:1; |
| 373 | txMsg.DataLength=2; |
381 | txMsg.DataLength=2; |
| 374 | BIOS_CanSend(&txMsg); |
382 | BIOS_CanSend(&txMsg); |
| 375 | rotenc_action(LEFT); |
383 | rotenc_action(LEFT); |
| 376 | } |
384 | } |
| 377 | } |
385 | } |
| 378 | rot_laststate = rot_data; |
386 | rot_laststate = rot_data; |
| 379 | } else { // No, only one of the signals are high. We can use this to find out what direction we are moving. |
387 | } else { // No, only one of the signals are high. We can use this to find out what direction we are moving. |
| 380 | rot_lastdir = rot_data; |
388 | rot_lastdir = rot_data; |
| 381 | } |
389 | } |
| 382 | } |
390 | } |
| 383 | 391 | ||
| 384 | 392 | ||
| 385 | 393 | ||
| 386 | - | ||
| 387 | - | ||
| 388 | - | ||
| 389 | - | ||
| 390 | - | ||
| 391 | - | ||
| 392 | // la pengi |
394 | // la pengi. Skall libbifieras. |
| 393 | void numtoascii( int16_t num, char **str ) { |
395 | void numtoascii( int16_t num, char **str ) { |
| 394 | if( num==0 ) return; |
396 | if( num==0 ) return; |
| 395 | numtoascii( num/10, str ); |
397 | numtoascii( num/10, str ); |
| 396 | **str = '0' + (num%10); |
398 | **str = '0' + (num%10); |
| 397 | (*str)++; |
399 | (*str)++; |
| 398 | } |
400 | } |
| 399 | 401 | ||
| 400 | void |
402 | void signedtoascii(int16_t num, uint8_t decimalplace, char *string, uint8_t numberofdecimals){ //decimalplace is number of decimals |
| 401 | uint8_t i; |
403 | uint8_t i; |
| 402 | #define ANTAL_NUFFROR 3 |
- | |
| - | 404 | ||
| 403 | if( num<0 ) { |
405 | if( num<0 ) { |
| 404 | *(string++) = '-'; |
406 | *(string++) = '-'; |
| 405 | num = -num; |
407 | num = -num; |
| 406 | } |
408 | } |
| 407 | numtoascii(num>>decimalplace, &string ); |
409 | numtoascii(num>>decimalplace, &string ); |
| - | 410 | if(numberofdecimals!=0) *(string++) = '.'; |
|
| - | 411 | for(i=0;i<numberofdecimals;i++) { |
|
| - | 412 | num %= 1<<decimalplace; |
|
| - | 413 | num *= 10; |
|
| - | 414 | *(string++) = '0' + (num>>decimalplace); |
|
| - | 415 | } |
|
| 408 | *(string++) = |
416 | *(string++) = 0; |
| - | 417 | } |
|
| - | 418 | ||
| - | 419 | void unsignedtoascii(uint16_t num, uint8_t decimalplace, char *string, uint8_t numberofdecimals){ //decimalplace is number of decimals |
|
| - | 420 | uint8_t i; |
|
| - | 421 | numtoascii(num>>decimalplace, &string ); |
|
| - | 422 | if(numberofdecimals!=0) *(string++) = '.'; |
|
| 409 | for(i=0;i< |
423 | for(i=0;i<numberofdecimals;i++) { |
| 410 | num %= 1<<decimalplace; |
424 | num %= 1<<decimalplace; |
| 411 | num *= 10; |
425 | num *= 10; |
| 412 | *(string++) = '0' + (num>>decimalplace); |
426 | *(string++) = '0' + (num>>decimalplace); |
| 413 | } |
427 | } |
| 414 | *(string++) = 0; |
428 | *(string++) = 0; |
| 415 | } |
429 | } |
| 416 | 430 | ||
| 417 | 431 | ||
| 418 | //Supersnodd: |
- | |
| 419 | - | ||
| 420 | - | ||
| 421 | - | ||
| 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 | */ |
- | |
| 457 | - | ||
| 458 | // nn annans rutin som jag inte riktigt frstr mig p. |
- | |
| 459 | uint8_t *io_s16toStr(int16_t value,uint8_t *str,uint8_t decimal,uint8_t options) { |
- | |
| 460 | uint8_t i=0,j=0,w=0; |
- | |
| 461 | uint16_t tmp; |
- | |
| 462 | - | ||
| 463 | if(value<0) { |
- | |
| 464 | str[i++]='-'; |
- | |
| 465 | tmp=-value; |
- | |
| 466 | } else { |
- | |
| 467 | if(options&0x01) str[i++]=' '; |
- | |
| 468 | tmp=value; |
- | |
| 469 | } |
- | |
| 470 | while(tmp>0) { |
- | |
| 471 | _io_buf[j++]='0'+(tmp%10); |
- | |
| 472 | tmp=tmp/10; |
- | |
| 473 | } |
- | |
| 474 | if(j<=decimal) { |
- | |
| 475 | str[i++]='0'; |
- | |
| 476 | if(decimal>0) str[i++]='.'; |
- | |
| 477 | w=i; |
- | |
| 478 | while((i-w)<(decimal-j)) str[i++]='0'; |
- | |
| 479 | while(j!=0) str[i++]=_io_buf[--j]; |
- | |
| 480 | } else { |
- | |
| 481 | while(j!=0) { |
- | |
| 482 | str[i++]=_io_buf[--j]; |
- | |
| 483 | if(j==decimal) str[i++]='.'; |
- | |
| 484 | } |
- | |
| 485 | } |
- | |
| 486 | str[i++]=0; |
- | |
| 487 | return(str); |
- | |
| 488 | } |
- | |
| 489 | - | ||
| 490 | uint8_t *io_u16toStr(uint16_t value,uint8_t *str,uint8_t decimal,uint8_t options) { |
- | |
| 491 | uint8_t i=0; |
- | |
| 492 | uint8_t j=0; |
- | |
| 493 | uint8_t w=0; |
- | |
| 494 | - | ||
| 495 | while(value>0) { |
- | |
| 496 | _io_buf[j++]='0'+(value%10); |
- | |
| 497 | value=value/10; |
- | |
| 498 | } |
- | |
| 499 | - | ||
| 500 | if(j<=decimal) { |
- | |
| 501 | str[i++]='0'; |
- | |
| 502 | if(decimal>0) str[i++]='.'; |
- | |
| 503 | w=i; |
- | |
| 504 | while((i-w)<(decimal-j)) str[i++]='0'; |
- | |
| 505 | while(j!=0) str[i++]=_io_buf[--j]; |
- | |
| 506 | } else { |
- | |
| 507 | while(j>0) { |
- | |
| 508 | str[i++]=_io_buf[--j]; |
- | |
| 509 | if((decimal>0)&&(j==decimal)) str[i++]='.'; |
- | |
| 510 | } |
- | |
| 511 | } |
- | |
| 512 | str[i++]=0; |
- | |
| 513 | return(str); |
- | |
| 514 | } |
- | |
| 515 | 432 | ||