ChaletLora/ChaletLora.X/Source/LedLightCtrl.c
2021-05-22 22:08:19 -04:00

96 lines
1.6 KiB
C

#include "define.h"
#include "LedLightCtrl.h"
#include "PWMCtrl.h"
int LedLightBrightness = 10;
int LedLightState = LED_LIGHT_ON;
void LedLightDecrease()
{
if(LedLightState == LED_LIGHT_OFF)
return;
LedLightDim(LED_LIGHT_TICK_STEP);
}
void LedLightDim(int Percent)
{
if(LedLightState == LED_LIGHT_OFF)
return;
LedLightBrightness -= Percent;
if(LedLightBrightness < LED_LIGHT_MIN_DIM_VAL)
{
LedLightBrightness = LED_LIGHT_MIN_DIM_VAL;
}
PWMSetValue(LedLightBrightness);
}
void LedLightBright(int Percent)
{
if(LedLightState == LED_LIGHT_OFF)
return;
LedLightBrightness += Percent;
if(LedLightBrightness >= 100)
{
LedLightBrightness = 100;
}
PWMSetValue(LedLightBrightness);
}
void LedLightIncrease()
{
if(LedLightState == LED_LIGHT_OFF)
return;
LedLightBright(LED_LIGHT_TICK_STEP);
}
void LedLightSet(int Percent)
{
if(Percent < 0)
Percent = 0;
if(Percent > 100)
Percent = 100;
LedLightBrightness = Percent;
PWMSetValue(LedLightBrightness);
}
void TurnLedLightON()
{
LedLightState = LED_LIGHT_ON;
PWMSetValue(LedLightBrightness);
}
void TurnLedLightOFF()
{
LedLightState = LED_LIGHT_OFF;
PWMSetValue(0);
}
void LedLightONOFFBtnPressed()
{
if(LedLightState == LED_LIGHT_ON)
{
TurnLedLightOFF();
}
else
{
TurnLedLightON();
}
}
int GetLedLightBrightness()
{
return LedLightBrightness;
}
int GetLedLightState()
{
return LedLightState;
}