clean-up songs
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -29,7 +29,7 @@
|
||||
|
||||
#define LED_PIN 12
|
||||
|
||||
#define VBATTMIN 3000 //before lowbatt cutoff
|
||||
#define VBATTMIN 3200 //before lowbatt cutoff
|
||||
#define VBATTMAX 4180
|
||||
#define VBATTREF 3300
|
||||
#define R12 4.7
|
||||
|
||||
@@ -88,6 +88,8 @@ void handleGame(void)
|
||||
log_i("activeState = startPlaying");
|
||||
newState = false;
|
||||
setRFIDscanState(false);
|
||||
PowerKeepAlive();
|
||||
|
||||
}
|
||||
|
||||
if (hallIsIdle())
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "audio.h"
|
||||
#include "rfid.h"
|
||||
#include "config.h"
|
||||
#include "power.h"
|
||||
|
||||
#define TIMEOUT_IDLE 20000
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ bool powerbutton_released = true;
|
||||
|
||||
uint32_t PowerLastKeepAlive = 0;
|
||||
uint32_t PowerOtaLongPressTime = 0;
|
||||
uint64_t measure_timer = 0;
|
||||
uint32_t powerstate_timer = 0;
|
||||
|
||||
POWERSTATES powerstate = off;
|
||||
POWERSTATES lastState = off;
|
||||
@@ -124,16 +124,22 @@ void handlePowerState(void)
|
||||
if (buttonPower.pressedFor(100))
|
||||
{
|
||||
lastState = on;
|
||||
powerstate = poweringOff;
|
||||
powerstate = POWERSTATES::poweringOff;
|
||||
break;
|
||||
}
|
||||
if (getLowBatt())
|
||||
{
|
||||
log_w("on: Lowbat");
|
||||
powerstate = lowBatt;
|
||||
powerstate_timer = millis();
|
||||
powerstate = POWERSTATES::lowBatt;
|
||||
SetLedColor(CRGB::Red, true);
|
||||
break;
|
||||
}
|
||||
if(millis() - PowerLastKeepAlive > TIMEOUT_POWER)
|
||||
{
|
||||
powerstate_timer = millis();
|
||||
powerstate = POWERSTATES::timeOut;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case poweringOff:
|
||||
@@ -146,16 +152,6 @@ void handlePowerState(void)
|
||||
|
||||
log_w("poweringoff: 3/3 ==> powerOff");
|
||||
}
|
||||
else if (buttonPower.pressedFor(500))
|
||||
{
|
||||
log_w("poweringoff: 2/3");
|
||||
SetLedColor(CRGB::Orange, true);
|
||||
}
|
||||
else if (buttonPower.pressedFor(200))
|
||||
{
|
||||
log_w("poweringoff: 1/3");
|
||||
SetLedColor(CRGB::Brown, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
powerstate = lastState;
|
||||
@@ -174,17 +170,16 @@ void handlePowerState(void)
|
||||
break;
|
||||
case timeOut:
|
||||
{
|
||||
log_w("timeout ==> off");
|
||||
powerstate = off;
|
||||
SetLedColor(CRGB::Red, true);
|
||||
powerOff();
|
||||
delay(5000);
|
||||
log_w("timeout");
|
||||
SetLedColor(CRGB::Yellow, true);
|
||||
if(millis() - powerstate_timer > POWEROFFOFFDELAY)
|
||||
{
|
||||
powerstate = off;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case lowBatt:
|
||||
{
|
||||
// add delay
|
||||
//powerstate = off;
|
||||
if(!getLowBatt())
|
||||
{
|
||||
powerstate = on;
|
||||
@@ -194,6 +189,12 @@ void handlePowerState(void)
|
||||
{
|
||||
SetLedColor(CRGB::Red, true);
|
||||
}
|
||||
|
||||
// add delay
|
||||
if(millis() - powerstate_timer > POWEROFFOFFDELAY)
|
||||
{
|
||||
powerstate = off;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case overTheAir:
|
||||
|
||||
@@ -9,10 +9,11 @@
|
||||
#include "led.h"
|
||||
|
||||
|
||||
#define TIMEOUT_POWER (5 * 1000 * 60) //5minutes timeout
|
||||
#define POWERBUTTONDELAY 1000
|
||||
#define BATTERYMEASUREDELAY 60000
|
||||
#define POWERBUTTONOTADELAY 7000
|
||||
#define TIMEOUT_POWER (7 * 1000 * 60) // 7 minutes timeout
|
||||
#define POWERBUTTONDELAY 1000
|
||||
//#define BATTERYMEASUREDELAY 60000
|
||||
#define POWERBUTTONOTADELAY 7000
|
||||
#define POWEROFFOFFDELAY 3000
|
||||
|
||||
typedef enum
|
||||
{
|
||||
@@ -30,6 +31,7 @@ typedef enum
|
||||
} POWERSTATES;
|
||||
|
||||
POWERSTATES getPowerState( void );
|
||||
void PowerKeepAlive(void);
|
||||
|
||||
void initBattery(void);
|
||||
bool handleBattery(void);
|
||||
|
||||
@@ -9,12 +9,16 @@ bool batteryLow = false;
|
||||
|
||||
uint16_t BatterySensor = 0;
|
||||
uint16_t BatteryVoltage = 0;
|
||||
uint32_t BatteryWarningFirst = 0;
|
||||
|
||||
uint16_t HallSensor = 0;
|
||||
|
||||
uint32_t last_hall_read = 0;
|
||||
uint16_t last_hall_sample = 0;
|
||||
uint16_t last_hall_Delta = 0;
|
||||
uint8_t hall_idle_count = 0;
|
||||
uint8_t hall_decrease_count = 0;
|
||||
uint8_t hall_increase_count = 0;
|
||||
bool hall_is_Idle = true;
|
||||
|
||||
bool hallinitOK = false;
|
||||
@@ -44,7 +48,7 @@ bool hallIsIdle(void)
|
||||
void initBattery(void)
|
||||
{
|
||||
battery.onDemand(MEAS_EN, LOW);
|
||||
battery.begin(VBATTREF, (R12 + R13) / R13); // R1 = 220K, R2 = 100K, factor = (R1+R2)/R2
|
||||
battery.begin(VBATTREF, (R12 + R13) / R13, &sigmoidal); // R1 = 220K, R2 = 100K, factor = (R1+R2)/R2
|
||||
}
|
||||
|
||||
void initSensor(void)
|
||||
@@ -73,8 +77,24 @@ bool CheckBattery(void)
|
||||
log_i("read batt, ticks=%d, raw=%4.2f, vbatt=%d, level=%d", battticks, vbattraw, BatteryVoltage, BatterySensor);
|
||||
if (BatteryVoltage < VBATTMIN)
|
||||
{
|
||||
batteryLow = true;
|
||||
return true;
|
||||
uint32_t timeNow = millis();
|
||||
if(BatteryWarningFirst == 0)
|
||||
{
|
||||
BatteryWarningFirst = timeNow;
|
||||
}
|
||||
if(timeNow - BatteryWarningFirst > LOWBATTPERIOD)
|
||||
{
|
||||
batteryLow = true;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
SetLedColor(CRGB::Orange, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
BatteryWarningFirst = 0;
|
||||
}
|
||||
batteryLow = false;
|
||||
return false;
|
||||
@@ -106,53 +126,97 @@ void handleBatterySensor(void)
|
||||
}
|
||||
}
|
||||
|
||||
HALLSENSORSTATES hall_sensor_state = HALLSENSORSTATES::hall_idle;
|
||||
|
||||
void handleHallSensor(void)
|
||||
{
|
||||
uint32_t timeNow = millis();
|
||||
if (timeNow - last_hall_read > HALLINTERVAL)
|
||||
{
|
||||
//get sample
|
||||
uint16_t hall_sample = ADS.readADC(HALL_INPUT);
|
||||
bool skipfirstSample = false;
|
||||
if (!last_hall_Delta)
|
||||
|
||||
switch(hall_sensor_state)
|
||||
{
|
||||
skipfirstSample = true;
|
||||
}
|
||||
uint16_t hall_delta = (last_hall_sample > hall_sample) ? (last_hall_sample - hall_sample) : (hall_sample - last_hall_sample);
|
||||
hall_delta = (hall_delta + last_hall_Delta) / 2;
|
||||
last_hall_Delta = hall_delta;
|
||||
if (skipfirstSample)
|
||||
{
|
||||
log_v("First sample skipped");
|
||||
if (hall_idle_count)
|
||||
{
|
||||
hall_idle_count--;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (hall_delta > HALLIDLETHRESHOLD)
|
||||
{
|
||||
if (hall_idle_count > HALLIDLESAMPLES)
|
||||
{
|
||||
hall_is_Idle = false;
|
||||
hall_idle_count = HALLPLAYSAMPLES;
|
||||
log_i("Game: playing, delta = %d", hall_delta);
|
||||
}
|
||||
else
|
||||
{
|
||||
hall_idle_count++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (hall_idle_count == 0)
|
||||
{
|
||||
hall_is_Idle = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
hall_idle_count--;
|
||||
}
|
||||
case hall_idle:
|
||||
{
|
||||
if(int(hall_sample - last_hall_sample) > 0)
|
||||
{
|
||||
hall_decrease_count = 0;
|
||||
if(hall_increase_count++ > HALLTHRESHOLD) hall_sensor_state = hall_increasing;
|
||||
}
|
||||
else if(int(hall_sample - last_hall_sample) < 0)
|
||||
{
|
||||
hall_increase_count = 0;
|
||||
if(hall_decrease_count++ > HALLTHRESHOLD) hall_sensor_state = hall_decreasing;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case hall_decreasing:
|
||||
{
|
||||
|
||||
}
|
||||
break;
|
||||
case hall_tipover:
|
||||
{
|
||||
|
||||
}
|
||||
break;
|
||||
case hall_increasing:
|
||||
{
|
||||
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// bool skipfirstSample = false;
|
||||
// if (!last_hall_Delta)
|
||||
// {
|
||||
// skipfirstSample = true;
|
||||
// }
|
||||
// uint16_t hall_delta = (last_hall_sample > hall_sample) ? (last_hall_sample - hall_sample) : (hall_sample - last_hall_sample);
|
||||
// hall_delta = (hall_delta + last_hall_Delta) / 2;
|
||||
// last_hall_Delta = hall_delta;
|
||||
// if (skipfirstSample)
|
||||
// {
|
||||
// log_v("First sample skipped");
|
||||
// if (hall_idle_count)
|
||||
// {
|
||||
// hall_idle_count--;
|
||||
// }
|
||||
// return;
|
||||
// }
|
||||
// if (hall_delta > HALLIDLETHRESHOLD)
|
||||
// {
|
||||
// if (hall_idle_count > HALLIDLESAMPLES)
|
||||
// {
|
||||
// hall_is_Idle = false;
|
||||
// hall_idle_count = HALLPLAYSAMPLES;
|
||||
// log_i("Game: playing, delta = %d", hall_delta);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// hall_idle_count++;
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (hall_idle_count == 0)
|
||||
// {
|
||||
// hall_is_Idle = true;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// hall_idle_count--;
|
||||
// }
|
||||
// }
|
||||
log_v("HallSensor: val=%d, delta=%d, count=%d, idle=%s\n",
|
||||
hall_sample,
|
||||
hall_delta,
|
||||
|
||||
@@ -7,13 +7,22 @@
|
||||
|
||||
#define ADSINTERVAL 100
|
||||
#define VBATTINTERVALL 15000
|
||||
#define VBATTMEASPRECHARGE 10
|
||||
#define VBATTMEASPRECHARGE 500
|
||||
#define LOWBATTPERIOD 30000
|
||||
|
||||
#define HALLINTERVAL 100
|
||||
#define HALLTHRESHOLD 5
|
||||
#define HALLIDLETHRESHOLD 20
|
||||
#define HALLIDLESAMPLES 15
|
||||
#define HALLPLAYSAMPLES 24
|
||||
|
||||
typedef enum
|
||||
{
|
||||
hall_idle,
|
||||
hall_increasing,
|
||||
hall_tipover,
|
||||
hall_decreasing,
|
||||
}HALLSENSORSTATES;
|
||||
|
||||
void initSensor(void);
|
||||
void handleBatterySensor(void);
|
||||
|
||||
Reference in New Issue
Block a user