updaed v1.1 code (shutdown)

This commit is contained in:
2021-05-08 18:37:21 +02:00
parent 94bcc5f979
commit ae1676c669
2 changed files with 42 additions and 8 deletions

View File

@@ -6,6 +6,8 @@
#define VBATTMAX 4180
#define VBATTREF 3300
#define HARDWAREVERSION 11
#ifndef UNIT_TEST
#if HARDWAREVERSION==9 //proto board with nucleo32l031 board

View File

@@ -5,6 +5,13 @@
#include "led.h"
#include "buttons.h"
#ifdef BTN_PWR
#include "JC_Button.h"
Button buttonPower(BTN_PWR);
#endif
bool doShutdown = false;
#ifdef VBATTPIN
#include "Battery.h"
Battery battery(VBATTMIN, VBATTMAX, VBATTPIN);
@@ -15,7 +22,7 @@ void initBattery(void)
#ifdef VBATTPIN
#ifdef MEAS_EN
battery.begin(VBATTREF, (R12 + R13) / R13); //R1 = 220K, R2 = 100K, factor = (R1+R2)/R2
battery.onDemand(MEAS_EN, HIGH);
battery.onDemand(MEAS_EN, LOW);
#else
battery.begin(VBATTREF, (R12 + R13) / R13); //R1 = 220K, R2 = 100K, factor = (R1+R2)/R2
#endif
@@ -65,8 +72,11 @@ void initShutdown(void)
{
#ifdef PW_HOLD
pinMode(PW_HOLD, OUTPUT);
pinMode(BTN_PWR, INPUT);
buttonPower.begin();
digitalWrite(PW_HOLD, LOW);
delay(2000);
digitalWrite(PW_HOLD, HIGH);
doShutdown = false;
#endif
}
@@ -75,23 +85,38 @@ void initPower(void)
{
LowPower_init();
initBattery();
initShutdown();
}
void shutdown(void)
{
LowPower_shutdown();
delay(2000);
//digitalWrite()
}
void HandlePower(void)
{
HandleTimeOut();
batteryCheck();
}
void HandlePowerOn(void)
{
if (buttonPower.read())
{
if (buttonPower.pressedFor(2000))
{
doShutdown = true;
delay(500);
}
else
{
doShutdown = false;
}
}
else
{
if (doShutdown & buttonPower.releasedFor(2000))
{
digitalWrite(PW_HOLD, LOW);
}
}
}
void HandleTimeOut(void)
@@ -121,4 +146,11 @@ void HandleTimeOut(void)
lasttimeOut = currentmillis;
}
}
}
void HandlePower(void)
{
HandleTimeOut();
batteryCheck();
HandlePowerOn();
}