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"]
|
[submodule "FW/leo_muziekdoos_esp32/lib/ESP8266Audio"]
|
||||||
path = 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"]
|
[submodule "FW/leo_muziekdoos_esp32/lib/littleFS_esp32"]
|
||||||
path = 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"]
|
[submodule "FW/leo_muziekdoos_esp32/lib/JCButton"]
|
||||||
path = 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"]
|
[submodule "FW/leo_muziekdoos_esp32/lib/NDEF"]
|
||||||
path = 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"]
|
[submodule "FW/leo_muziekdoos_esp32/lib/PN532"]
|
||||||
path = 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"]
|
[submodule "FW/leo_muziekdoos_esp32/lib/PN532_SPI"]
|
||||||
path = 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"]
|
[submodule "FW/leo_muziekdoos_esp32/lib/ADC_ADS1x15"]
|
||||||
path = 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"]
|
[submodule "FW/leo_muziekdoos_esp32/lib/BatterySense"]
|
||||||
path = 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 =
|
lib_deps =
|
||||||
bblanchon/ArduinoJson@^6.18.5
|
bblanchon/ArduinoJson@^6.18.5
|
||||||
fastled/FastLED@^3.4.0
|
fastled/FastLED@^3.4.0
|
||||||
|
robtillaart/AS5600@^0.3.4
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
lib_ldf_mode = deep+
|
lib_ldf_mode = deep+
|
||||||
extra_scripts = ./littlefsbuilder.py
|
extra_scripts = ./littlefsbuilder.py
|
||||||
|
|||||||
@@ -103,6 +103,8 @@ void initAudio()
|
|||||||
|
|
||||||
void setAudioState(bool state)
|
void setAudioState(bool state)
|
||||||
{
|
{
|
||||||
|
if(state == audioState) return;
|
||||||
|
|
||||||
audioState = state;
|
audioState = state;
|
||||||
if (state)
|
if (state)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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(20);
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleLed(void)
|
void handleLed(void)
|
||||||
|
|||||||
@@ -10,9 +10,9 @@
|
|||||||
|
|
||||||
|
|
||||||
#define TIMEOUT_POWER (7 * 1000 * 60) // 7 minutes timeout
|
#define TIMEOUT_POWER (7 * 1000 * 60) // 7 minutes timeout
|
||||||
#define POWERBUTTONDELAY 1000
|
#define POWERBUTTONDELAY 400
|
||||||
//#define BATTERYMEASUREDELAY 60000
|
//#define BATTERYMEASUREDELAY 60000
|
||||||
#define POWERBUTTONOTADELAY 7000
|
#define POWERBUTTONOTADELAY 4000
|
||||||
#define POWEROFFOFFDELAY 3000
|
#define POWEROFFOFFDELAY 3000
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ uint16_t BatteryVoltage = 0;
|
|||||||
uint32_t BatteryWarningFirst = 0;
|
uint32_t BatteryWarningFirst = 0;
|
||||||
|
|
||||||
uint16_t HallSensor = 0;
|
uint16_t HallSensor = 0;
|
||||||
|
HALLSENSORSTATES hall_sensor_state = HALLSENSORSTATES::hall_idle;
|
||||||
|
|
||||||
uint32_t last_hall_read = 0;
|
uint32_t last_hall_read = 0;
|
||||||
uint16_t last_hall_sample = 0;
|
uint16_t last_hall_sample = 0;
|
||||||
@@ -23,6 +24,23 @@ bool hall_is_Idle = true;
|
|||||||
|
|
||||||
bool hallinitOK = false;
|
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)
|
bool getSensorInitStatus(void)
|
||||||
{
|
{
|
||||||
return hallinitOK;
|
return hallinitOK;
|
||||||
@@ -55,6 +73,7 @@ void initSensor(void)
|
|||||||
{
|
{
|
||||||
log_i("sensor init ADS1x15:");
|
log_i("sensor init ADS1x15:");
|
||||||
bool result = ADS.begin(I2C_SDA, I2C_SCL);
|
bool result = ADS.begin(I2C_SDA, I2C_SCL);
|
||||||
|
ADS.setMode(0);
|
||||||
initBattery();
|
initBattery();
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
@@ -78,11 +97,11 @@ bool CheckBattery(void)
|
|||||||
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;
|
||||||
@@ -119,62 +138,108 @@ void handleBatterySensor(void)
|
|||||||
{
|
{
|
||||||
CheckBattery();
|
CheckBattery();
|
||||||
log_i("vbatt level = %d %%", BatterySensor);
|
log_i("vbatt level = %d %%", BatterySensor);
|
||||||
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 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)
|
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);
|
||||||
|
|
||||||
switch(hall_sensor_state)
|
switch (hall_sensor_state)
|
||||||
{
|
{
|
||||||
case hall_idle:
|
case hall_idle:
|
||||||
{
|
{
|
||||||
if(int(hall_sample - last_hall_sample) > 0)
|
hall_is_Idle = true;
|
||||||
|
if (int(hall_sample - last_hall_sample) > HALLIDLETHRESHOLD)
|
||||||
{
|
{
|
||||||
hall_decrease_count = 0;
|
hall_decrease_count = 0;
|
||||||
if(hall_increase_count++ > HALLTHRESHOLD) hall_sensor_state = hall_increasing;
|
if (hall_increase_count++ > HALLIDLETHRESHOLD)
|
||||||
|
hall_sensor_state = hall_increasing;
|
||||||
}
|
}
|
||||||
else if(int(hall_sample - last_hall_sample) < 0)
|
else if (int(hall_sample - last_hall_sample) < HALLTHRESHOLD)
|
||||||
{
|
{
|
||||||
hall_increase_count = 0;
|
hall_increase_count = 0;
|
||||||
if(hall_decrease_count++ > HALLTHRESHOLD) hall_sensor_state = hall_decreasing;
|
if (hall_decrease_count++ > HALLIDLETHRESHOLD)
|
||||||
|
hall_sensor_state = hall_decreasing;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case hall_decreasing:
|
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;
|
||||||
|
}
|
||||||
|
else if (int(hall_sample - last_hall_sample) < HALLTHRESHOLD)
|
||||||
|
{
|
||||||
|
hall_increase_count = 0;
|
||||||
|
if(hall_decrease_count < HALLIDLETHRESHOLD) hall_decrease_count++;
|
||||||
|
}
|
||||||
|
else if (hall_decrease_count == 0)
|
||||||
|
{
|
||||||
|
hall_sensor_state = hall_tipover;
|
||||||
|
log_i("go to tipover");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hall_decrease_count--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case hall_tipover:
|
case hall_tipover:
|
||||||
{
|
{
|
||||||
|
// check if samples increase
|
||||||
|
// check if samples decrease
|
||||||
|
// check if samples are steady
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case hall_increasing:
|
case hall_increasing:
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
|
log_d("state: default");
|
||||||
}
|
}
|
||||||
break;
|
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;
|
// bool skipfirstSample = false;
|
||||||
// if (!last_hall_Delta)
|
// if (!last_hall_Delta)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "Arduino.h"
|
||||||
#include "ADS1X15.h"
|
#include "ADS1X15.h"
|
||||||
#include "Battery.h"
|
#include "Battery.h"
|
||||||
#include "board.h"
|
#include "board.h"
|
||||||
@@ -10,8 +11,8 @@
|
|||||||
#define VBATTMEASPRECHARGE 500
|
#define VBATTMEASPRECHARGE 500
|
||||||
#define LOWBATTPERIOD 30000
|
#define LOWBATTPERIOD 30000
|
||||||
|
|
||||||
#define HALLINTERVAL 100
|
#define HALLINTERVAL 50
|
||||||
#define HALLTHRESHOLD 5
|
#define HALLCNTTHRESHOLD 20
|
||||||
#define HALLIDLETHRESHOLD 20
|
#define HALLIDLETHRESHOLD 20
|
||||||
#define HALLIDLESAMPLES 15
|
#define HALLIDLESAMPLES 15
|
||||||
#define HALLPLAYSAMPLES 24
|
#define HALLPLAYSAMPLES 24
|
||||||
@@ -24,6 +25,7 @@ typedef enum
|
|||||||
hall_decreasing,
|
hall_decreasing,
|
||||||
}HALLSENSORSTATES;
|
}HALLSENSORSTATES;
|
||||||
|
|
||||||
|
|
||||||
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