29 Commits

Author SHA1 Message Date
b82f9f90a8 add ping to startuup - not working yet 2024-02-14 16:25:52 +01:00
1d7b8fb492 restore default littleFS 2024-02-14 10:18:56 +01:00
3a88dcfc07 replace littleFS with default 2024-02-14 10:09:53 +01:00
89af60bd22 replace littleFS with default 2024-02-14 10:09:40 +01:00
f17f9ddf7c update submodule paths 2024-02-10 14:50:36 +01:00
6d9b3fadd0 administratie 2023-06-04 14:42:28 +02:00
966868b531 levering 02-06-2023 2023-06-04 14:42:20 +02:00
715359f89e extend settings 2023-04-16 21:58:56 +02:00
da809f1ae4 clean up headerfile 2023-04-16 21:45:51 +02:00
d353bc4f38 fix merge issues 2023-04-16 21:44:59 +02:00
30db59d4a8 Merge branch 'as5600' 2023-04-16 21:35:19 +02:00
16995b67ef Merge branch 'as5600' of http://git.oldemans.nl/projects_leo/muziekdoos into as5600 2023-04-16 21:23:16 +02:00
8b4c00bc7f extended config 2023-04-16 21:21:05 +02:00
02a4ff420d Merge branch 'as5600' of http://git.oldemans.nl/projects_leo/muziekdoos into as5600 2023-04-16 13:54:38 +02:00
1fde3347c8 fix issues wifi fallback 2023-04-16 13:36:56 +02:00
0e02abd9c9 update submoduls 2023-01-04 20:32:21 +01:00
f45809690e update platformIO 2023-01-04 14:46:23 +01:00
8e07b6151f typo + skip battcheck 2023-01-04 12:03:11 +01:00
a27853297f added datasheet as5600 2023-01-04 11:22:50 +01:00
ab15d1ce3f refactor 2023-01-02 22:20:38 +01:00
5257cf9a31 fix statemachine bug 2023-01-02 07:53:36 +01:00
bde3daae53 optimize statemachine 2023-01-02 07:42:16 +01:00
ae2dde8e63 clean up statemachine and simplify sensor 2023-01-01 20:11:24 +01:00
01be1b6a93 added as5600 sensor readout 2023-01-01 18:16:14 +01:00
0828ced6d1 clean hw folder 2023-01-01 18:15:53 +01:00
59d6eb8dc2 update ADC submodule 2023-01-01 18:14:16 +01:00
53fbd0ebfa added submodule CAD 2023-01-01 18:13:55 +01:00
fd34ac13ca merge gitmodules 2023-01-01 08:53:20 +01:00
59519e4f55 led, sensor, power 2023-01-01 08:52:10 +01:00
31 changed files with 25183 additions and 433 deletions

30
.gitmodules vendored
View File

@@ -1,35 +1,31 @@
[submodule "FW/leo_muziekdoos_esp32/lib/ESP8266Audio"]
path = FW/leo_muziekdoos_esp32/lib/ESP8266Audio
url = http://debianvm.local:3000/libs/ESP8266Audio.git
branch = master
[submodule "FW/leo_muziekdoos_esp32/lib/littleFS_esp32"]
path = FW/leo_muziekdoos_esp32/lib/littleFS_esp32
url = http://debianvm.local:3000/libs/LittleFS_esp32
url = http://git.oldemans.nl/libs/ESP8266Audio.git
branch = master
[submodule "FW/leo_muziekdoos_esp32/lib/JCButton"]
path = FW/leo_muziekdoos_esp32/lib/JCButton
url = http://debianvm.local:3000/libs/JCButton.git
url = http://git.oldemans.nl/libs/JCButton.git
branch = master
[submodule "FW/leo_muziekdoos_esp32/lib/NDEF"]
path = FW/leo_muziekdoos_esp32/lib/NDEF
url = http://debianvm.local:3000/libs/rfid.NDEF.git
url = http://git.oldemans.nl/libs/rfid.NDEF.git
branch = master
[submodule "FW/leo_muziekdoos_esp32/lib/PN532"]
path = FW/leo_muziekdoos_esp32/lib/PN532
url = http://debianvm.local:3000/libs/rfid.PN532.git
url = http://git.oldemans.nl/libs/rfid.PN532.git
branch = master
[submodule "FW/leo_muziekdoos_esp32/lib/PN532_SPI"]
path = FW/leo_muziekdoos_esp32/lib/PN532_SPI
url = http://debianvm.local:3000/libs/rfid.PN532_SPI.git
url = http://git.oldemans.nl/libs/rfid.PN532_SPI.git
[submodule "FW/leo_muziekdoos_esp32/lib/BatterySense"]
path = FW/leo_muziekdoos_esp32/lib/BatterySense
url = http://git.oldemans.nl/libs/BatterySense.git
branch = master
[submodule "FW/leo_muziekdoos_esp32/lib/ADC_ADS1x15"]
path = FW/leo_muziekdoos_esp32/lib/ADC_ADS1x15
url = http://debianvm.local:3000/libs/ADC_ADS1X15.git
url = http://git.oldemans.nl/libs/ADC_ADS1X15.git
branch = master
[submodule "FW/leo_muziekdoos_esp32/lib/BatterySense"]
path = FW/leo_muziekdoos_esp32/lib/BatterySense
url = http://debianvm.local:3000/libs/BatterySense.git
branch = master
[submodule "CAD"]
path = CAD
url = http://debianvm.local:3000/projects_leo/muziekdooos_hardware.git
[submodule "CAD-SCH"]
path = CADSCH
url = http://git.oldemans.nl/projects_leo/muziekdooos_hardware.git
branch = master

1
CAD

Submodule CAD deleted from 04fb595533

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@@ -1,16 +1,17 @@
{
"tags": [{
"TagUID" : "B3 26 D0 15",
"audiofile" : "/Billy-Jean.mp3"
},
{
"TagUID" : "1F E8 20 00",
"audiofile" : "/Let_it_be.mp3"
},
{
"TagUID" : "23 0E 2C 19",
"audiofile" : "/ringoffire.mp3"
}],
"tags": [
{
"TagUID" : "B3 26 D0 15",
"audiofile" : "/Billy-Jean.mp3"
},
{
"TagUID" : "1F E8 20 00",
"audiofile" : "/Let_it_be.mp3"
},
{
"TagUID" : "23 0E 2C 19",
"audiofile" : "/ringoffire.mp3"
}],
"WiFi": [
{
"ssid": "poes",
@@ -19,6 +20,14 @@
{
"ssid": "wifi2",
"psk": "pass2"
}
]
}],
"AudioGain": 0.5,
"ScanTimeout": 50,
"HardwareVersion": 2,
"GameTimeout": 20000,
"PowerTimeout": 30,
"PowerOTADelay": 4000,
"Brightness": 2,
"ping": "/ping.mp3"
}

View File

@@ -8,18 +8,32 @@
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env]
build_src_filter = +<*> -<.git/> -<.svn/> -<example/> -<examples/> -<test/> -<tests/>
[env:esp32-pico]
platform = espressif32
board = m5stack-atom
#board = m5stack-atom
board = pico32
framework = arduino
lib_deps =
bblanchon/ArduinoJson@^6.18.5
fastled/FastLED@^3.4.0
monitor_speed = 115200
bblanchon/ArduinoJson@^6.20.0
fastled/FastLED@^3.5.0
#robtillaart/AS5600 @ ^0.3.4
robtillaart/AS5600 @ ^0.3.6
LITTLEFS
build_src_filter = ${env.build_src_filter}
lib_ldf_mode = deep+
extra_scripts = ./littlefsbuilder.py
build_flags =
-DHARDWARE=2
-DCORE_DEBUG_LEVEL=4
-DCORE_DEBUG_LEVEL=3
-DNDEF_DEBUG=1
-fexceptions
extra_scripts = ./littlefsbuilder.py
board_build.filesystem = littlefs
monitor_speed = 115200
#upload_protocol = esptool
upload_protocol = espota
upload_port = muziekdoos.local

View File

@@ -10,7 +10,6 @@ String nextAudioFile = "";
uint8_t n = 0;
bool audioState = false;
bool audioInitOk = false;
const char *waveFile[] =
@@ -82,7 +81,7 @@ void playSong(String filename)
}
else
{
log_e("no filenae specified");
log_e("no filename specified");
}
}
@@ -93,7 +92,7 @@ void initAudio()
delay(500);
out = new AudioOutputI2S();
out->SetPinout(I2S_BCLK, I2S_WCLK, I2S_DATA); // bclk, wclk, data
out->SetGain(AUDIOGAIN);
out->SetGain(getFloatParam("AudioGain", AUDIOGAIN));
pinMode(DAC_SDMODE, OUTPUT);
setAudioState(false);
mp3 = new AudioGeneratorMP3();
@@ -103,6 +102,8 @@ void initAudio()
void setAudioState(bool state)
{
if(state == audioState) return;
audioState = state;
if (state)
{

View File

@@ -8,12 +8,9 @@
#include "AudioOutputI2S.h"
#include "game.h"
#include "config.h"
#define AUDIOGAIN 0.5
#define AUDIONSONGS 3
#define AUDIOREPEATS 3
void initAudio(void);
void handleAudio(void);

View File

@@ -1,11 +1,11 @@
#include "config.h"
#include <vector>
#include "FS.h"
#include "LITTLEFS.h"
#include <LittleFS.h>
#include "ArduinoJson.h"
const char *tagConfigfile = "/settings.json";
DynamicJsonDocument settingsDoc(512);
DynamicJsonDocument settingsDoc(1024);
bool configInitOK = false;
struct tagConfig
@@ -48,10 +48,61 @@ String GetWifiPassword(String ssid)
return "";
}
int GetIntparam(String param, int def)
{
log_i("Get param %s",param );
if(param == "")
{
log_e("No param(%s) given", param);
return def;
}
if(!settingsDoc.containsKey(param))
{
log_e("param(%s) not found",param);
return def;
}
return settingsDoc[param];
}
float getFloatParam(String param, int def)
{
log_i("Get param %s",param );
if( param == "")
{
log_e("No param(%s) given",param);
return def;
}
if(!settingsDoc.containsKey(param))
{
log_e("param(%s) not availavle",param);
return def;
}
return settingsDoc[param];
}
String getStringParam(String param, String def)
{
log_i("Get String param %s",param );
if( param == "")
{
log_e("No param(%s) given",param);
return def;
}
if(!settingsDoc.containsKey(param))
{
log_e("param(%s) not availavle",param);
return def;
}
return settingsDoc[param];
}
void loadConfig(const char *fname)
{
log_i("config: load");
File file = LITTLEFS.open(fname);
File file = LittleFS.open(fname);
DeserializationError error = deserializeJson(settingsDoc, file);
if (error)
@@ -80,6 +131,9 @@ void loadConfig(const char *fname)
}
configInitOK = !hasError;
}
//test values
int test = GetIntparam("ScanTimeout");
log_i("retval(%i)",test);
log_i("config: load done");
}
@@ -95,6 +149,26 @@ void handleConfig(void)
{
}
bool getUIDvalid(String uid)
{
JsonArray array = settingsDoc["tags"].as<JsonArray>();
for (JsonVariant v : array)
{
String taguid((const char*)v["TagUID"]);
uint16_t result = uid.compareTo(taguid);
log_v("compare %s(config) with %s(read) = %d",taguid.c_str(), uid.c_str(), result);
if (!result)
{
String filename((const char*)v["audiofile"]);
log_i("Tag found in config");
return true;
}
}
log_e("taguid %s not found",uid.c_str() );
return false;
}
String getConfigSong(String uid)
{
JsonArray array = settingsDoc["tags"].as<JsonArray>();

View File

@@ -3,8 +3,11 @@
#include "Arduino.h"
String getConfigSong(String uid);
bool getUIDvalid(String uid);
String GetWifiPassword(String ssid);
int GetIntparam(String param, int def = -1);
float getFloatParam( String param, int def = -1);
String getStringParam(String param, String def = "error");
void initConfig(void);
void handleConfig(void);

View File

@@ -4,92 +4,174 @@
bool newState = true;
uint32_t idleTime = 0;
uint32_t gameTimeout = 0;
GamneStates gameState = GamneStates::stateInit;
static const char *Gameenum_str[]
{
"stateInit",
"stateIdle",
"stateScanning",
"stateArmed",
"stateStartPlaying",
"statePlaying",
"stateStopPlaying",
"stateStopped"
};
GameStates gameState = GameStates::stateInit;
void initGame(void)
{
gameTimeout = GetIntparam("GameTimeout", TIMEOUT_ARMED);
log_i("Game: init: done");
}
void setGameState(GamneStates newstate)
void setGameState(GameStates newstate)
{
gameState = newstate;
newState = true;
log_i("NewState = %s", StateToString(newstate).c_str());
}
void handleNewState(void)
{
if (newState)
{
log_i("ActiveState = %s" , StateToString(gameState).c_str());
newState = false;
}
}
String StateToString(GameStates gamestate)
{
try
{
return Gameenum_str[gamestate];
}
catch(const std::exception& e)
{
log_e("statestring size does not match");
return "statestringerror";
}
}
void GameStartPlayingSong(void)
{
// get filefrom config
String lastUID = getRFIDlastUID();
log_i("uid=%s", lastUID.c_str());
String nextSong = getConfigSong(lastUID);
log_i("nextSong=%s", nextSong.c_str());
playSong(nextSong);
setAudioState(true);
}
void handleGame(void)
{
switch (gameState)
{
case stateInit:
{
SetLedColor(CRGB::White);
setLedBlink(true);
if (newState)
{
log_i("activeState = Init");
newState = false;
handleNewState();
}
if (getSensorInitStatus() && getAudioInitStatus() && getRFIDInitStatus())
{
log_i("All systems init OK, Game ready");
setGameState(stateIdle);
log_i("nextState = idle");
}
}
break;
case stateIdle:
{
SetLedColor(CRGB::Purple);
setLedBlink(false);
if (newState)
{
log_i("activeState = Idle");
newState = false;
idleTime = millis();
handleNewState();
setRFIDscanState(false);
setAudioState(false);
//idleTime = millis();
}
if (getRFIDlastUID() == "")
idleTime = getLastTagTime();
if (!getRFIDlastUIDValid())
{
// no UID found, go RFID scanning
setGameState(stateScanning);
log_i("nextState = Scanning");
}
else
{
if (!hallIsIdle())
{
setGameState(stateStartPlaying);
log_i("nextState = Start playing");
}
else
{
setRFIDscanState(true);
}
// valid RFID found arm system
setGameState(stateArmed);
}
}
break;
case stateScanning:
{
SetLedColor(CRGB::Green);
setLedBlink(true);
if (newState)
{
log_i("activeState = RFID scanning");
handleNewState();
setRFIDscanState(true);
newState = false;
}
if (getRFIDlastUID() != "")
if (getRFIDlastUIDValid())
{
setGameState(stateIdle);
// valid RFID found arm system
setRFIDscanState(false);
log_i("nextState = idle");
setGameState(stateArmed);
}
}
break;
case stateStartPlaying:
case stateArmed:
{
SetLedColor(CRGB::Green);
setLedBlink(false);
if (newState)
{
log_i("activeState = startPlaying");
newState = false;
handleNewState();
setRFIDscanState(true);
idleTime = millis();
}
if (!hallIsIdle())
{
// hall has detected movement, start playing
setGameState(stateStartPlaying);
}
else
{
uint32_t now = millis();
if(now - idleTime > gameTimeout)
{
log_i("Armed timed-out, clear current UID and go back to Idle");
clearRFIDlastUID();
setGameState(stateIdle);
}
}
}
break;
case stateStartPlaying:
{
SetLedColor(CRGB::Pink);
setLedBlink(true);
if (newState)
{
handleNewState();
setRFIDscanState(false);
PowerKeepAlive();
}
if (hallIsIdle())
@@ -98,53 +180,52 @@ void handleGame(void)
}
else
{
// get filefrom config
String lastUID = getRFIDlastUID();
log_i("uid=%s", lastUID.c_str());
String nextSong = getConfigSong(lastUID);
log_i("nextSong=%s", nextSong.c_str());
playSong(nextSong);
setAudioState(true);
GameStartPlayingSong();
setGameState(statePlaying);
}
}
break;
case statePlaying:
{
SetLedColor(CRGB::Pink);
setLedBlink(false);
if (newState)
{
log_i("activeState = Playing");
newState = false;
handleNewState();
}
if (hallIsIdle())
{
setAudioState(false);
setGameState(stateStopPlaying);
}
}
break;
case stateStopPlaying:
{
SetLedColor(CRGB::Teal);
setLedBlink(true);
if (newState)
{
log_i("activeState = stopPlaying");
newState = false;
setAudioState(false);
handleNewState();
}
if (!getAudioState())
{
setAudioState(false);
setGameState(stateStopped);
}
}
break;
case stateStopped:
{
SetLedColor(CRGB::Teal);
setLedBlink(false);
if (newState)
{
log_i("activeState = stopped");
newState = false;
handleNewState();
}
if (!getAudioState())
{
setGameState(stateIdle);
@@ -153,6 +234,8 @@ void handleGame(void)
break;
default:
{
log_w("Unknown state go to Idle");
setGameState(stateIdle);
}
break;
}

View File

@@ -9,17 +9,19 @@
#include "power.h"
#define TIMEOUT_IDLE 20000
#define TIMEOUT_ARMED 20000
typedef enum{
stateInit,
stateIdle,
stateScanning,
stateArmed,
stateStartPlaying,
statePlaying,
stateStopPlaying,
stateStopped,
stateLAST
}GamneStates;
}GameStates;
void initGame(void);
void handleGame(void);
@@ -27,3 +29,6 @@ bool hallIsIdle(void);
void handleHallSensor(void);
String StateToString(GameStates state);

View File

@@ -1,5 +1,11 @@
#include "led.h"
#ifdef STEALTH
const bool LED_STEALTH = true;
#else
const bool LED_STEALTH = false;
#endif
CRGB leds[NUM_LEDS];
bool ledstate = false;
@@ -28,7 +34,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(LEDBRIGHTNESS);
FastLED.setBrightness(GetIntparam("Brightness", LEDDEFBRIGHT));
}
void handleLed(void)
@@ -56,7 +62,8 @@ void handleLed(void)
{
leds[0] = ledcolor;
}
FastLED.show();
FastLED.show();
lastLedTime = timeNow;
}
}

View File

@@ -4,11 +4,12 @@
#include "power.h"
#include "audio.h"
#include "rfid.h"
#include "config.h"
#define NUM_LEDS 1
#define LEDTIMEOUT 100
#define LEDBLINKTIME 500
#define LEDBRIGHTNESS 75
#define LEDDEFBRIGHT 20
void initLed(void);
void handleLed(void);

View File

@@ -47,6 +47,10 @@ void loop()
handleHallSensor();
handleGame();
}
else if(getPowerState() == POWERSTATES::poweringOn2)
{
handleAudio();
}
else if (getPowerState() == POWERSTATES::overTheAir2)
{
handleOta();

View File

@@ -36,6 +36,11 @@ bool OtaProcess_class::initialize(void)
m_ssid = WiFi.SSID(i);
m_psk = tmppsk;
}
else{
log_w("using fallback SSID %s", SECRET_SSID);
m_ssid = SECRET_SSID;
m_psk = SECRET_PASS;
}
log_i("[%d] %s %s (%d) [%s]", i, WiFi.SSID(i), (WiFi.encryptionType(i) == WIFI_AUTH_OPEN) ? " " : "*", WiFi.RSSI(i), (tmppsk != "")? "OK": "Not congigured");
}
}
@@ -64,10 +69,10 @@ bool OtaProcess_class::initialize(void)
case otaConnect:
{
log_i("Otastate = initialize(connect)");
uint32_t timeTemp = millis();
if (timeTemp - m_lastconnectTime > WIFICONNECTINTERVAL)
{
log_i("Otastate = initialize(connect)");
if (WiFi.status() != WL_CONNECTED)
{
log_e("Connection Failed! Retry...");
@@ -112,7 +117,7 @@ bool OtaProcess_class::initialize(void)
.onEnd([]()
{ log_i("End"); ota.m_otaState = otaDone; })
.onProgress([](unsigned int progress, unsigned int total)
{ log_i("Progress: %u%%\r", (progress / (total / 100))); ota.m_otaState = otaBusy; })
{ log_i("Progress: %u%%\r", (progress / (total / 100))); ota.m_otaState = otaBusy; PowerKeepAlive();})
.onError([](ota_error_t error)
{
log_e("Error[%u]: ", error);
@@ -130,8 +135,9 @@ bool OtaProcess_class::initialize(void)
{
log_i("Otastate = initialize(start)");
ArduinoOTA.begin();
log_i("Ota ready, IPaddress:%s", WiFi.localIP());
log_i("Ota ready, IPaddress:%s", WiFi.localIP().toString());
m_otaState = otaInitDone;
setLedBlink(true);
}
break;
case otaInitDone:

View File

@@ -7,7 +7,7 @@
#include "ArduinoOTA.h"
#include "JC_Button.h"
#include "LITTLEFS.h"
#include "LittleFS.h"
#define WIFICONNECTINTERVAL 1000
@@ -38,7 +38,7 @@ class OtaProcess_class : public processClass
public:
OtaProcess_class(uint32_t timeout):processClass(timeout){}
OTASTATES m_otaState = otaInit;
OTASTATES m_otaState = otaInit;
};

View File

@@ -109,6 +109,7 @@ void handlePowerState(void)
else
{
log_i("Release for poweron, hold for %d to OTA", (POWERBUTTONOTADELAY - buttonPower.getPressedFor()));
playSong(getStringParam("ping"));
}
if (buttonPower.pressedFor(POWERBUTTONOTADELAY))
{
@@ -121,6 +122,7 @@ void handlePowerState(void)
// init all
log_i("powerinit");
SetLedColor(CRGB::Green);
//initConfig();
powerstate = on;
}
break;

View File

@@ -7,12 +7,13 @@
#include "audio.h"
#include "ota.h"
#include "led.h"
#include "config.h"
#define TIMEOUT_POWER (7 * 1000 * 60) // 7 minutes timeout
#define POWERBUTTONDELAY 1000
#define TIMEOUT_POWER (30 * 1000 * 60) // 7 minutes timeout
#define POWERBUTTONDELAY 400
//#define BATTERYMEASUREDELAY 60000
#define POWERBUTTONOTADELAY 7000
#define POWERBUTTONOTADELAY 4000
#define POWEROFFOFFDELAY 3000
typedef enum

View File

@@ -4,6 +4,11 @@ PN532_SPI pn532spi(SPI, NFC_SS, NFC_SCK, NFC_MISO, NFC_MOSI);
NfcAdapter nfc = NfcAdapter(pn532spi);
uint32_t lastRFID = 0;
uint32_t lastRFIDlog = 0;
uint32_t lastTagTime = 0;
//settings
uint32_t scantimeout = 0;
String lastUid = "";
@@ -15,6 +20,7 @@ void initRfid()
{
log_i("RFID init:"); // shows in serial that it is ready to read
nfc.begin(true);
scantimeout = GetIntparam("ScanTimeout", RFIDTIMEOUT );
RfidinitOK = true;
log_i("RFID init: OK"); // shows in serial that it is ready to read
}
@@ -23,19 +29,30 @@ void initRfid()
void handleRfid()
{
uint32_t timeNow = millis();
if (lastRFID - timeNow > RFIDINTERVAL && RfidScanActive)
if (timeNow - lastRFID > RFIDINTERVAL && RfidScanActive)
{
log_i("scanning");
if (nfc.tagPresent(100))
if(timeNow - lastRFIDlog > RFIDLOGINTERVAL)
{
log_i("scanning");
lastRFIDlog = timeNow;
}
if (nfc.tagPresent(RFIDTIMEOUT))
{
NfcTag tag = nfc.read();
lastUid = tag.getUidString();
lastTagTime = millis();
log_i("found tag %s",lastUid.c_str());
}
lastRFID = timeNow;
}
}
uint32_t getLastTagTime(void)
{
return lastTagTime;
}
bool getRFIDInitStatus(void)
{
return RfidinitOK;
@@ -46,6 +63,15 @@ String getRFIDlastUID(void)
return lastUid;
}
bool getRFIDlastUIDValid(void)
{
if(lastUid == "")
{
return false;
}
return (getUIDvalid(lastUid));
}
void setRFIDscanState(bool state)
{
RfidScanActive = state;

View File

@@ -2,6 +2,7 @@
#include "board.h"
#include "game.h"
#include "config.h"
#include <SPI.h>
#include "PN532_SPI.h"
@@ -9,11 +10,15 @@
#include "NfcAdapter.h"
#define NDEF_SUPPORT_MIFARE_CLASSIC
#define RFIDINTERVAL 800
#define RFIDINTERVAL 200
#define RFIDLOGINTERVAL 5000
#define RFIDTIMEOUT 50
void initRfid(void);
void handleRfid(void);
bool getRFIDInitStatus(void);
String getRFIDlastUID(void);
void setRFIDscanState(bool state);
void clearRFIDlastUID(void);
bool getRFIDlastUIDValid(void);
void clearRFIDlastUID(void);
uint32_t getLastTagTime(void);

View File

@@ -1,5 +1,7 @@
#include "sensor.h"
AS5600 as5600; // use default Wire
ADS1115 ADS(0x48);
Battery battery(VBATTMIN, VBATTMAX, MEAS_ADC, &getvbatt);
@@ -11,30 +13,23 @@ 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;
bool ADSinitOK = false;
bool ASinitOK = false;
bool getSensorInitStatus(void)
{
return hallinitOK;
}
uint16_t getHall(void)
{
return HallSensor;
return (ADSinitOK & ASinitOK);
}
uint16_t getvbatt(uint8_t dummy = 0)
{
if(!ADSinitOK)
{
log_e("battery not initialized due to ADS error");
return 0;
}
int16_t readbatt = ADS.readADC(MEAS_ADC);
log_i("readvbat=%d", readbatt);
return readbatt;
@@ -45,26 +40,49 @@ bool hallIsIdle(void)
return hall_is_Idle;
}
bool initADS(void)
{
log_i("sensor init ADS1x15:");
bool result = ADS.begin(I2C_SDA, I2C_SCL);
ADS.setMode(0);
result = ADS.isConnected();
ADSinitOK = result;
if(!result)
{
log_e("Failed to init ADS1x15");
}
return result;
}
void initBattery(void)
{
if(!ADSinitOK)
{
log_e("battery not initialized due to ADS error");
return;
}
battery.onDemand(MEAS_EN, LOW);
battery.begin(VBATTREF, (R12 + R13) / R13, &sigmoidal); // R1 = 220K, R2 = 100K, factor = (R1+R2)/R2
}
bool initAS5600(void)
{
as5600.begin(); // set direction pin.
as5600.setDirection(AS5600_CLOCK_WISE); // default, just be explicit.
bool result = as5600.isConnected();
ASinitOK = result;
if(!result)
{
log_e("error initilizing AS5600");
}
return result;
}
void initSensor(void)
{
log_i("sensor init ADS1x15:");
bool result = ADS.begin(I2C_SDA, I2C_SCL);
initADS();
initBattery();
if (!result)
{
log_e("sensor init: FAIL");
}
else
{
log_i("sensor init: OK");
hallinitOK = true;
}
initAS5600();
}
bool CheckBattery(void)
@@ -108,6 +126,11 @@ bool getLowBatt(void)
void handleBatterySensor(void)
{
uint32_t timeNow = millis();
if(getAudioState())
{
return;
}
if (timeNow - lastVbatt > (VBATTINTERVALL - VBATTMEASPRECHARGE))
{
@@ -118,7 +141,7 @@ void handleBatterySensor(void)
if (timeNow - lastVbatt > VBATTINTERVALL)
{
CheckBattery();
log_i("vbatt voltage = %d mv", BatteryVoltage);
log_i("vbatt level = %d %%", BatterySensor);
if (BatterySensor > 80)
SetLedColor(CRGB::Green);
else if (BatterySensor > 50)
@@ -129,187 +152,36 @@ void handleBatterySensor(void)
}
}
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)
{
uint32_t timeNow = millis();
if (timeNow - last_hall_read > HALLINTERVAL)
if (timeNow - lastADS < ADSINTERVAL)
{
// get sample
uint16_t hall_sample = ADS.readADC(HALL_INPUT);
int hall_delta = hall_sample - last_hall_sample;
switch (hall_sensor_state)
{
case hall_idle:
{
if (hall_delta > HALLTHRESHOLD)
{
hall_decrease_count = 0;
if (hall_increase_count++ > HALLTHRESHOLD)
{
hall_sensor_state = hall_increasing;
log_i("next state = increasing");
}
}
else if (hall_delta < HALLTHRESHOLD)
{
hall_increase_count = 0;
if (hall_decrease_count++ > HALLTHRESHOLD)
{
hall_sensor_state = hall_decreasing;
log_i("next state = decreasing");
}
}
else
{
/* stay idle */
}
}
break;
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;
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;
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;
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_i("HallSensor: val=%d, delta=%d, count=%d, idle=%s\n",
hall_sample,
hall_delta,
hall_idle_count,
(hall_is_Idle ? "yes" : "no"));
last_hall_sample = hall_sample;
last_hall_read = timeNow;
//wait for timer
return;
}
lastADS = timeNow;
int angle = as5600.getCumulativePosition();
log_v("sensor angle %d", angle);
if( angle > HALLTHRESHOLD)
{
if(hall_is_Idle)
{
log_i("hall state changed to active(%i)", angle);
}
hall_is_Idle = false;
}
else
{
if(!hall_is_Idle)
{
log_i("hall state changed to idle (%i)", angle);
}
hall_is_Idle = true;
}
as5600.resetPosition();
}

View File

@@ -1,45 +1,26 @@
#pragma once
#include "Arduino.h"
#include "ADS1X15.h"
#include "Battery.h"
#include "board.h"
#include "led.h"
#include "AS5600.h"
#include "Wire.h"
#include "audio.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 HALLIDLETHRESHOLD 10
#define HALLIDLESAMPLES 15
#define HALLPLAYSAMPLES 24
typedef enum
{
hall_idle,
hall_increasing,
hall_tipover,
hall_decreasing,
hall_tipunder,
HALL_LAST
}HALLSENSORSTATES;
static String HALLSENESORSTATES_ENUM2STR[HALL_LAST]
{
"Hall Idle",
"Hall Increasing",
"Hall Tipover",
"Hall decreasing",
"Hall tipUnder"
};
void initSensor(void);
void handleBatterySensor(void);
void handleHallSensor(void);
uint16_t getHall( void );
bool hallIsIdle(void);
uint16_t getvbatt(uint8_t dummy);
@@ -47,5 +28,7 @@ bool getSensorInitStatus(void);
bool CheckBattery(void);
bool getLowBatt(void);
void readsensor(void);

View File

@@ -5,12 +5,12 @@
#include "FS.h"
#if defined ESP_ARDUINO_VERSION_VAL
#if (ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(2, 0, 0)
#if (ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(2, 0, 0))
#include <LittleFS.h>
#define ESP_V2
#endif
#else
#include <LITTLEFS.h>
#include <LittleFS.h>
#endif
#ifndef CONFIG_LITTLEFS_FOR_IDF_3_2
@@ -92,12 +92,12 @@ void readFile(fs::FS &fs, const char *path)
void initStorage()
{
if (!LITTLEFS.begin(FORMAT_LITTLEFS_IF_FAILED))
if (!LittleFS.begin(FORMAT_LITTLEFS_IF_FAILED))
{
log_e("LITTLEFS Mount Failed");
log_e("LittleFS Mount Failed");
return;
}
listDir(LITTLEFS, "/", 0);
listDir(LittleFS, "/", 0);
}
void handleStorage()

View File

@@ -1,85 +0,0 @@
{
"cod": "200",
"message": 0,
"list": [
{
"dt": 1581498000,
"main": {
"temp": 3.23,
"feels_like": -3.63,
"temp_min": 3.23,
"temp_max": 4.62,
"pressure": 1014,
"sea_level": 1014,
"grnd_level": 1010,
"humidity": 58,
"temp_kf": -1.39
},
"weather": [
{
"id": 800,
"main": "Clear",
"description": "clear sky",
"icon": "01d"
}
],
"clouds": {
"all": 0
},
"wind": {
"speed": 6.19,
"deg": 266
},
"sys": {
"pod": "d"
},
"dt_txt": "2020-02-12 09:00:00"
},
{
"dt": 1581508800,
"main": {
"temp": 6.09,
"feels_like": -1.07,
"temp_min": 6.09,
"temp_max": 7.13,
"pressure": 1015,
"sea_level": 1015,
"grnd_level": 1011,
"humidity": 48,
"temp_kf": -1.04
},
"weather": [
{
"id": 800,
"main": "Clear",
"description": "clear sky",
"icon": "01d"
}
],
"clouds": {
"all": 9
},
"wind": {
"speed": 6.64,
"deg": 268
},
"sys": {
"pod": "d"
},
"dt_txt": "2020-02-12 12:00:00"
}
],
"city": {
"id": 2643743,
"name": "London",
"coord": {
"lat": 51.5085,
"lon": -0.1257
},
"country": "GB",
"population": 1000000,
"timezone": 0,
"sunrise": 1581492085,
"sunset": 1581527294
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.