Merge branch 'master' of http://192.168.2.3/Bonobo.Git.Server/muziekdoos
This commit is contained in:
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -16,3 +16,6 @@
|
||||
[submodule "FW/leo_muziekdoos_esp32/lib/PN532_SPI"]
|
||||
path = FW/leo_muziekdoos_esp32/lib/PN532_SPI
|
||||
url = http://192.168.2.3/Bonobo.Git.Server/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/Bonobo.Git.Server/ADC_ADS1X15.git
|
||||
|
||||
@@ -25,9 +25,9 @@ Text Label 5700 2950 2 50 ~ 0
|
||||
ESP_RX1
|
||||
Text HLabel 5700 3150 2 50 Input ~ 0
|
||||
BTN_PWR
|
||||
Text HLabel 5700 3350 2 50 Output ~ 0
|
||||
Text HLabel 5700 4150 2 50 Output ~ 0
|
||||
MEAS_EN
|
||||
Text HLabel 5700 3250 2 50 Output ~ 0
|
||||
Text HLabel 5700 3050 2 50 Output ~ 0
|
||||
PW_HOLD
|
||||
Text HLabel 5700 4550 2 50 Input ~ 0
|
||||
NFC_SPI_MISO
|
||||
@@ -469,8 +469,6 @@ NoConn ~ 5200 4850
|
||||
NoConn ~ 3600 2750
|
||||
NoConn ~ 3600 2850
|
||||
NoConn ~ 3600 2950
|
||||
Wire Wire Line
|
||||
5700 3350 5200 3350
|
||||
Wire Wire Line
|
||||
2850 1600 4300 1600
|
||||
Wire Wire Line
|
||||
@@ -644,10 +642,6 @@ F 4 "Espressive" H 4400 3850 50 0001 C CNN "Manufacturer"
|
||||
1 4400 3850
|
||||
1 0 0 -1
|
||||
$EndComp
|
||||
Wire Wire Line
|
||||
5700 3150 5200 3150
|
||||
Wire Wire Line
|
||||
5700 3250 5200 3250
|
||||
Wire Wire Line
|
||||
5700 4350 5200 4350
|
||||
Wire Wire Line
|
||||
@@ -656,8 +650,7 @@ Wire Wire Line
|
||||
5700 4550 5200 4550
|
||||
Wire Wire Line
|
||||
5700 3650 5200 3650
|
||||
NoConn ~ 5200 3050
|
||||
NoConn ~ 5200 4150
|
||||
NoConn ~ 5200 3450
|
||||
$Comp
|
||||
L Device:C C22
|
||||
U 1 1 61885C4A
|
||||
@@ -785,7 +778,6 @@ Wire Wire Line
|
||||
7650 5600 7650 5450
|
||||
Wire Wire Line
|
||||
5700 3550 5200 3550
|
||||
NoConn ~ 5200 3450
|
||||
$Comp
|
||||
L Analog_ADC:ADS1114IDGS U6
|
||||
U 1 1 6177DA48
|
||||
@@ -801,4 +793,12 @@ Wire Wire Line
|
||||
9050 5500 9550 5500
|
||||
Wire Wire Line
|
||||
9450 5600 9550 5600
|
||||
Wire Wire Line
|
||||
5700 4150 5200 4150
|
||||
NoConn ~ 5200 3250
|
||||
NoConn ~ 5200 3350
|
||||
Wire Wire Line
|
||||
5200 3050 5700 3050
|
||||
Wire Wire Line
|
||||
5700 3150 5200 3150
|
||||
$EndSCHEMATC
|
||||
|
||||
@@ -787,7 +787,7 @@ F 0 "R12" H 2850 2650 50 0000 C CNN
|
||||
F 1 "10K" H 2900 2550 50 0000 C CNN
|
||||
F 2 "Resistor_SMD:R_0402_1005Metric" V 2680 2600 50 0001 C CNN
|
||||
F 3 "~" H 2750 2600 50 0001 C CNN
|
||||
F 4 "R03K3_0402" H 2750 2600 50 0001 C CNN "StockRef"
|
||||
F 4 "R10K_0402" H 2750 2600 50 0001 C CNN "StockRef"
|
||||
F 5 "2447170" H 2750 2600 50 0001 C CNN "ordercode"
|
||||
F 6 "farnell" H 2750 2600 50 0001 C CNN "supplier"
|
||||
1 2750 2600
|
||||
|
||||
@@ -804,6 +804,8 @@ F 6 "farnell" H 6200 2400 50 0001 C CNN "supplier"
|
||||
1 6200 2400
|
||||
0 1 1 0
|
||||
$EndComp
|
||||
Wire Wire Line
|
||||
7250 1150 7250 1300
|
||||
Text Label 2900 1800 1 20 ~ 0
|
||||
MCP_STAT
|
||||
Text HLabel 4250 3800 2 50 Input ~ 0
|
||||
@@ -986,19 +988,4 @@ Wire Wire Line
|
||||
8500 1450 9000 1450
|
||||
Wire Wire Line
|
||||
9000 1450 9000 1850
|
||||
$Comp
|
||||
L USB4105_REVA:USB4105_REVA J?
|
||||
U 1 1 618A8036
|
||||
P 4550 5200
|
||||
F 0 "J?" H 4550 5867 50 0000 C CNN
|
||||
F 1 "USB4105_REVA" H 4550 5776 50 0000 C CNN
|
||||
F 2 "Connector_USB:GCT_USB4105_REVA" H 4550 5200 50 0001 L BNN
|
||||
F 3 "" H 4550 5200 50 0001 L BNN
|
||||
F 4 "0.2" H 4550 5200 50 0001 L BNN "PARTREV"
|
||||
F 5 "3.31 mm" H 4550 5200 50 0001 L BNN "MAXIMUM_PACKAGE_HEIGHT"
|
||||
F 6 "Manufacturer Recommendations" H 4550 5200 50 0001 L BNN "STANDARD"
|
||||
F 7 "GCT" H 4550 5200 50 0001 L BNN "MANUFACTURER"
|
||||
1 4550 5200
|
||||
1 0 0 -1
|
||||
$EndComp
|
||||
$EndSCHEMATC
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,10 +1,10 @@
|
||||
{
|
||||
"tags": [{
|
||||
"TagUID" : "63 7E 1B 16",
|
||||
"TagUID" : "B3 26 D0 15",
|
||||
"audiofile" : "Billy-Jean.mp3"
|
||||
},
|
||||
{
|
||||
"TagUID" : "63 7E 1B 17",
|
||||
"TagUID" : "1F E8 20 00",
|
||||
"audiofile" : "Let_it_be.mp3"
|
||||
},
|
||||
{
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
test_test_test
|
||||
1
FW/leo_muziekdoos_esp32/lib/ADC_ADS1x15
Submodule
1
FW/leo_muziekdoos_esp32/lib/ADC_ADS1x15
Submodule
Submodule FW/leo_muziekdoos_esp32/lib/ADC_ADS1x15 added at aef37c6fe8
Submodule FW/leo_muziekdoos_esp32/lib/ESP8266Audio updated: dc7c4bbb17...f47f87cd5f
Submodule FW/leo_muziekdoos_esp32/lib/NDEF updated: 4d119fdce3...d8dfaa7205
Submodule FW/leo_muziekdoos_esp32/lib/littleFS_esp32 updated: 0c8b4b6b14...2f664b93e0
@@ -9,16 +9,14 @@
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[env:esp32-pico]
|
||||
platform = https://github.com/platformio/platform-espressif32.git#feature/arduino-upstream
|
||||
platform = espressif32
|
||||
board = m5stack-atom
|
||||
framework = arduino
|
||||
lib_deps =
|
||||
bblanchon/ArduinoJson@^6.18.5
|
||||
joaolopesf/SerialDebug@^0.9.82
|
||||
monitor_speed = 115200
|
||||
lib_ldf_mode = deep+
|
||||
extra_scripts = ./littlefsbuilder.py
|
||||
build_flags =
|
||||
-DHARDWARE=2
|
||||
;upload_protocol = espota
|
||||
;upload_port = 192.168.2.254
|
||||
-DCORE_DEBUG_LEVEL=3
|
||||
|
||||
@@ -6,10 +6,13 @@ AudioFileSourceLittleFS *file;
|
||||
AudioOutputI2S *out;
|
||||
|
||||
uint8_t audio_current_Song = 0;
|
||||
const char* nextAudioFile = "";
|
||||
uint8_t n = 0;
|
||||
|
||||
bool audio_start = false;
|
||||
|
||||
bool audioInitOk = false;
|
||||
|
||||
const char *waveFile[] =
|
||||
{"/ringoffire.mp3",
|
||||
"/Let_it_be.mp3",
|
||||
@@ -19,24 +22,7 @@ const char *waveFile[] =
|
||||
void MDCallback(void *cbData, const char *type, bool isUnicode, const char *string)
|
||||
{
|
||||
(void)cbData;
|
||||
Serial.printf("ID3 callback for: %s = '", type);
|
||||
|
||||
if (isUnicode)
|
||||
{
|
||||
string += 2;
|
||||
}
|
||||
|
||||
while (*string)
|
||||
{
|
||||
char a = *(string++);
|
||||
if (isUnicode)
|
||||
{
|
||||
string++;
|
||||
}
|
||||
Serial.printf("%c", a);
|
||||
}
|
||||
Serial.printf("'\n");
|
||||
Serial.flush();
|
||||
log_i("ID3 callback for: %s = '", type);
|
||||
}
|
||||
|
||||
// Called when there's a warning or error (like a buffer underflow or decode hiccup)
|
||||
@@ -47,24 +33,36 @@ void StatusCallback(void *cbData, int code, const char *string)
|
||||
char s1[64];
|
||||
strncpy_P(s1, string, sizeof(s1));
|
||||
s1[sizeof(s1) - 1] = 0;
|
||||
Serial.printf("STATUS(%s) '%d' = '%s'\n", ptr, code, s1);
|
||||
Serial.flush();
|
||||
log_i("STATUS(%s) '%d' = '%s'\n", ptr, code, s1);
|
||||
}
|
||||
|
||||
void playSong(uint8_t index)
|
||||
{
|
||||
if (index > AUDIONSONGS)
|
||||
return;
|
||||
Serial.printf("now playing %s\n", waveFile[index]);
|
||||
log_i("now playing %s\n", waveFile[index]);
|
||||
file = new AudioFileSourceLittleFS(waveFile[index]);
|
||||
id3 = new AudioFileSourceID3(file);
|
||||
id3->RegisterMetadataCB(MDCallback, (void *)"ID3TAG");
|
||||
mp3->begin(id3, out);
|
||||
}
|
||||
|
||||
void playSong(String filename)
|
||||
{
|
||||
if(filename != "")
|
||||
{
|
||||
log_i("now playing %s\n", filename.c_str());
|
||||
file = new AudioFileSourceLittleFS(filename.c_str());
|
||||
id3 = new AudioFileSourceID3(file);
|
||||
id3->RegisterMetadataCB(MDCallback, (void *)"ID3TAG");
|
||||
mp3->begin(id3, out);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void initAudio()
|
||||
{
|
||||
Serial.println("init Audio");
|
||||
log_i("init Audio");
|
||||
audioLogger = &Serial;
|
||||
delay(500);
|
||||
out = new AudioOutputI2S();
|
||||
@@ -73,28 +71,39 @@ void initAudio()
|
||||
|
||||
mp3 = new AudioGeneratorMP3();
|
||||
mp3->RegisterStatusCB(StatusCallback, (void *)"mp3");
|
||||
Serial.println("init Audio Done");
|
||||
audioInitOk = true;
|
||||
log_i("init Audio Done");
|
||||
//playSong(audio_current_Song);
|
||||
}
|
||||
|
||||
bool getAudioInitStatus(void)
|
||||
{
|
||||
return audioInitOk;
|
||||
}
|
||||
|
||||
void setAudioFileName(String filename)
|
||||
{
|
||||
nextAudioFile = filename;
|
||||
}
|
||||
|
||||
void handleAudio()
|
||||
{
|
||||
// if (hallIsIdle())
|
||||
// {
|
||||
// if (mp3->isRunning())
|
||||
// {
|
||||
// Serial.println("Audio: stop playback");
|
||||
// mp3->stop();
|
||||
// audio_start = false;
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if(!audio_start)
|
||||
// {
|
||||
// playSong(audio_current_Song);
|
||||
// audio_start = true;
|
||||
// }
|
||||
if (hallIsIdle())
|
||||
{
|
||||
if (mp3->isRunning())
|
||||
{
|
||||
log_w("Audio: stop playback");
|
||||
mp3->stop();
|
||||
audio_start = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!audio_start)
|
||||
{
|
||||
playSong(audio_current_Song);
|
||||
audio_start = true;
|
||||
}
|
||||
|
||||
if (mp3->isRunning())
|
||||
{
|
||||
@@ -104,5 +113,5 @@ void handleAudio()
|
||||
playSong(audio_current_Song);
|
||||
}
|
||||
}
|
||||
//}
|
||||
}
|
||||
}
|
||||
@@ -17,4 +17,7 @@
|
||||
|
||||
void initAudio(void);
|
||||
void handleAudio(void);
|
||||
bool getAudioInitStatus(void);
|
||||
void playSong(String filename);
|
||||
|
||||
|
||||
|
||||
@@ -18,10 +18,15 @@
|
||||
|
||||
#define PWR_HOLD 4
|
||||
#define PWR_BTN 5
|
||||
#define MEAS_EN 12
|
||||
#define MEAS_ADC 35 //ADC1_CH7
|
||||
#define MEAS_EN 22
|
||||
|
||||
#define HALL_INPUT 36 //ADC1_CH0
|
||||
#define I2C_SDA 33
|
||||
#define I2C_SCL 32
|
||||
#define MEAS_ADC 1 //ADC1_CH7
|
||||
|
||||
#define HALL_INPUT 0 //ADC1_CH0
|
||||
|
||||
#define LED_PIN 12
|
||||
#endif
|
||||
|
||||
#if HARDWARE == 1
|
||||
|
||||
@@ -5,8 +5,11 @@
|
||||
#include "ArduinoJson.h"
|
||||
|
||||
const char *tagConfigfile = "/tagconfig.json";
|
||||
DynamicJsonDocument tagDoc(512);
|
||||
|
||||
struct tagConfig {
|
||||
bool configInitOK = false;
|
||||
struct tagConfig
|
||||
{
|
||||
char filename[64];
|
||||
char tagID[64];
|
||||
};
|
||||
@@ -15,28 +18,67 @@ std::vector<tagConfig> tags;
|
||||
|
||||
void loadConfig(const char *fname)
|
||||
{
|
||||
Serial.println("config: load");
|
||||
log_i("config: load");
|
||||
File file = LITTLEFS.open(fname);
|
||||
StaticJsonDocument<512> doc;
|
||||
DeserializationError error = deserializeJson(doc, file);
|
||||
if (error)
|
||||
Serial.println(F("Failed to read file"));
|
||||
|
||||
serializeJsonPretty(doc, Serial);
|
||||
Serial.println("config: load done");
|
||||
|
||||
DeserializationError error = deserializeJson(tagDoc, file);
|
||||
if (error)
|
||||
{
|
||||
log_e("Failed to deserialize err=%s", error.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
serializeJsonPretty(tagDoc, Serial);
|
||||
|
||||
JsonArray array = tagDoc["tags"].as<JsonArray>();
|
||||
log_i("JsonArray size = %d", array.size());
|
||||
bool hasError = false;
|
||||
for (JsonVariant v : array)
|
||||
{
|
||||
if (!v.containsKey("TagUID"))
|
||||
{
|
||||
log_e("key TAGUID not found");
|
||||
hasError = true;
|
||||
}
|
||||
if (!v.containsKey("audiofile"))
|
||||
{
|
||||
log_e("Key: audiofile not found");
|
||||
hasError = true;
|
||||
}
|
||||
}
|
||||
configInitOK = !hasError;
|
||||
}
|
||||
log_i("config: load done");
|
||||
}
|
||||
|
||||
void initConfig(void)
|
||||
{
|
||||
Serial.println("config: init");
|
||||
log_i("config: init start");
|
||||
|
||||
loadConfig(tagConfigfile);
|
||||
Serial.println("config: init done");
|
||||
|
||||
log_i("config: init done");
|
||||
}
|
||||
|
||||
void handleConfig(void)
|
||||
{
|
||||
}
|
||||
|
||||
String getConfigSong(String uid)
|
||||
{
|
||||
JsonArray array = tagDoc["tags"].as<JsonArray>();
|
||||
|
||||
const char* filename = "";
|
||||
|
||||
for (JsonVariant v : array)
|
||||
{
|
||||
const char *taguid = v["TagUID"];
|
||||
if (!strcmp(uid.c_str(), taguid))
|
||||
{
|
||||
filename = v["audiofile"];
|
||||
String retval(filename);
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
log_e("taguid %s not found",uid );
|
||||
return "";
|
||||
}
|
||||
@@ -6,22 +6,127 @@ uint32_t last_hall_read;
|
||||
uint16_t last_hall_sample;
|
||||
uint8_t hall_idle_count;
|
||||
bool hall_is_Idle = true;
|
||||
bool newState = true;
|
||||
uint32_t idleTime = 0;
|
||||
|
||||
GamneStates gameState = GamneStates::stateInit;
|
||||
|
||||
void initGame(void)
|
||||
{
|
||||
printlnI("Game: init");
|
||||
pinMode(HALL_INPUT, ANALOG);
|
||||
//analogReadResolution(10);
|
||||
analogSetAttenuation(ADC_11db);
|
||||
printlnI("Game: init: done");
|
||||
log_i("Game: init: done");
|
||||
}
|
||||
|
||||
void setState(GamneStates newstate)
|
||||
{
|
||||
gameState = newstate;
|
||||
newState = true;
|
||||
}
|
||||
|
||||
void handleGame(void)
|
||||
{
|
||||
switch (gameState)
|
||||
{
|
||||
case stateInit:
|
||||
{
|
||||
if(newState)
|
||||
{
|
||||
log_i("activeState = Init");
|
||||
newState = false;
|
||||
}
|
||||
if (getSensorInitStatus() && getAudioInitStatus() && getRFIDInitStatus())
|
||||
{
|
||||
setState(stateIdle);
|
||||
log_i("nextState = idle");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case stateIdle:
|
||||
{
|
||||
uint32_t timeNow = millis();
|
||||
if(newState)
|
||||
{
|
||||
log_i("activeState = Idle");
|
||||
newState = false;
|
||||
idleTime = millis();
|
||||
}
|
||||
|
||||
if (getRFIDlastUID() == "")
|
||||
{
|
||||
setState(stateScanning);
|
||||
log_i("nextState = Scanning");
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!hallIsIdle())
|
||||
{
|
||||
setState(stateStartPlaying);
|
||||
log_i("nextState = Start playing");
|
||||
}
|
||||
if(timeNow - idleTime > TIMEOUT_IDLE)
|
||||
{
|
||||
clearRFIDlastUID();
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case stateScanning:
|
||||
{
|
||||
if(newState)
|
||||
{
|
||||
log_i("activeState = RFID scanning");
|
||||
setRFIDscanState(true);
|
||||
newState = false;
|
||||
}
|
||||
|
||||
if (getRFIDlastUID() != "")
|
||||
{
|
||||
setState(stateIdle);
|
||||
setRFIDscanState(false);
|
||||
log_i("nextState = idle");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case stateStartPlaying:
|
||||
{
|
||||
if(newState)
|
||||
{
|
||||
log_i("activeState = startPlaying");
|
||||
newState = false;
|
||||
}
|
||||
setState(statePlaying);
|
||||
|
||||
}
|
||||
break;
|
||||
case statePlaying:
|
||||
{
|
||||
}
|
||||
break;
|
||||
case stateStopPlaying:
|
||||
{
|
||||
}
|
||||
break;
|
||||
case stateStopped:
|
||||
{
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool hallIsIdle(void)
|
||||
{
|
||||
return hall_is_Idle;
|
||||
}
|
||||
|
||||
void handleHallSensor(void)
|
||||
{
|
||||
uint32_t timeNow = millis();
|
||||
if (timeNow - last_hall_read > HALLINTERVAL)
|
||||
{
|
||||
uint16_t hall_sample = analogRead(HALL_INPUT);
|
||||
uint16_t hall_sample = getHall();
|
||||
uint16_t hall_delta = (last_hall_sample > hall_sample) ? (last_hall_sample - hall_sample) : (hall_sample - last_hall_sample);
|
||||
if (hall_delta > HALLIDLETHRESHOLD)
|
||||
{
|
||||
@@ -29,6 +134,7 @@ void handleGame(void)
|
||||
{
|
||||
hall_is_Idle = false;
|
||||
hall_idle_count = HALLPLAYSAMPLES;
|
||||
log_i("Game: playing");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -40,24 +146,18 @@ void handleGame(void)
|
||||
if (hall_idle_count == 0)
|
||||
{
|
||||
hall_is_Idle = true;
|
||||
printlnI("Game: Idle");
|
||||
}
|
||||
else
|
||||
{
|
||||
hall_idle_count--;
|
||||
}
|
||||
}
|
||||
Serial.printf("HallSensor: val=%d, delta=%d, count=%d, idle=%s\n",
|
||||
hall_sample,
|
||||
hall_delta,
|
||||
hall_idle_count,
|
||||
(hall_is_Idle? "yes":"no"));
|
||||
log_v("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;
|
||||
}
|
||||
}
|
||||
|
||||
bool hallIsIdle(void)
|
||||
{
|
||||
return hall_is_Idle;
|
||||
}
|
||||
@@ -2,13 +2,31 @@
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "board.h"
|
||||
#include "SerialDebug.h"
|
||||
#include "sensor.h"
|
||||
#include "audio.h"
|
||||
#include "rfid.h"
|
||||
|
||||
#define HALLINTERVAL 100
|
||||
#define HALLIDLETHRESHOLD 4
|
||||
#define HALLIDLESAMPLES 4
|
||||
#define HALLPLAYSAMPLES 8
|
||||
|
||||
#define TIMEOUT_IDLE 20000
|
||||
|
||||
typedef enum{
|
||||
stateInit,
|
||||
stateIdle,
|
||||
stateScanning,
|
||||
stateStartPlaying,
|
||||
statePlaying,
|
||||
stateStopPlaying,
|
||||
stateStopped,
|
||||
stateLAST
|
||||
}GamneStates;
|
||||
|
||||
void initGame(void);
|
||||
void handleGame(void);
|
||||
bool hallIsIdle(void);
|
||||
|
||||
void handleHallSensor(void);
|
||||
|
||||
|
||||
@@ -1,37 +1,44 @@
|
||||
#include <Arduino.h>
|
||||
#include "SerialDebug.h"
|
||||
|
||||
#include "power.h"
|
||||
#include "storage.h"
|
||||
#include "audio.h"
|
||||
#include "rfid.h"
|
||||
#include "sensor.h"
|
||||
#include "config.h"
|
||||
#include "ota.h"
|
||||
#include "game.h"
|
||||
|
||||
uint32_t looptime = 0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
initPower();
|
||||
Serial.begin(115200);
|
||||
delay(2000);
|
||||
Serial.setDebugOutput(true);
|
||||
log_i("muziekdoos v2");
|
||||
Serial.flush();
|
||||
delay(1000);
|
||||
|
||||
initStorage();
|
||||
initConfig();
|
||||
//initOta();
|
||||
initAudio();
|
||||
initRfid();
|
||||
|
||||
initSensor();
|
||||
initGame();
|
||||
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
debugHandle();
|
||||
looptime = millis();
|
||||
|
||||
handleAudio();
|
||||
//handleRfid();
|
||||
//handleGame();
|
||||
handleRfid();
|
||||
handleSensor();
|
||||
handleGame();
|
||||
handlePower();
|
||||
//handleOta();
|
||||
log_v("main: looptime = %d", millis() - looptime);
|
||||
}
|
||||
|
||||
@@ -1,62 +1,68 @@
|
||||
#include "power.h"
|
||||
|
||||
|
||||
bool powerbutton_released = true;
|
||||
|
||||
#define DR_REG_RTCCNTL_BASE 0x3ff48000
|
||||
#define RTC_CNTL_BROWN_OUT_REG (DR_REG_RTCCNTL_BASE + 0xd4)
|
||||
|
||||
|
||||
uint32_t PowerLastKeepAlive = 0;
|
||||
|
||||
void initPowerOn(void)
|
||||
{
|
||||
//disable brownout
|
||||
//WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); //disable brownout detector
|
||||
if(digitalRead(PWR_BTN))
|
||||
// disable brownout
|
||||
if (digitalRead(PWR_BTN))
|
||||
{
|
||||
//enable LDO
|
||||
// enable LDO
|
||||
pinMode(PWR_HOLD, OUTPUT);
|
||||
pinMode(PWR_BTN, INPUT);
|
||||
digitalWrite(PWR_HOLD, HIGH);
|
||||
powerbutton_released = false;
|
||||
|
||||
//dac_sdMode
|
||||
// dac_sdMode
|
||||
pinMode(DAC_SDMODE, OUTPUT);
|
||||
digitalWrite(DAC_SDMODE, HIGH);
|
||||
//powerstate = poweringOn;
|
||||
//buttonPower.begin();
|
||||
// powerstate = poweringOn;
|
||||
// buttonPower.begin();
|
||||
}
|
||||
else
|
||||
{
|
||||
ESP.deepSleep(10000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void powerDown(uint16_t delayMs)
|
||||
{
|
||||
log_w("poweringDown!");
|
||||
digitalWrite(PWR_HOLD, LOW);
|
||||
delay(delayMs);
|
||||
ESP.restart();
|
||||
}
|
||||
|
||||
void initPower(void)
|
||||
{
|
||||
printlnI(F("Power: init"));
|
||||
log_i("Power: init");
|
||||
initPowerOn();
|
||||
printlnI(F("Power: init: done"));
|
||||
|
||||
log_i("Power: init: done");
|
||||
}
|
||||
|
||||
void handlePower(void)
|
||||
{
|
||||
if(digitalRead(PWR_BTN) && powerbutton_released)
|
||||
if (digitalRead(PWR_BTN) && powerbutton_released)
|
||||
{
|
||||
printlnA("poweringDown!");
|
||||
debugHandle();
|
||||
while(digitalRead(PWR_BTN)) {}
|
||||
digitalWrite(PWR_HOLD, LOW);
|
||||
delay(1000);
|
||||
ESP.restart();
|
||||
while (digitalRead(PWR_BTN))
|
||||
{
|
||||
}
|
||||
powerDown(1000);
|
||||
}
|
||||
else{
|
||||
else
|
||||
{
|
||||
powerbutton_released = true;
|
||||
}
|
||||
// check timeout
|
||||
if ( millis() - PowerLastKeepAlive > TIMEOUT_POWER)
|
||||
{
|
||||
powerDown(1000);
|
||||
}
|
||||
}
|
||||
|
||||
void PowerKeepAlive(void)
|
||||
{
|
||||
PowerLastKeepAlive = millis();
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
#include "board.h"
|
||||
#include "Arduino.h"
|
||||
#include "SerialDebug.h"
|
||||
|
||||
#define TIMEOUT_POWER (5 * 1000 * 60) //5minutes timeout
|
||||
|
||||
void initPower(void);
|
||||
void handlePower(void);
|
||||
@@ -5,27 +5,55 @@ NfcAdapter nfc = NfcAdapter(pn532spi);
|
||||
|
||||
uint32_t lastRFID = 0;
|
||||
|
||||
String lastUid = "";
|
||||
|
||||
bool RfidinitOK = false;
|
||||
bool RfidScanActive = false;
|
||||
|
||||
//*****************************************************************************************//
|
||||
void initRfid()
|
||||
{
|
||||
// int8_t sck=-1, int8_t miso=-1, int8_t mosi=-1, int8_t ss=-1);
|
||||
log_i("RFID init:"); // shows in serial that it is ready to read
|
||||
nfc.begin(true);
|
||||
Serial.println(F("rfid init done")); // shows in serial that it is ready to read
|
||||
RfidinitOK = true;
|
||||
log_i("RFID init: OK"); // shows in serial that it is ready to read
|
||||
}
|
||||
|
||||
//*****************************************************************************************//
|
||||
void handleRfid()
|
||||
{
|
||||
uint32_t timeNow = millis();
|
||||
if (lastRFID - timeNow > RFIDINTERVAL)
|
||||
if (lastRFID - timeNow > RFIDINTERVAL && RfidScanActive)
|
||||
{
|
||||
|
||||
log_i("scanning");
|
||||
if (nfc.tagPresent())
|
||||
{
|
||||
NfcTag tag = nfc.read();
|
||||
String uid = tag.getUidString();
|
||||
Serial.println(uid);
|
||||
lastUid = tag.getUidString();
|
||||
log_i("found tag %s",lastUid.c_str());
|
||||
}
|
||||
lastRFID = timeNow;
|
||||
}
|
||||
}
|
||||
|
||||
bool getRFIDInitStatus(void)
|
||||
{
|
||||
return RfidinitOK;
|
||||
}
|
||||
|
||||
String getRFIDlastUID(void)
|
||||
{
|
||||
return lastUid;
|
||||
}
|
||||
|
||||
void setRFIDscanState(bool state)
|
||||
{
|
||||
RfidScanActive = state;
|
||||
}
|
||||
|
||||
void clearRFIDlastUID( void)
|
||||
{
|
||||
log_i("cleard lasttag");
|
||||
lastUid = "";
|
||||
}
|
||||
//*****************************************************************************************//
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "board.h"
|
||||
#include "game.h"
|
||||
|
||||
#include <SPI.h>
|
||||
#include "PN532_SPI.h"
|
||||
@@ -11,4 +12,8 @@
|
||||
#define RFIDINTERVAL 200
|
||||
|
||||
void initRfid(void);
|
||||
void handleRfid(void);
|
||||
void handleRfid(void);
|
||||
bool getRFIDInitStatus(void);
|
||||
String getRFIDlastUID(void);
|
||||
void setRFIDscanState(bool state);
|
||||
void clearRFIDlastUID(void);
|
||||
66
FW/leo_muziekdoos_esp32/src/sensor.cpp
Normal file
66
FW/leo_muziekdoos_esp32/src/sensor.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
#include "sensor.h"
|
||||
|
||||
ADS1115 ADS(0x48);
|
||||
uint32_t lastADS = 0;
|
||||
uint32_t lastVbatt = 0;
|
||||
|
||||
uint16_t BatterySensor = 0;
|
||||
uint16_t HallSensor = 0;
|
||||
|
||||
bool hallinitOK = false;
|
||||
|
||||
void initSensor(void)
|
||||
{
|
||||
log_i("sensor init ADS1x15:");
|
||||
bool result = ADS.begin(I2C_SDA, I2C_SCL);
|
||||
pinMode(MEAS_EN, OUTPUT);
|
||||
if (!result)
|
||||
{
|
||||
log_e("sensor init: FAIL");
|
||||
}
|
||||
else
|
||||
{
|
||||
log_i("sensor init: OK");
|
||||
hallinitOK = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool getSensorInitStatus(void)
|
||||
{
|
||||
return hallinitOK;
|
||||
}
|
||||
|
||||
void handleSensor(void)
|
||||
{
|
||||
uint32_t timeNow = millis();
|
||||
if (lastADS - timeNow > ADSINTERVAL)
|
||||
{
|
||||
HallSensor = ADS.readADC(HALL_INPUT);
|
||||
lastADS = timeNow;
|
||||
}
|
||||
|
||||
if (lastVbatt - timeNow > VBATTINTERVALL - VBATTMEASPRECHARGE)
|
||||
{
|
||||
digitalWrite(MEAS_EN, HIGH);
|
||||
log_v("precharge vbatt measurement");
|
||||
}
|
||||
|
||||
if (lastVbatt - timeNow > VBATTINTERVALL)
|
||||
{
|
||||
BatterySensor = ADS.readADC(MEAS_ADC);
|
||||
digitalWrite(MEAS_EN, LOW);
|
||||
lastVbatt = timeNow;
|
||||
}
|
||||
|
||||
log_v("Read sensor: Hall=%d, vbatt=%d", HallSensor, BatterySensor);
|
||||
}
|
||||
|
||||
uint16_t getHall(void)
|
||||
{
|
||||
return HallSensor;
|
||||
}
|
||||
|
||||
uint16_t getvbatt(void)
|
||||
{
|
||||
return BatterySensor;
|
||||
}
|
||||
15
FW/leo_muziekdoos_esp32/src/sensor.h
Normal file
15
FW/leo_muziekdoos_esp32/src/sensor.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "ADS1X15.h"
|
||||
#include "board.h"
|
||||
|
||||
#define ADSINTERVAL 250
|
||||
#define VBATTINTERVALL 1000
|
||||
#define VBATTMEASPRECHARGE 250
|
||||
|
||||
|
||||
void initSensor(void);
|
||||
void handleSensor(void);
|
||||
uint16_t getHall( void );
|
||||
uint16_t getvbatt( void );
|
||||
bool getSensorInitStatus(void);
|
||||
@@ -3,11 +3,15 @@
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "FS.h"
|
||||
#if ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(2, 0, 0)
|
||||
#include <littleFS.h>
|
||||
#else
|
||||
#include <LITTLEFS.h>
|
||||
#endif
|
||||
|
||||
#if defined ESP_ARDUINO_VERSION_VAL
|
||||
#if (ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(2, 0, 0)
|
||||
#include <LittleFS.h>
|
||||
#define ESP_V2
|
||||
#endif
|
||||
#else
|
||||
#include <LITTLEFS.h>
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_LITTLEFS_FOR_IDF_3_2
|
||||
#include <time.h>
|
||||
@@ -17,17 +21,17 @@
|
||||
|
||||
void listDir(fs::FS &fs, const char *dirname, uint8_t levels)
|
||||
{
|
||||
Serial.printf("Listing directory: %s\r\n", dirname);
|
||||
log_i("Listing directory: %s\r\n", dirname);
|
||||
|
||||
File root = fs.open(dirname);
|
||||
if (!root)
|
||||
{
|
||||
Serial.println("- failed to open directory");
|
||||
log_e("- failed to open directory");
|
||||
return;
|
||||
}
|
||||
if (!root.isDirectory())
|
||||
{
|
||||
Serial.println(" - not a directory");
|
||||
log_e(" - not a directory");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -36,15 +40,14 @@ void listDir(fs::FS &fs, const char *dirname, uint8_t levels)
|
||||
{
|
||||
if (file.isDirectory())
|
||||
{
|
||||
Serial.print(" DIR : ");
|
||||
log_i(" DIR : ");
|
||||
|
||||
#ifdef CONFIG_LITTLEFS_FOR_IDF_3_2
|
||||
Serial.println(file.name());
|
||||
#else
|
||||
Serial.print(file.name());
|
||||
time_t t = file.getLastWrite();
|
||||
struct tm *tmstruct = localtime(&t);
|
||||
Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec);
|
||||
log_i("FILE: %s LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n",file.name(), (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec);
|
||||
#endif
|
||||
|
||||
if (levels)
|
||||
@@ -54,17 +57,13 @@ void listDir(fs::FS &fs, const char *dirname, uint8_t levels)
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.print(" FILE: ");
|
||||
Serial.print(file.name());
|
||||
Serial.print(" SIZE: ");
|
||||
|
||||
#ifdef CONFIG_LITTLEFS_FOR_IDF_3_2
|
||||
Serial.println(file.size());
|
||||
#else
|
||||
Serial.print(file.size());
|
||||
time_t t = file.getLastWrite();
|
||||
struct tm *tmstruct = localtime(&t);
|
||||
Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec);
|
||||
log_i(" FILE: %s, SIZE: %d LAST WRITE: %d-%02d-%02d %02d:%02d:%02d" ,file.name(), file.size(), (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec);
|
||||
#endif
|
||||
}
|
||||
file = root.openNextFile();
|
||||
@@ -74,16 +73,16 @@ void listDir(fs::FS &fs, const char *dirname, uint8_t levels)
|
||||
|
||||
void readFile(fs::FS &fs, const char *path)
|
||||
{
|
||||
Serial.printf("Reading file: %s\r\n", path);
|
||||
log_i("Reading file: %s\r\n", path);
|
||||
|
||||
File file = fs.open(path);
|
||||
if (!file || file.isDirectory())
|
||||
{
|
||||
Serial.println("- failed to open file for reading");
|
||||
log_e("- failed to open file for reading");
|
||||
return;
|
||||
}
|
||||
|
||||
Serial.println("- read from file:");
|
||||
log_i("- read from file:");
|
||||
while (file.available())
|
||||
{
|
||||
Serial.write(file.read());
|
||||
@@ -95,7 +94,7 @@ void initStorage()
|
||||
{
|
||||
if (!LITTLEFS.begin(FORMAT_LITTLEFS_IF_FAILED))
|
||||
{
|
||||
Serial.println("LITTLEFS Mount Failed");
|
||||
log_e("LITTLEFS Mount Failed");
|
||||
return;
|
||||
}
|
||||
listDir(LITTLEFS, "/", 0);
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "SerialDebug.h"
|
||||
|
||||
|
||||
void initStorage();
|
||||
Reference in New Issue
Block a user