126 lines
2.6 KiB
C
126 lines
2.6 KiB
C
/**** Includes ****/
|
|
#include "display.h"
|
|
|
|
/**** Private definitions ****/
|
|
|
|
/**** Private variables ****/
|
|
static uint8_t PWM_DIMM = 50;
|
|
static uint8_t PWM_BRIGTH = 100;
|
|
|
|
static uint8_t set_image = 0x00;
|
|
|
|
static uint16_t lock_timer = 0;
|
|
|
|
/**** Private function declarations ****/
|
|
static uint8_t ImageGen_Dot10(uint8_t percent);
|
|
static uint8_t ImageGen_Dot20(uint8_t percent);
|
|
static uint8_t ImageGen_Bar(uint8_t percent);
|
|
|
|
/**** Public function definitions ****/
|
|
void Display_CfgBacklight(uint8_t brigth, uint8_t dimm)
|
|
{
|
|
//Limit values
|
|
if(brigth>100) brigth = 100;
|
|
else if(brigth==0) brigth = 1;
|
|
|
|
if(dimm>100) dimm = 100;
|
|
else if(dimm==0) dimm = 1;
|
|
|
|
//Save values
|
|
PWM_BRIGTH = brigth;
|
|
PWM_DIMM = dimm;
|
|
}
|
|
|
|
void Display_SetImage(uint8_t image)
|
|
{
|
|
if(lock_timer) return;
|
|
|
|
set_image = image & 0x3F;
|
|
}
|
|
|
|
void Display_SetPercent(uint8_t value, dspStyle_t style)
|
|
{
|
|
switch(style)
|
|
{
|
|
case BAR:
|
|
Display_SetImage(ImageGen_Bar(value));
|
|
break;
|
|
|
|
case DOT10:
|
|
Display_SetImage(ImageGen_Dot10(value));
|
|
break;
|
|
|
|
default:
|
|
Display_SetImage(ImageGen_Dot20(value));
|
|
break;
|
|
}
|
|
}
|
|
|
|
void Display_SetScale(uint16_t value, uint16_t max_value ,dspStyle_t style)
|
|
{
|
|
//Convert value to percent
|
|
uint32_t temp = (uint32_t)value *100;
|
|
temp /= max_value;
|
|
|
|
//Limit value to 100 percent
|
|
uint8_t percent = 0;
|
|
if(temp >= 100) percent = 100;
|
|
else if(temp == 0) percent = 0;
|
|
else percent = (uint8_t)temp;
|
|
|
|
Display_SetPercent(percent, style);
|
|
}
|
|
|
|
void Display_SetLock(uint16_t time)
|
|
{
|
|
lock_timer = time;
|
|
}
|
|
|
|
void Display_Update(inputs_t* inputs)
|
|
{
|
|
// Brightness control
|
|
if(inputs->dimm.is_active) LED_DSP_SetBrightness(PWM_DIMM);
|
|
else LED_DSP_SetBrightness(PWM_BRIGTH);
|
|
|
|
if(lock_timer) lock_timer--;
|
|
|
|
// Set image
|
|
LED_DSP_ShowImage(set_image);
|
|
}
|
|
|
|
/**** Private function definitions ****/
|
|
static uint8_t ImageGen_Dot10(uint8_t percent)
|
|
{
|
|
if(percent<6) return 0x01;
|
|
else if(percent<16) return 0x03;
|
|
else if(percent<26) return 0x02;
|
|
else if(percent<36) return 0x06;
|
|
else if(percent<46) return 0x04;
|
|
else if(percent<56) return 0x0C;
|
|
else if(percent<66) return 0x08;
|
|
else if(percent<76) return 0x18;
|
|
else if(percent<86) return 0x10;
|
|
else if(percent<96) return 0x30;
|
|
else return 0x20;
|
|
}
|
|
|
|
static uint8_t ImageGen_Dot20(uint8_t percent)
|
|
{
|
|
if(percent<11) return 0x01;
|
|
else if(percent<31) return 0x02;
|
|
else if(percent<51) return 0x04;
|
|
else if(percent<71) return 0x08;
|
|
else if(percent<91) return 0x10;
|
|
else return 0x20;
|
|
}
|
|
|
|
static uint8_t ImageGen_Bar(uint8_t percent)
|
|
{
|
|
if(percent<11) return 0x01;
|
|
else if(percent<31) return 0x03;
|
|
else if(percent<51) return 0x07;
|
|
else if(percent<71) return 0x0F;
|
|
else if(percent<91) return 0x1F;
|
|
else return 0x3F;
|
|
}
|