-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathSpencer.cpp
63 lines (48 loc) · 1.3 KB
/
Spencer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "Spencer.h"
SpencerImpl Spencer;
LEDmatrixImpl LEDmatrix;
SpencerImpl::SpencerImpl()
{
}
SpencerImpl::~SpencerImpl()
{
}
void SpencerImpl::begin()
{
disableCore0WDT();
disableCore1WDT();
SPIClass spi(3);
spi.begin(18, 19, 23, FLASH_CS_PIN);
if(!SerialFlash.begin(spi, FLASH_CS_PIN)){
Serial.println("Flash fail");
return;
}
pinMode(LED_PIN, OUTPUT);
if(!LEDmatrix.begin()){
Serial.println("couldn't start matrix");
for(;;);
}
I2S* i2s = new I2S();
i2s_driver_uninstall(I2S_NUM_0); //revert wrong i2s config from esp8266audio
i2s->begin();
Playback.begin(i2s);
Recording.begin(i2s);
LoopManager::addListener(&Playback);
LoopManager::addListener(&LEDmatrix);
LoopManager::addListener(new InputGPIO());
Net.set(Settings.get().SSID, Settings.get().pass);
LoopManager::setStackSize(10240);
}
bool SpencerImpl::loadSettings(){
bool firstTime = !Settings.begin() || Settings.get().SSID[0] == 0;
if(firstTime){
Settings.reset();
Settings.get().brightnessLevel = Settings.get().volumeLevel = 1;
Settings.store();
}
uint8_t brightnessLevelValues[3] = {5, 20, 100};
float audioLevelValues[3] = {0.1, 0.4, 1.0};
LEDmatrix.setBrightness(brightnessLevelValues[Settings.get().brightnessLevel]);
Playback.setVolume(audioLevelValues[Settings.get().volumeLevel]);
return firstTime;
}