firmware updates
This commit is contained in:
Binary file not shown.
Submodule FW/leo_muziekdoos_esp32/lib/PN532 updated: e88576ed93...47ec860298
@@ -21,6 +21,5 @@ extra_scripts = ./littlefsbuilder.py
|
|||||||
build_flags =
|
build_flags =
|
||||||
-DHARDWARE=2
|
-DHARDWARE=2
|
||||||
-DCORE_DEBUG_LEVEL=4
|
-DCORE_DEBUG_LEVEL=4
|
||||||
-DNDEF_DEBUG=1
|
|
||||||
upload_protocol = espota
|
upload_protocol = espota
|
||||||
upload_port = muziekdoos.local
|
upload_port = muziekdoos.local
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ void SetLedColor(CRGB color, bool blink)
|
|||||||
void initLed(void)
|
void initLed(void)
|
||||||
{
|
{
|
||||||
FastLED.addLeds<SK6812, LED_PIN, GRB>(leds, NUM_LEDS); // GRB ordering is typical
|
FastLED.addLeds<SK6812, LED_PIN, GRB>(leds, NUM_LEDS); // GRB ordering is typical
|
||||||
FastLED.setBrightness(40);
|
FastLED.setBrightness(LEDBRIGHTNESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleLed(void)
|
void handleLed(void)
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#define NUM_LEDS 1
|
#define NUM_LEDS 1
|
||||||
#define LEDTIMEOUT 100
|
#define LEDTIMEOUT 100
|
||||||
#define LEDBLINKTIME 500
|
#define LEDBLINKTIME 500
|
||||||
|
#define LEDBRIGHTNESS 75
|
||||||
|
|
||||||
void initLed(void);
|
void initLed(void);
|
||||||
void handleLed(void);
|
void handleLed(void);
|
||||||
|
|||||||
@@ -74,15 +74,15 @@ bool CheckBattery(void)
|
|||||||
BatteryVoltage = battery.voltage();
|
BatteryVoltage = battery.voltage();
|
||||||
BatterySensor = battery.level(BatteryVoltage);
|
BatterySensor = battery.level(BatteryVoltage);
|
||||||
digitalWrite(MEAS_EN, HIGH);
|
digitalWrite(MEAS_EN, HIGH);
|
||||||
log_i("read batt, ticks=%d, raw=%4.2f, vbatt=%d, level=%d", battticks, vbattraw, BatteryVoltage, BatterySensor);
|
log_v("read batt, ticks=%d, raw=%4.2f, vbatt=%d, level=%d", battticks, vbattraw, BatteryVoltage, BatterySensor);
|
||||||
if (BatteryVoltage < VBATTMIN)
|
if (BatteryVoltage < VBATTMIN)
|
||||||
{
|
{
|
||||||
uint32_t timeNow = millis();
|
uint32_t timeNow = millis();
|
||||||
if(BatteryWarningFirst == 0)
|
if (BatteryWarningFirst == 0)
|
||||||
{
|
{
|
||||||
BatteryWarningFirst = timeNow;
|
BatteryWarningFirst = timeNow;
|
||||||
}
|
}
|
||||||
if(timeNow - BatteryWarningFirst > LOWBATTPERIOD)
|
if (timeNow - BatteryWarningFirst > LOWBATTPERIOD)
|
||||||
{
|
{
|
||||||
batteryLow = true;
|
batteryLow = true;
|
||||||
return true;
|
return true;
|
||||||
@@ -118,106 +118,193 @@ void handleBatterySensor(void)
|
|||||||
if (timeNow - lastVbatt > VBATTINTERVALL)
|
if (timeNow - lastVbatt > VBATTINTERVALL)
|
||||||
{
|
{
|
||||||
CheckBattery();
|
CheckBattery();
|
||||||
log_i("vbatt level = %d %%", BatterySensor);
|
log_i("vbatt voltage = %d mv", BatteryVoltage);
|
||||||
if(BatterySensor > 80) SetLedColor(CRGB::Green);
|
if (BatterySensor > 80)
|
||||||
else if(BatterySensor > 50) SetLedColor(CRGB::Orange);
|
SetLedColor(CRGB::Green);
|
||||||
else if(BatterySensor > 20) SetLedColor(CRGB::Red);
|
else if (BatterySensor > 50)
|
||||||
|
SetLedColor(CRGB::Orange);
|
||||||
|
else if (BatterySensor > 20)
|
||||||
|
SetLedColor(CRGB::Red);
|
||||||
lastVbatt = timeNow;
|
lastVbatt = timeNow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HALLSENSORSTATES hall_sensor_state = HALLSENSORSTATES::hall_idle;
|
HALLSENSORSTATES hall_sensor_state = HALLSENSORSTATES::hall_idle;
|
||||||
|
uint32_t hall_timeout = 0;
|
||||||
|
uint32_t hall_stateTimer = 0;
|
||||||
|
HALLSENSORSTATES previous_hall_state = hall_sensor_state;
|
||||||
|
|
||||||
|
#define HALLSTATETIMEOUT 300
|
||||||
|
#define HALLTIMEOUT 1000
|
||||||
|
|
||||||
void handleHallSensor(void)
|
void handleHallSensor(void)
|
||||||
{
|
{
|
||||||
uint32_t timeNow = millis();
|
uint32_t timeNow = millis();
|
||||||
if (timeNow - last_hall_read > HALLINTERVAL)
|
if (timeNow - last_hall_read > HALLINTERVAL)
|
||||||
{
|
{
|
||||||
//get sample
|
// get sample
|
||||||
uint16_t hall_sample = ADS.readADC(HALL_INPUT);
|
uint16_t hall_sample = ADS.readADC(HALL_INPUT);
|
||||||
|
int hall_delta = hall_sample - last_hall_sample;
|
||||||
|
|
||||||
switch(hall_sensor_state)
|
switch (hall_sensor_state)
|
||||||
{
|
{
|
||||||
case hall_idle:
|
case hall_idle:
|
||||||
{
|
{
|
||||||
if(int(hall_sample - last_hall_sample) > 0)
|
if (hall_delta > HALLTHRESHOLD)
|
||||||
{
|
{
|
||||||
hall_decrease_count = 0;
|
hall_decrease_count = 0;
|
||||||
if(hall_increase_count++ > HALLTHRESHOLD) hall_sensor_state = hall_increasing;
|
if (hall_increase_count++ > HALLTHRESHOLD)
|
||||||
|
{
|
||||||
|
hall_sensor_state = hall_increasing;
|
||||||
|
log_i("next state = increasing");
|
||||||
}
|
}
|
||||||
else if(int(hall_sample - last_hall_sample) < 0)
|
}
|
||||||
|
else if (hall_delta < HALLTHRESHOLD)
|
||||||
{
|
{
|
||||||
hall_increase_count = 0;
|
hall_increase_count = 0;
|
||||||
if(hall_decrease_count++ > HALLTHRESHOLD) hall_sensor_state = hall_decreasing;
|
if (hall_decrease_count++ > HALLTHRESHOLD)
|
||||||
|
{
|
||||||
|
hall_sensor_state = hall_decreasing;
|
||||||
|
log_i("next state = decreasing");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* stay idle */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case hall_decreasing:
|
case hall_decreasing:
|
||||||
{
|
{
|
||||||
|
// lets see if we are bottoming out or stalling
|
||||||
|
if (hall_delta < HALLIDLETHRESHOLD)
|
||||||
|
{
|
||||||
|
// reset timer
|
||||||
|
hall_timeout = timeNow;
|
||||||
|
hall_stateTimer = timeNow;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (timeNow - hall_stateTimer > HALLSTATETIMEOUT)
|
||||||
|
{
|
||||||
|
// we are stalling or tipping under
|
||||||
|
hall_sensor_state = hall_tipunder;
|
||||||
|
hall_stateTimer = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case hall_tipover:
|
case hall_tipunder:
|
||||||
{
|
{
|
||||||
|
// check if we are stalling or moving into the increasing state
|
||||||
|
if (!(hall_delta > HALLIDLETHRESHOLD))
|
||||||
|
{
|
||||||
|
hall_stateTimer = timeNow;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (timeNow - hall_stateTimer > HALLSTATETIMEOUT)
|
||||||
|
{
|
||||||
|
// samples detected to the upside, move to increasing state
|
||||||
|
hall_sensor_state = hall_increasing;
|
||||||
|
hall_stateTimer = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(timeNow - hall_timeout > HALLTIMEOUT)
|
||||||
|
{
|
||||||
|
//timeed out, move to idle
|
||||||
|
hall_sensor_state = hall_idle;
|
||||||
|
hall_stateTimer = 0;
|
||||||
|
hall_timeout = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case hall_increasing:
|
case hall_increasing:
|
||||||
{
|
{
|
||||||
|
// check if we are increasing
|
||||||
|
if (hall_delta > HALLIDLETHRESHOLD)
|
||||||
|
{
|
||||||
|
hall_stateTimer = timeNow;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (timeNow - hall_stateTimer > HALLSTATETIMEOUT)
|
||||||
|
{
|
||||||
|
// samples detected to the upside, move to increasing state
|
||||||
|
hall_sensor_state = hall_tipover;
|
||||||
|
hall_stateTimer = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case hall_tipover:
|
||||||
|
{
|
||||||
|
// check if we are stalling or moving into the increasing state
|
||||||
|
if (!(hall_delta > HALLIDLETHRESHOLD))
|
||||||
|
{
|
||||||
|
hall_stateTimer = timeNow;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (timeNow - hall_stateTimer > HALLSTATETIMEOUT)
|
||||||
|
{
|
||||||
|
// samples detected to the upside, move to increasing state
|
||||||
|
hall_sensor_state = hall_decreasing;
|
||||||
|
hall_stateTimer = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(timeNow - hall_timeout > HALLTIMEOUT)
|
||||||
|
{
|
||||||
|
//timeed out, move to idle
|
||||||
|
hall_sensor_state = hall_idle;
|
||||||
|
hall_stateTimer = 0;
|
||||||
|
hall_timeout = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool skipfirstSample = false;
|
||||||
// bool skipfirstSample = false;
|
if (!last_hall_Delta)
|
||||||
// if (!last_hall_Delta)
|
{
|
||||||
// {
|
skipfirstSample = true;
|
||||||
// skipfirstSample = true;
|
}
|
||||||
// }
|
uint16_t hall_delta = (last_hall_sample > hall_sample) ? (last_hall_sample - hall_sample) : (hall_sample - last_hall_sample);
|
||||||
// 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;
|
||||||
// hall_delta = (hall_delta + last_hall_Delta) / 2;
|
last_hall_Delta = hall_delta;
|
||||||
// last_hall_Delta = hall_delta;
|
if (skipfirstSample)
|
||||||
// if (skipfirstSample)
|
{
|
||||||
// {
|
log_v("First sample skipped");
|
||||||
// log_v("First sample skipped");
|
if (hall_idle_count)
|
||||||
// if (hall_idle_count)
|
{
|
||||||
// {
|
hall_idle_count--;
|
||||||
// hall_idle_count--;
|
}
|
||||||
// }
|
return;
|
||||||
// return;
|
}
|
||||||
// }
|
if (hall_delta > HALLIDLETHRESHOLD)
|
||||||
// if (hall_delta > HALLIDLETHRESHOLD)
|
{
|
||||||
// {
|
if (hall_idle_count > HALLIDLESAMPLES)
|
||||||
// if (hall_idle_count > HALLIDLESAMPLES)
|
{
|
||||||
// {
|
hall_is_Idle = false;
|
||||||
// hall_is_Idle = false;
|
hall_idle_count = HALLPLAYSAMPLES;
|
||||||
// hall_idle_count = HALLPLAYSAMPLES;
|
log_i("Game: playing, delta = %d", hall_delta);
|
||||||
// log_i("Game: playing, delta = %d", hall_delta);
|
}
|
||||||
// }
|
else
|
||||||
// else
|
{
|
||||||
// {
|
hall_idle_count++;
|
||||||
// hall_idle_count++;
|
}
|
||||||
// }
|
}
|
||||||
// }
|
else
|
||||||
// else
|
{
|
||||||
// {
|
if (hall_idle_count == 0)
|
||||||
// if (hall_idle_count == 0)
|
{
|
||||||
// {
|
hall_is_Idle = true;
|
||||||
// hall_is_Idle = true;
|
}
|
||||||
// }
|
else
|
||||||
// else
|
{
|
||||||
// {
|
hall_idle_count--;
|
||||||
// hall_idle_count--;
|
}
|
||||||
// }
|
}
|
||||||
// }
|
log_i("HallSensor: val=%d, delta=%d, count=%d, idle=%s\n",
|
||||||
log_v("HallSensor: val=%d, delta=%d, count=%d, idle=%s\n",
|
|
||||||
hall_sample,
|
hall_sample,
|
||||||
hall_delta,
|
hall_delta,
|
||||||
hall_idle_count,
|
hall_idle_count,
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
#define HALLINTERVAL 100
|
#define HALLINTERVAL 100
|
||||||
#define HALLTHRESHOLD 5
|
#define HALLTHRESHOLD 5
|
||||||
#define HALLIDLETHRESHOLD 20
|
#define HALLIDLETHRESHOLD 10
|
||||||
#define HALLIDLESAMPLES 15
|
#define HALLIDLESAMPLES 15
|
||||||
#define HALLPLAYSAMPLES 24
|
#define HALLPLAYSAMPLES 24
|
||||||
|
|
||||||
@@ -22,8 +22,19 @@ typedef enum
|
|||||||
hall_increasing,
|
hall_increasing,
|
||||||
hall_tipover,
|
hall_tipover,
|
||||||
hall_decreasing,
|
hall_decreasing,
|
||||||
|
hall_tipunder,
|
||||||
|
HALL_LAST
|
||||||
}HALLSENSORSTATES;
|
}HALLSENSORSTATES;
|
||||||
|
|
||||||
|
static String HALLSENESORSTATES_ENUM2STR[HALL_LAST]
|
||||||
|
{
|
||||||
|
"Hall Idle",
|
||||||
|
"Hall Increasing",
|
||||||
|
"Hall Tipover",
|
||||||
|
"Hall decreasing",
|
||||||
|
"Hall tipUnder"
|
||||||
|
};
|
||||||
|
|
||||||
void initSensor(void);
|
void initSensor(void);
|
||||||
void handleBatterySensor(void);
|
void handleBatterySensor(void);
|
||||||
void handleHallSensor(void);
|
void handleHallSensor(void);
|
||||||
|
|||||||
Reference in New Issue
Block a user