firmware release 1.2

fixed MSboard, game class prep, power impr.
This commit is contained in:
2021-03-29 11:10:57 +02:00
parent 095e650457
commit 04b1235f1a
17 changed files with 222 additions and 113 deletions

View File

@@ -3,35 +3,25 @@
#include "rtc.h"
#include "low_Power.h"
#include "led.h"
#include "buttons.h"
#ifdef VBATTPIN
#include "Battery.h"
Battery battery(2500, 4160, VBATTPIN);
Battery battery(VBATTMIN, VBATTMAX, VBATTPIN);
#endif
void initBattery(void)
{
#ifdef VBATTPIN
battery.begin(3300, (R12+R13)/R13); //R1 = 220K, R2 = 100K, factor = (R1+R2)/R2
battery.begin(VBATTREF, (R12+R13)/R13); //R1 = 220K, R2 = 100K, factor = (R1+R2)/R2
#endif
}
uint16_t batteryGetVoltage( void )
{
#ifdef VBATTPIN
return battery.voltage();
#endif
return 4200;
}
void batterydisplay(void)
{
#ifdef VBATTPIN
uint16_t currentlevel = battery.level();
uint16_t currentvoltage = batteryGetVoltage();
if(currentvoltage)
{
if (currentlevel > 90)
{
turnOnLed(3);
@@ -44,14 +34,14 @@ void batterydisplay(void)
{
turnOnLed(1);
}
}
#endif
}
void batteryCheck(void)
{
#ifdef VBATTPIN
if (battery.level() < 10)
if (battery.voltage() < VBATTMIN)
{
for( int i = 0; i < 10;i++)
{
@@ -75,4 +65,40 @@ void initLowPower(void)
void shutdown(void)
{
LowPower_shutdown();
}
void HandlePower(void)
{
HandleTimeOut();
batteryCheck();
}
void HandleTimeOut(void)
{
uint64_t currentmillis = millis();
static uint64_t lasttimeOut = 0;
static bool buttonChanged = false;
if (!lasttimeOut)
{
lasttimeOut = currentmillis;
buttonChanged = anybutton();
}
//check if lastTime is initialized or timeout expired
if ((currentmillis - lasttimeOut > IDLESHUTDOWN))
{
turnOffAllLed();
shutdown();
}
else
{
if (buttonChanged != anybutton())
{
buttonChanged = anybutton();
//game in progress, update timer
lasttimeOut = currentmillis;
}
}
}