Rev 2 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2 | Rev 3 | ||
---|---|---|---|
Line 46... | Line 46... | ||
46 | heaterControl control; ///< control state |
46 | heaterControl control; ///< control state |
47 | uint16_t LEDintensity; ///< current LED intensity |
47 | uint16_t LEDintensity; ///< current LED intensity |
48 | uint16_t LEDtarget; ///< current LED target intensity |
48 | uint16_t LEDtarget; ///< current LED target intensity |
49 | uint32_t heatTimer; /// < tick time counter for heater channel |
49 | uint32_t heatTimer; /// < tick time counter for heater channel |
50 | uint8_t buttonCount; /// < debounce counter |
50 | uint8_t buttonCount; /// < debounce counter |
- | 51 | uint8_t tick; /// < a value that increments |
|
51 | uint16_t checkSum; /// < checksum used in post-reset validation |
52 | uint16_t checkSum; /// < checksum used in post-reset validation |
52 | } heaterStatus; |
53 | } heaterStatus; |
53 | #pragma pack(pop) |
54 | #pragma pack(pop) |
54 | 55 | ||
55 | /// \brief enumeration of LED intensities for each case |
56 | /// \brief enumeration of LED intensities for each case |
Line 316... | Line 317... | ||
316 | }; |
317 | }; |
317 | // default return a reset state |
318 | // default return a reset state |
318 | return &ResetHeater; |
319 | return &ResetHeater; |
319 | } |
320 | } |
320 | 321 | ||
321 | void process(heaterStatus *status, uint8_t button, uint16_t intensity, int8_t temperature, uint16_t battery, uint16_t dashboard) |
322 | void process(heaterStatus *status, uint8_t button, int8_t temperature, uint16_t battery, uint16_t dashboard) |
322 | { |
323 | { |
323 | // deal with button debounce |
324 | // deal with button debounce |
324 | uint8_t buttonPressed = 0; |
325 | uint8_t buttonPressed = 0; |
325 | uint8_t longButtonPressed = 0; |
326 | uint8_t longButtonPressed = 0; |
326 | 327 | ||
- | 328 | // deal with intensity |
|
- | 329 | uint16_t intensity; |
|
- | 330 | status->tick++; |
|
- | 331 | if ((status->tick % 128) < 64) |
|
- | 332 | { |
|
- | 333 | intensity = INTENSITY_STBY_DIM; |
|
- | 334 | } |
|
- | 335 | else{ |
|
- | 336 | intensity = INTENSITY_STBY_BRIGHT; |
|
- | 337 | } |
|
- | 338 | ||
- | 339 | if (status->buttonCount >=100) |
|
- | 340 | status->buttonCount=100; |
|
327 | if (button && status->buttonCount < 100) |
341 | if (button && status->buttonCount < 100) |
328 | { |
342 | { |
329 | status->buttonCount++; |
343 | status->buttonCount++; |
330 | if (status->buttonCount == 10) |
344 | if (status->buttonCount == 10) |
331 | buttonPressed = 1; |
345 | buttonPressed = 1; |
332 | if (status->buttonCount == 100) |
346 | if (status->buttonCount == 100) |
333 | longButtonPressed = 1; |
347 | longButtonPressed = 1; |
334 | } |
348 | } |
335 | if (!button) |
349 | if (!button) |
336 | status->buttonCount = 0; |
350 | status->buttonCount = 0; |
- | 351 | ||
337 | 352 | ||
338 | // deal with LED brightness control |
353 | // deal with LED brightness control |
339 | 354 | ||
340 | if (status->LEDintensity < status->LEDtarget) |
355 | if (status->LEDintensity < status->LEDtarget) |
341 | { |
356 | { |
Line 496... | Line 511... | ||
496 | HAL_TIM_OC_Start(&htim3, TIM_CHANNEL_2); |
511 | HAL_TIM_OC_Start(&htim3, TIM_CHANNEL_2); |
497 | HAL_TIM_OC_Start(&htim3, TIM_CHANNEL_4); |
512 | HAL_TIM_OC_Start(&htim3, TIM_CHANNEL_4); |
498 | 513 | ||
499 | HAL_TIM_OC_Start(&htim14, TIM_CHANNEL_1); |
514 | HAL_TIM_OC_Start(&htim14, TIM_CHANNEL_1); |
500 | 515 | ||
501 | int cnt = 0; |
- | |
502 | - | ||
503 | uint16_t intensity = 0; |
- | |
504 | HeaterLeft.LEDtarget = INTENSITY_OFF; |
516 | HeaterLeft.LEDtarget = INTENSITY_OFF; |
505 | HeaterRight.LEDtarget = INTENSITY_OFF; |
517 | HeaterRight.LEDtarget = INTENSITY_OFF; |
506 | 518 | ||
507 | /* USER CODE END 2 */ |
519 | /* USER CODE END 2 */ |
508 | 520 | ||
Line 520... | Line 532... | ||
520 | setLEDRight(HeaterRight.LEDintensity); |
532 | setLEDRight(HeaterRight.LEDintensity); |
521 | setLEDEval(HeaterLeft.LEDintensity); |
533 | setLEDEval(HeaterLeft.LEDintensity); |
522 | 534 | ||
523 | setRelayLeft(HeaterLeft.control); |
535 | setRelayLeft(HeaterLeft.control); |
524 | setRelayRight(HeaterRight.control); |
536 | setRelayRight(HeaterRight.control); |
525 | 537 | ||
526 | cnt = cnt + 1; |
- | |
527 | // generate different intensity targets for LED pulsation effect |
538 | // generate different intensity targets for LED pulsation effect |
528 | if ((cnt % 128) == 64) |
- | |
529 | { |
- | |
530 | intensity = INTENSITY_STBY_DIM; |
- | |
531 | } |
- | |
532 | if ((cnt % 128) == 0) |
- | |
533 | { |
- | |
534 | intensity = INTENSITY_STBY_BRIGHT; |
- | |
535 | } |
- | |
536 | 539 | ||
537 | process(&HeaterLeft, getButtonLeft(), intensity, temperature, batteryVoltage, dashVoltage); |
540 | process(&HeaterLeft, getButtonLeft(), temperature, batteryVoltage, dashVoltage); |
538 | process(&HeaterRight, getButtonRight(), intensity, temperature, batteryVoltage, dashVoltage); |
541 | process(&HeaterRight, getButtonRight(), temperature, batteryVoltage, dashVoltage); |
539 | 542 | ||
540 | /* note the WWDG configuration also needs to be updated if this delay is changed */ |
543 | /* note the WWDG configuration also needs to be updated if this delay is changed */ |
541 | HAL_Delay(10); |
544 | HAL_Delay(10); |
542 | #if defined WATCHDOG |
545 | #if defined WATCHDOG |
543 | HAL_WWDG_Refresh(&hwwdg); |
546 | HAL_WWDG_Refresh(&hwwdg); |