Compare commits
3 Commits
6dca8972e3
...
developmen
| Author | SHA1 | Date | |
|---|---|---|---|
| 7c60a7e97a | |||
| fd34ac13ca | |||
| 59519e4f55 |
16
.gitmodules
vendored
16
.gitmodules
vendored
@@ -1,24 +1,24 @@
|
||||
[submodule "FW/leo_muziekdoos_esp32/lib/ESP8266Audio"]
|
||||
path = FW/leo_muziekdoos_esp32/lib/ESP8266Audio
|
||||
url = http://192.168.2.3:3000/libs/ESP8266Audio.git
|
||||
url = http://debianvm.local:3000/libs/ESP8266Audio.git
|
||||
[submodule "FW/leo_muziekdoos_esp32/lib/littleFS_esp32"]
|
||||
path = FW/leo_muziekdoos_esp32/lib/littleFS_esp32
|
||||
url = http://192.168.2.3:3000/libs/LittleFS_esp32
|
||||
url = http://debianvm.local:3000/libs/LittleFS_esp32
|
||||
[submodule "FW/leo_muziekdoos_esp32/lib/JCButton"]
|
||||
path = FW/leo_muziekdoos_esp32/lib/JCButton
|
||||
url = http://192.168.2.3:3000/libs/JCButton.git
|
||||
url = http://debianvm.local:3000/libs/JCButton.git
|
||||
[submodule "FW/leo_muziekdoos_esp32/lib/NDEF"]
|
||||
path = FW/leo_muziekdoos_esp32/lib/NDEF
|
||||
url = http://192.168.2.3:3000/libs/rfid.NDEF.git
|
||||
url = http://debianvm.local:3000/libs/rfid.NDEF.git
|
||||
[submodule "FW/leo_muziekdoos_esp32/lib/PN532"]
|
||||
path = FW/leo_muziekdoos_esp32/lib/PN532
|
||||
url = http://192.168.2.3:3000/libs/rfid.PN532.git
|
||||
url = http://debianvm.local:3000/libs/rfid.PN532.git
|
||||
[submodule "FW/leo_muziekdoos_esp32/lib/PN532_SPI"]
|
||||
path = FW/leo_muziekdoos_esp32/lib/PN532_SPI
|
||||
url = http://192.168.2.3:3000/libs/rfid.PN532_SPI.git
|
||||
url = http://debianvm.local:3000/libs/rfid.PN532_SPI.git
|
||||
[submodule "FW/leo_muziekdoos_esp32/lib/ADC_ADS1x15"]
|
||||
path = FW/leo_muziekdoos_esp32/lib/ADC_ADS1x15
|
||||
url = http://192.168.2.3:3000/libs/ADC_ADS1X15.git
|
||||
url = http://debianvm.local:3000/libs/ADC_ADS1X15.git
|
||||
[submodule "FW/leo_muziekdoos_esp32/lib/BatterySense"]
|
||||
path = FW/leo_muziekdoos_esp32/lib/BatterySense
|
||||
url = http://192.168.2.3:3000/libs/BatterySense.git
|
||||
url = http://debianvm.local:3000/libs/BatterySense.git
|
||||
|
||||
@@ -15,6 +15,7 @@ framework = arduino
|
||||
lib_deps =
|
||||
bblanchon/ArduinoJson@^6.18.5
|
||||
fastled/FastLED@^3.4.0
|
||||
robtillaart/AS5600@^0.3.4
|
||||
monitor_speed = 115200
|
||||
lib_ldf_mode = deep+
|
||||
extra_scripts = ./littlefsbuilder.py
|
||||
|
||||
@@ -103,6 +103,8 @@ void initAudio()
|
||||
|
||||
void setAudioState(bool state)
|
||||
{
|
||||
if(state == audioState) return;
|
||||
|
||||
audioState = state;
|
||||
if (state)
|
||||
{
|
||||
|
||||
@@ -28,7 +28,7 @@ void SetLedColor(CRGB color, bool blink)
|
||||
void initLed(void)
|
||||
{
|
||||
FastLED.addLeds<SK6812, LED_PIN, GRB>(leds, NUM_LEDS); // GRB ordering is typical
|
||||
FastLED.setBrightness(40);
|
||||
FastLED.setBrightness(20);
|
||||
}
|
||||
|
||||
void handleLed(void)
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
|
||||
|
||||
#define TIMEOUT_POWER (7 * 1000 * 60) // 7 minutes timeout
|
||||
#define POWERBUTTONDELAY 1000
|
||||
#define POWERBUTTONDELAY 400
|
||||
//#define BATTERYMEASUREDELAY 60000
|
||||
#define POWERBUTTONOTADELAY 7000
|
||||
#define POWERBUTTONOTADELAY 4000
|
||||
#define POWEROFFOFFDELAY 3000
|
||||
|
||||
typedef enum
|
||||
|
||||
@@ -12,6 +12,7 @@ uint16_t BatteryVoltage = 0;
|
||||
uint32_t BatteryWarningFirst = 0;
|
||||
|
||||
uint16_t HallSensor = 0;
|
||||
HALLSENSORSTATES hall_sensor_state = HALLSENSORSTATES::hall_idle;
|
||||
|
||||
uint32_t last_hall_read = 0;
|
||||
uint16_t last_hall_sample = 0;
|
||||
@@ -23,6 +24,23 @@ bool hall_is_Idle = true;
|
||||
|
||||
bool hallinitOK = false;
|
||||
|
||||
String HALLSENSORSTATES_STR[] = {
|
||||
"hall_idle",
|
||||
"hall_increasing",
|
||||
"hall_tipover",
|
||||
"hall_decreasing",
|
||||
"unknown"};
|
||||
|
||||
String getHallSensorStateStr(HALLSENSORSTATES state)
|
||||
{
|
||||
if (state < sizeof(HALLSENSORSTATES))
|
||||
{
|
||||
return HALLSENSORSTATES_STR[state];
|
||||
}
|
||||
log_d("unknown state %d", state);
|
||||
return "unknown state";
|
||||
}
|
||||
|
||||
bool getSensorInitStatus(void)
|
||||
{
|
||||
return hallinitOK;
|
||||
@@ -55,6 +73,7 @@ void initSensor(void)
|
||||
{
|
||||
log_i("sensor init ADS1x15:");
|
||||
bool result = ADS.begin(I2C_SDA, I2C_SCL);
|
||||
ADS.setMode(0);
|
||||
initBattery();
|
||||
if (!result)
|
||||
{
|
||||
@@ -78,11 +97,11 @@ bool CheckBattery(void)
|
||||
if (BatteryVoltage < VBATTMIN)
|
||||
{
|
||||
uint32_t timeNow = millis();
|
||||
if(BatteryWarningFirst == 0)
|
||||
if (BatteryWarningFirst == 0)
|
||||
{
|
||||
BatteryWarningFirst = timeNow;
|
||||
}
|
||||
if(timeNow - BatteryWarningFirst > LOWBATTPERIOD)
|
||||
if (timeNow - BatteryWarningFirst > LOWBATTPERIOD)
|
||||
{
|
||||
batteryLow = true;
|
||||
return true;
|
||||
@@ -119,63 +138,109 @@ void handleBatterySensor(void)
|
||||
{
|
||||
CheckBattery();
|
||||
log_i("vbatt level = %d %%", BatterySensor);
|
||||
if(BatterySensor > 80) SetLedColor(CRGB::Green);
|
||||
else if(BatterySensor > 50) SetLedColor(CRGB::Orange);
|
||||
else if(BatterySensor > 20) SetLedColor(CRGB::Red);
|
||||
if (BatterySensor > 80)
|
||||
SetLedColor(CRGB::Green);
|
||||
else if (BatterySensor > 50)
|
||||
SetLedColor(CRGB::Orange);
|
||||
else if (BatterySensor > 20)
|
||||
SetLedColor(CRGB::Red);
|
||||
lastVbatt = timeNow;
|
||||
}
|
||||
}
|
||||
|
||||
HALLSENSORSTATES hall_sensor_state = HALLSENSORSTATES::hall_idle;
|
||||
HALLSENSORSTATES getprogressstate(uint16_t sample)
|
||||
{
|
||||
if (int(sample - last_hall_sample) > HALLTHRESHOLD)
|
||||
{
|
||||
return hall_increasing;
|
||||
}
|
||||
else if (int(sample - last_hall_sample) < HALLTHRESHOLD)
|
||||
{
|
||||
return hall_decreasing;
|
||||
}
|
||||
else
|
||||
{
|
||||
return hall_idle;
|
||||
}
|
||||
}
|
||||
|
||||
void handleHallSensor(void)
|
||||
{
|
||||
uint32_t timeNow = millis();
|
||||
if (timeNow - last_hall_read > HALLINTERVAL)
|
||||
{
|
||||
//get sample
|
||||
// get sample
|
||||
uint16_t hall_sample = ADS.readADC(HALL_INPUT);
|
||||
|
||||
switch(hall_sensor_state)
|
||||
switch (hall_sensor_state)
|
||||
{
|
||||
case hall_idle:
|
||||
case hall_idle:
|
||||
{
|
||||
hall_is_Idle = true;
|
||||
if (int(hall_sample - last_hall_sample) > HALLIDLETHRESHOLD)
|
||||
{
|
||||
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;
|
||||
}
|
||||
hall_decrease_count = 0;
|
||||
if (hall_increase_count++ > HALLIDLETHRESHOLD)
|
||||
hall_sensor_state = hall_increasing;
|
||||
}
|
||||
break;
|
||||
case hall_decreasing:
|
||||
else if (int(hall_sample - last_hall_sample) < HALLTHRESHOLD)
|
||||
{
|
||||
|
||||
hall_increase_count = 0;
|
||||
if (hall_decrease_count++ > HALLIDLETHRESHOLD)
|
||||
hall_sensor_state = hall_decreasing;
|
||||
}
|
||||
break;
|
||||
case hall_tipover:
|
||||
}
|
||||
break;
|
||||
case hall_decreasing:
|
||||
{
|
||||
hall_is_Idle = false;
|
||||
if (int(hall_sample - last_hall_sample) > HALLIDLETHRESHOLD)
|
||||
{
|
||||
|
||||
hall_decrease_count = 0;
|
||||
log_i("goto hall_increasing");
|
||||
if (hall_increase_count++ > HALLIDLETHRESHOLD)
|
||||
hall_sensor_state = hall_increasing;
|
||||
}
|
||||
break;
|
||||
case hall_increasing:
|
||||
else if (int(hall_sample - last_hall_sample) < HALLTHRESHOLD)
|
||||
{
|
||||
|
||||
hall_increase_count = 0;
|
||||
if(hall_decrease_count < HALLIDLETHRESHOLD) hall_decrease_count++;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
else if (hall_decrease_count == 0)
|
||||
{
|
||||
|
||||
hall_sensor_state = hall_tipover;
|
||||
log_i("go to tipover");
|
||||
}
|
||||
break;
|
||||
else
|
||||
{
|
||||
hall_decrease_count--;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case hall_tipover:
|
||||
{
|
||||
// check if samples increase
|
||||
// check if samples decrease
|
||||
// check if samples are steady
|
||||
}
|
||||
break;
|
||||
case hall_increasing:
|
||||
{
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
log_d("state: default");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
log_d("state: %s (sample: %d), countup(%d), countdown(%d)",
|
||||
getHallSensorStateStr(hall_sensor_state).c_str(),
|
||||
hall_sample,
|
||||
hall_increase_count,
|
||||
hall_decrease_count);
|
||||
|
||||
|
||||
// bool skipfirstSample = false;
|
||||
// if (!last_hall_Delta)
|
||||
// {
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "ADS1X15.h"
|
||||
#include "Battery.h"
|
||||
#include "board.h"
|
||||
#include "led.h"
|
||||
|
||||
#define ADSINTERVAL 100
|
||||
#define VBATTINTERVALL 15000
|
||||
#define VBATTMEASPRECHARGE 500
|
||||
#define LOWBATTPERIOD 30000
|
||||
#define ADSINTERVAL 100
|
||||
#define VBATTINTERVALL 15000
|
||||
#define VBATTMEASPRECHARGE 500
|
||||
#define LOWBATTPERIOD 30000
|
||||
|
||||
#define HALLINTERVAL 100
|
||||
#define HALLTHRESHOLD 5
|
||||
#define HALLINTERVAL 50
|
||||
#define HALLCNTTHRESHOLD 20
|
||||
#define HALLIDLETHRESHOLD 20
|
||||
#define HALLIDLESAMPLES 15
|
||||
#define HALLPLAYSAMPLES 24
|
||||
@@ -24,6 +25,7 @@ typedef enum
|
||||
hall_decreasing,
|
||||
}HALLSENSORSTATES;
|
||||
|
||||
|
||||
void initSensor(void);
|
||||
void handleBatterySensor(void);
|
||||
void handleHallSensor(void);
|
||||
|
||||
Reference in New Issue
Block a user