update
This commit is contained in:
@@ -14,9 +14,11 @@ board = m5stack-atom
|
|||||||
framework = arduino
|
framework = arduino
|
||||||
lib_deps =
|
lib_deps =
|
||||||
bblanchon/ArduinoJson@^6.18.5
|
bblanchon/ArduinoJson@^6.18.5
|
||||||
|
fastled/FastLED@^3.4.0
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
lib_ldf_mode = deep+
|
lib_ldf_mode = deep+
|
||||||
extra_scripts = ./littlefsbuilder.py
|
extra_scripts = ./littlefsbuilder.py
|
||||||
build_flags =
|
build_flags =
|
||||||
-DHARDWARE=2
|
-DHARDWARE=2
|
||||||
-DCORE_DEBUG_LEVEL=3
|
-DCORE_DEBUG_LEVEL=4
|
||||||
|
-DNDEF_DEBUG=1
|
||||||
@@ -94,7 +94,8 @@ void initAudio()
|
|||||||
out = new AudioOutputI2S();
|
out = new AudioOutputI2S();
|
||||||
out->SetPinout(I2S_BCLK, I2S_WCLK, I2S_DATA); // bclk, wclk, data
|
out->SetPinout(I2S_BCLK, I2S_WCLK, I2S_DATA); // bclk, wclk, data
|
||||||
out->SetGain(AUDIOGAIN);
|
out->SetGain(AUDIOGAIN);
|
||||||
|
pinMode(DAC_SDMODE, OUTPUT);
|
||||||
|
digitalWrite(DAC_SDMODE, HIGH);
|
||||||
mp3 = new AudioGeneratorMP3();
|
mp3 = new AudioGeneratorMP3();
|
||||||
audioInitOk = true;
|
audioInitOk = true;
|
||||||
log_i("init Audio Done");
|
log_i("init Audio Done");
|
||||||
|
|||||||
@@ -69,9 +69,9 @@ String getConfigSong(String uid)
|
|||||||
for (JsonVariant v : array)
|
for (JsonVariant v : array)
|
||||||
{
|
{
|
||||||
String taguid((const char*)v["TagUID"]);
|
String taguid((const char*)v["TagUID"]);
|
||||||
uint16_t result = uid.compareTo(taguid)
|
uint16_t result = uid.compareTo(taguid);
|
||||||
|
|
||||||
log_v("compare %s(config) with %s(read) = %d",taguid.c_Str(), uid.c_Str(), result);
|
log_v("compare %s(config) with %s(read) = %d",taguid.c_str(), uid.c_str(), result);
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
String filename((const char*)v["audiofile"]);
|
String filename((const char*)v["audiofile"]);
|
||||||
|
|||||||
@@ -58,9 +58,9 @@ void handleGame(void)
|
|||||||
setGameState(stateStartPlaying);
|
setGameState(stateStartPlaying);
|
||||||
log_i("nextState = Start playing");
|
log_i("nextState = Start playing");
|
||||||
}
|
}
|
||||||
if (timeNow - idleTime > TIMEOUT_IDLE)
|
else
|
||||||
{
|
{
|
||||||
clearRFIDlastUID();
|
setRFIDscanState(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -88,6 +88,7 @@ void handleGame(void)
|
|||||||
{
|
{
|
||||||
log_i("activeState = startPlaying");
|
log_i("activeState = startPlaying");
|
||||||
newState = false;
|
newState = false;
|
||||||
|
setRFIDscanState(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hallIsIdle())
|
if (hallIsIdle())
|
||||||
|
|||||||
57
FW/leo_muziekdoos_esp32/src/led.cpp
Normal file
57
FW/leo_muziekdoos_esp32/src/led.cpp
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
#include "led.h"
|
||||||
|
|
||||||
|
CRGB leds[NUM_LEDS];
|
||||||
|
|
||||||
|
bool ledstate = false;
|
||||||
|
uint32_t lastLedTime = 0;
|
||||||
|
|
||||||
|
void initLed(void)
|
||||||
|
{
|
||||||
|
FastLED.addLeds<SK6812, LED_PIN, GRB>(leds, NUM_LEDS); // GRB ordering is typical
|
||||||
|
FastLED.setBrightness(80);
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleLed(void)
|
||||||
|
{
|
||||||
|
uint32_t timeNow = millis();
|
||||||
|
if (timeNow - lastLedTime > LEDTIMEOUT)
|
||||||
|
{
|
||||||
|
if (ledstate)
|
||||||
|
{
|
||||||
|
if (getPowerState() == POWERSTATES::on)
|
||||||
|
{
|
||||||
|
if(getAudioState())
|
||||||
|
{
|
||||||
|
leds[0] = CRGB::Purple;
|
||||||
|
}
|
||||||
|
else if( getRFIDlastUID() != "")
|
||||||
|
{
|
||||||
|
leds[0] = CRGB::Yellow;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
leds[0] = CRGB::Green;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (getPowerState() == POWERSTATES::poweringOn2)
|
||||||
|
{
|
||||||
|
leds[0] = CRGB::Blue;
|
||||||
|
}
|
||||||
|
else if (getPowerState() == POWERSTATES::poweringOff2)
|
||||||
|
{
|
||||||
|
leds[0] = CRGB::Orange;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
leds[0] = CRGB::Red;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
leds[0] = CRGB::Black;
|
||||||
|
}
|
||||||
|
FastLED.show();
|
||||||
|
ledstate = !ledstate;
|
||||||
|
lastLedTime = timeNow;
|
||||||
|
}
|
||||||
|
}
|
||||||
12
FW/leo_muziekdoos_esp32/src/led.h
Normal file
12
FW/leo_muziekdoos_esp32/src/led.h
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <FastLED.h>
|
||||||
|
#include "board.h"
|
||||||
|
#include "power.h"
|
||||||
|
#include "audio.h"
|
||||||
|
#include "rfid.h"
|
||||||
|
|
||||||
|
#define NUM_LEDS 1
|
||||||
|
#define LEDTIMEOUT 500
|
||||||
|
|
||||||
|
void initLed(void);
|
||||||
|
void handleLed(void);
|
||||||
@@ -8,6 +8,7 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "ota.h"
|
#include "ota.h"
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
#include "led.h"
|
||||||
|
|
||||||
uint32_t looptime = 0;
|
uint32_t looptime = 0;
|
||||||
|
|
||||||
@@ -26,6 +27,7 @@ void setup()
|
|||||||
initAudio();
|
initAudio();
|
||||||
initRfid();
|
initRfid();
|
||||||
initSensor();
|
initSensor();
|
||||||
|
initLed();
|
||||||
initGame();
|
initGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,6 +36,7 @@ void loop()
|
|||||||
looptime = millis();
|
looptime = millis();
|
||||||
|
|
||||||
handlePower();
|
handlePower();
|
||||||
|
handleLed();
|
||||||
|
|
||||||
if (getPowerState() == POWERSTATES::on)
|
if (getPowerState() == POWERSTATES::on)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -85,10 +85,12 @@ bool OtaProcess_class::initialize(void)
|
|||||||
case otaInitDone:
|
case otaInitDone:
|
||||||
{
|
{
|
||||||
setProcessState(processIdle);
|
setProcessState(processIdle);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OtaProcess_class::idle(void)
|
void OtaProcess_class::idle(void)
|
||||||
@@ -98,7 +100,7 @@ void OtaProcess_class::idle(void)
|
|||||||
log_i("Otastate = Idle");
|
log_i("Otastate = Idle");
|
||||||
m_newState = false;
|
m_newState = false;
|
||||||
}
|
}
|
||||||
if (m_otaState = otaInitDone)
|
if (m_otaState == otaInitDone)
|
||||||
{
|
{
|
||||||
ArduinoOTA.handle();
|
ArduinoOTA.handle();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,8 +43,10 @@ void powerOn(void)
|
|||||||
void powerOff(void)
|
void powerOff(void)
|
||||||
{
|
{
|
||||||
log_w("poweringDown!");
|
log_w("poweringDown!");
|
||||||
|
digitalWrite(DAC_SDMODE, LOW);
|
||||||
digitalWrite(PWR_HOLD, LOW);
|
digitalWrite(PWR_HOLD, LOW);
|
||||||
delay(1000);
|
delay(1000);
|
||||||
|
ESP.restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool measureBattery(void)
|
bool measureBattery(void)
|
||||||
@@ -146,6 +148,7 @@ void handlePowerState(void)
|
|||||||
if (buttonPower.pressedFor(POWERBUTTONDELAY))
|
if (buttonPower.pressedFor(POWERBUTTONDELAY))
|
||||||
{
|
{
|
||||||
powerstate = poweringOff2;
|
powerstate = poweringOff2;
|
||||||
|
setAudioState(false);
|
||||||
log_w("poweringoff: 3/3 ==> powerOff");
|
log_w("poweringoff: 3/3 ==> powerOff");
|
||||||
}
|
}
|
||||||
else if (buttonPower.pressedFor(500))
|
else if (buttonPower.pressedFor(500))
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include "JC_Button.h"
|
#include "JC_Button.h"
|
||||||
#include "Battery.h"
|
#include "Battery.h"
|
||||||
#include "sensor.h"
|
#include "sensor.h"
|
||||||
|
#include "audio.h"
|
||||||
|
|
||||||
|
|
||||||
#define TIMEOUT_POWER (5 * 1000 * 60) //5minutes timeout
|
#define TIMEOUT_POWER (5 * 1000 * 60) //5minutes timeout
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ void handleRfid()
|
|||||||
if (lastRFID - timeNow > RFIDINTERVAL && RfidScanActive)
|
if (lastRFID - timeNow > RFIDINTERVAL && RfidScanActive)
|
||||||
{
|
{
|
||||||
log_i("scanning");
|
log_i("scanning");
|
||||||
if (nfc.tagPresent())
|
if (nfc.tagPresent(100))
|
||||||
{
|
{
|
||||||
NfcTag tag = nfc.read();
|
NfcTag tag = nfc.read();
|
||||||
lastUid = tag.getUidString();
|
lastUid = tag.getUidString();
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
#include "NfcAdapter.h"
|
#include "NfcAdapter.h"
|
||||||
|
|
||||||
#define NDEF_SUPPORT_MIFARE_CLASSIC
|
#define NDEF_SUPPORT_MIFARE_CLASSIC
|
||||||
#define RFIDINTERVAL 200
|
#define RFIDINTERVAL 800
|
||||||
|
|
||||||
void initRfid(void);
|
void initRfid(void);
|
||||||
void handleRfid(void);
|
void handleRfid(void);
|
||||||
|
|||||||
@@ -7,9 +7,10 @@ uint32_t lastVbatt = 0;
|
|||||||
uint16_t BatterySensor = 0;
|
uint16_t BatterySensor = 0;
|
||||||
uint16_t HallSensor = 0;
|
uint16_t HallSensor = 0;
|
||||||
|
|
||||||
uint32_t last_hall_read;
|
uint32_t last_hall_read=0;
|
||||||
uint16_t last_hall_sample;
|
uint16_t last_hall_sample=0;
|
||||||
uint8_t hall_idle_count;
|
uint16_t last_hall_Delta=0;
|
||||||
|
uint8_t hall_idle_count=0;
|
||||||
bool hall_is_Idle = true;
|
bool hall_is_Idle = true;
|
||||||
|
|
||||||
bool hallinitOK = false;
|
bool hallinitOK = false;
|
||||||
@@ -38,11 +39,6 @@ bool getSensorInitStatus(void)
|
|||||||
void handleSensor(void)
|
void handleSensor(void)
|
||||||
{
|
{
|
||||||
uint32_t timeNow = millis();
|
uint32_t timeNow = millis();
|
||||||
if (lastADS - timeNow > ADSINTERVAL)
|
|
||||||
{
|
|
||||||
HallSensor = ADS.readADC(HALL_INPUT);
|
|
||||||
lastADS = timeNow;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lastVbatt - timeNow > VBATTINTERVALL - VBATTMEASPRECHARGE)
|
if (lastVbatt - timeNow > VBATTINTERVALL - VBATTMEASPRECHARGE)
|
||||||
{
|
{
|
||||||
@@ -81,15 +77,26 @@ void handleHallSensor(void)
|
|||||||
uint32_t timeNow = millis();
|
uint32_t timeNow = millis();
|
||||||
if (timeNow - last_hall_read > HALLINTERVAL)
|
if (timeNow - last_hall_read > HALLINTERVAL)
|
||||||
{
|
{
|
||||||
uint16_t hall_sample = getHall();
|
uint16_t hall_sample = ADS.readADC(HALL_INPUT);
|
||||||
|
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);
|
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)
|
||||||
|
{
|
||||||
|
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");
|
log_i("Game: playing, delta = %d",hall_delta);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,12 +3,12 @@
|
|||||||
#include "ADS1X15.h"
|
#include "ADS1X15.h"
|
||||||
#include "board.h"
|
#include "board.h"
|
||||||
|
|
||||||
#define ADSINTERVAL 250
|
#define ADSINTERVAL 100
|
||||||
#define VBATTINTERVALL 1000
|
#define VBATTINTERVALL 1000
|
||||||
#define VBATTMEASPRECHARGE 250
|
#define VBATTMEASPRECHARGE 250
|
||||||
|
|
||||||
#define HALLINTERVAL 100
|
#define HALLINTERVAL 100
|
||||||
#define HALLIDLETHRESHOLD 4
|
#define HALLIDLETHRESHOLD 5
|
||||||
#define HALLIDLESAMPLES 4
|
#define HALLIDLESAMPLES 4
|
||||||
#define HALLPLAYSAMPLES 8
|
#define HALLPLAYSAMPLES 8
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user