Skip to content

Commit

Permalink
Merge pull request #20 from toniebox-reverse-engineering/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
SciLor committed Jul 20, 2021
2 parents 52639e6 + 74d37d1 commit e7bfc0d
Show file tree
Hide file tree
Showing 18 changed files with 135 additions and 139 deletions.
6 changes: 3 additions & 3 deletions BoxAccelerometer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ void BoxAccelerometer::begin() {
digitalWrite(62, HIGH);

setInterval(250);
Log.info("Initialize Accelerometer...");
Log.info("Init Accelerometer...");

if (!_accel.begin())
Log.error("... not found!");
Log.error("...not found!");

_accel.setupPL();

Expand All @@ -30,7 +30,7 @@ void BoxAccelerometer::begin() {
_accel.writeRegister(CTRL_REG5, 0x40); //Original 0x40
_accel.writeRegister(CTRL_REG1, 0x03); //Original 0x03

Log.info("... initialized");
Log.info("...done");
}

void BoxAccelerometer::loop() {
Expand Down
12 changes: 6 additions & 6 deletions BoxBattery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void BoxBattery::logBatteryStatus() {
int voltageNum = voltageDec / 100;
voltageDec = voltageDec - voltageNum * 100;

Log.info("Battery Status:");
Log.info("Battery Stats:");
Log.info(" Charging: %T", isChargerConnected());
Log.info(" ADC Raw: %c", getBatteryAdcRaw());
Log.info(" Estimated Voltage: %d.%s%dV", voltageNum, (voltageDec<10) ? "0": "", voltageDec);
Expand Down Expand Up @@ -123,11 +123,11 @@ void BoxBattery::_doBatteryTestStep() {
file.writeString("\r\n");
file.close();
} else {
Log.error("Could not write battery logfile %", _batteryTestFilename);
Log.error("Couldn't write log %", _batteryTestFilename);
}
}
void BoxBattery::startBatteryTest() {
Log.info("Starting battery test...");
Log.info("Start battery test...");

_batteryTestThread.enabled = true;
_batteryTestStartMillis = millis();
Expand All @@ -152,14 +152,14 @@ void BoxBattery::startBatteryTest() {

_batteryTestThread.run();
} else {
Log.error("Could not initialize battery logfile %s", _batteryTestFilename);
Log.error("Couldn't init battery log %s", _batteryTestFilename);
_batteryTestThread.enabled = false;
}
}
void BoxBattery::stopBatteryTest() {
if (!_batteryTestThread.enabled)
return;
Log.info("Stopping battery test...");
Log.info("Stop battery test...");
_batteryTestThread.enabled = false;
_doBatteryTestStep();
FileFs file;
Expand All @@ -172,7 +172,7 @@ void BoxBattery::stopBatteryTest() {
file.writeString("\r\n");
file.close();
} else {
Log.error("Could not write battery logfile %s", _batteryTestFilename);
Log.error("Couldn't write battery log %s", _batteryTestFilename);
_batteryTestThread.enabled = false;
}
}
Expand Down
30 changes: 15 additions & 15 deletions BoxCLI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void BoxCLI::begin() {
cmdRFID.addFlagArg("o/verwrite");

cmdLoad = cli.addCmd("load");
cmdLoad.setDescription(" Shows the current load of all threads");
cmdLoad.setDescription(" Shows the load of all threads");
cmdLoad.addArg("n/ame", "");
cmdLoad.addArg("p/ointer", "0");
cmdLoad.addFlagArg("r/eset");
Expand Down Expand Up @@ -145,14 +145,14 @@ void BoxCLI::execI2C() {

tmpNum = parseNumber(saddress);
if (tmpNum > 127) {
Log.error("address must be lower than 128");
Log.error("address must be <128");
return;
}
addr = (uint8_t)tmpNum;

tmpNum = parseNumber(sregister);
if (tmpNum > 255) {
Log.error("register must be lower than 256");
Log.error("register must be <256");
return;
}
regi = (uint8_t)tmpNum;
Expand All @@ -163,7 +163,7 @@ void BoxCLI::execI2C() {
if (read) {
String soutput = c.getArg("output").getValue();
if (!(soutput == "x" || soutput == "X" || soutput == "i" || soutput == "b" || soutput == "B")) {
Log.error("Allowed values for output are: x, X, i, b, B");
Log.error("Allowed output values are: x, X, i, b, B");
return;
}

Expand All @@ -187,10 +187,10 @@ void BoxCLI::execI2C() {
while(isspace((unsigned char)*value)) value++;
tmpNum = parseNumber(value, &newVal);
if (tmpNum > 255) {
Log.error("value must be lower than 256");
Log.error("value must be <256");
return;
} else if (value == newVal) {
Log.error("Could not parse part \"%s\" of \"%s\"", value, svalue.c_str());
Log.error("Couldn't parse part \"%s\" of \"%s\"", value, svalue.c_str());
return;
}
uint8_t data = (uint8_t)tmpNum;
Expand All @@ -212,15 +212,15 @@ void BoxCLI::execSpiRFID() {
String sregister = c.getArg("register").getValue();
tmpNum = parseNumber(sregister);
if (tmpNum > 255) {
Log.error("register must be lower than 256");
Log.error("register must be <256");
return;
}
uint8_t regi = (uint8_t)tmpNum;

String svalue = c.getArg("value").getValue();
tmpNum = parseNumber(svalue);
if (tmpNum > 255) {
Log.error("value/command must be lower than 256");
Log.error("value/command must be <256");
return;
}
uint8_t value = (uint8_t)tmpNum;
Expand Down Expand Up @@ -250,15 +250,15 @@ void BoxCLI::execBeep() {
String sid = c.getArg("midi-id").getValue();
tmpNum = parseNumber(sid);
if (tmpNum > 127) {
Log.error("midi-id must be lower than 128");
Log.error("midi-id must be <128");
return;
}
uint8_t id = (uint8_t)tmpNum;

String slength = c.getArg("length").getValue();
tmpNum = parseNumber(slength);
if (tmpNum > 65535) {
Log.error("length must be lower than 65.536");
Log.error("length must be <65.536");
return;
}
uint16_t length = (uint16_t)tmpNum;
Expand Down Expand Up @@ -309,7 +309,7 @@ void BoxCLI::execLoad() {
unsigned long pointer = parseNumber(pointerStr);

if (name != "") {
Log.info("Thread statistics for Threads starting with \"%s\"", name.c_str());
Log.info("Statistics for Threads starting with \"%s\"", name.c_str());
Log.println("---");
for (uint8_t i = 0; i < Box.threadController.size(); i++) {
EnhancedThread* thread = (EnhancedThread*)Box.threadController.get(i);
Expand All @@ -321,7 +321,7 @@ void BoxCLI::execLoad() {
Box.delayTask(1);
}
} else if (pointer > 0) {
Log.info("Thread statistics for Threads with pointer=%i", pointer);
Log.info("Statistics for Threads with pointer=%i", pointer);
Log.println("---");
for (uint8_t i = 0; i < Box.threadController.size(); i++) {
EnhancedThread* thread = (EnhancedThread*)Box.threadController.get(i);
Expand All @@ -333,7 +333,7 @@ void BoxCLI::execLoad() {
}
Box.delayTask(1);
} else {
Log.info("Thread statistics for all %i Threads", Box.threadController.size(false)); //TODO ThreadController
Log.info("Statistics for all %i Threads", Box.threadController.size(false)); //TODO ThreadController
Log.println("---");
for (uint8_t i = 0; i < Box.threadController.size(); i++) {
EnhancedThread* thread = (EnhancedThread*)Box.threadController.get(i);
Expand All @@ -344,7 +344,7 @@ void BoxCLI::execLoad() {
}
}

if (reset) Log.info("All stats of selected threads are reset.");
if (reset) Log.info("All stats of selected threads reset.");
}

void BoxCLI::execI2S() {
Expand Down Expand Up @@ -427,7 +427,7 @@ void BoxCLI::execAudio() {
Log.info("Max Samplerate is set to %ihz", Box.boxDAC.audioOutputResample->GetMaxRate());
}
if (buffer == 0) {
Log.info("Additional buffering disabled.");
Log.info("Additional buffering off");
Box.boxDAC.audioOutput = Box.boxDAC.audioOutputResample;
} else if (buffer > 0) {
if (buffer <= freeHeapMemory() / 2) {
Expand Down
28 changes: 10 additions & 18 deletions BoxConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ void BoxConfig::read() {
}
file.close();
if (!setFromJson(json)) {
Log.error("Could not read config file %s, try to recreate it.", CONFIG_SD_PATH);
Log.error("Couldn't read cfg file %s, recreating it", CONFIG_SD_PATH);
write();
}
} else {
Log.error("Could not read config file %s, try to recreate it.", CONFIG_SD_PATH);
Log.error("Couldn't read cfg file %s, recreating it", CONFIG_SD_PATH);
write();
}
}
void BoxConfig::write() {
String json = getAsJson();
_json = getAsJson();
FileFs file;
if (file.open(CONFIG_SD_PATH, FA_CREATE_ALWAYS | FA_WRITE)) {
file.writeString((char*)json.c_str());
file.writeString((char*)_json.c_str());
file.close();
} else {
Log.error("Could not write config file %", CONFIG_SD_PATH);
Log.error("Couldn't write cfg file %", CONFIG_SD_PATH);
}
}

Expand All @@ -48,8 +48,6 @@ ConfigStruct* BoxConfig::get() {

String BoxConfig::getAsJson() {
StaticJsonDocument<BOXCONFIG_JSON_SIZE> doc;
String json;

doc["version"] = _config.version;

JsonObject batteryDoc = doc.createNestedObject("battery");
Expand All @@ -73,13 +71,13 @@ String BoxConfig::getAsJson() {
JsonObject logDoc = doc.createNestedObject("log");
ConfigLog* logCfg = &_config.log;
logDoc["sdLog"] = logCfg->sdLog;
/*

JsonObject miscDoc = doc.createNestedObject("misc");
ConfigMisc* miscCfg = &_config.misc;
miscDoc["autodump"] = miscCfg->autodump;
*/
serializeJson(doc, json);
return json;

serializeJson(doc, _json);
return _json;
}
bool BoxConfig::setFromJson(String json) {
StaticJsonDocument<BOXCONFIG_JSON_SIZE> doc;
Expand Down Expand Up @@ -114,11 +112,9 @@ bool BoxConfig::setFromJson(String json) {
ConfigLog* logCfg = &_config.log;
logCfg->sdLog = logDoc["sdLog"].as<bool>();

/*
JsonObject miscDoc = doc["misc"];
ConfigMisc* miscCfg = &_config.misc;
miscCfg->autodump = logDoc["autodump"].as<bool>();
*/
miscCfg->autodump = miscDoc["autodump"].as<bool>();

// Convert old config version to latest one.
if (_config.version != CONFIG_ACTIVE_VERSION) {
Expand All @@ -127,15 +123,11 @@ bool BoxConfig::setFromJson(String json) {
batteryCfg->criticalAdc = batteryDoc["minimalAdc"].as<uint16_t>();
batteryCfg->lowAdc = batteryCfg->criticalAdc + 100;
_config.version = 3;
write();
break;
/*
case 3:
miscCfg->autodump = false;
_config.version = 4;
write();
break;
*/
default:
_initializeConfig();
write();
Expand Down
5 changes: 3 additions & 2 deletions BoxConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include "BoxSD.h"


#define BOXCONFIG_JSON_SIZE 489
//{"version":255,"battery":{"voltageFactor":4294967295,"voltageChargerFactor":4294967295,"lowAdc":65535,"criticalAdc":65535,"sleepMinutes":255},"buttonEars":{"longPressMs":65535,"veryLongPressMs":65535},"wifi":{"ssid":"12345678901234567890123456789012","password":"1234567890123456789012345678901234567890123456789012345678901234"},"log":{"sdLog":false}}
#define BOXCONFIG_JSON_SIZE 515
//{"version":255,"battery":{"voltageFactor":4294967295,"voltageChargerFactor":4294967295,"lowAdc":65535,"criticalAdc":65535,"sleepMinutes":255},"buttonEars":{"longPressMs":65535,"veryLongPressMs":65535},"wifi":{"ssid":"12345678901234567890123456789012","password":"1234567890123456789012345678901234567890123456789012345678901234"},"log":{"sdLog":false},"misc":{"autodump":false}}
//Size from https://arduinojson.org/v6/assistant/

class BoxConfig {
Expand All @@ -22,6 +22,7 @@ class BoxConfig {

ConfigStruct* get();
private:
String _json;
ConfigStruct _config;

void _initializeConfig();
Expand Down
24 changes: 12 additions & 12 deletions BoxDAC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@

void BoxDAC::logDmaIrqChanges() {
if (lastDmaIRQcount != dmaIRQcount) {
Log.info("***dmaIRQcount=%i", dmaIRQcount);
Log.info("*dmaIRQcount=%i", dmaIRQcount);
lastDmaIRQcount = dmaIRQcount;
}
if (lastPriIndexRx != priIndexRx) {
Log.info("***priIndexRx=%i", priIndexRx);
Log.info("*priIndexRx=%i", priIndexRx);
lastPriIndexRx = priIndexRx;
}
if (lastAltIndexRx != altIndexRx) {
Log.info("***altIndexRx=%i", altIndexRx);
Log.info("*altIndexRx=%i", altIndexRx);
lastAltIndexRx = altIndexRx;
}

if (lastDmaBufferFilled != dmaBufferFilled) {
Log.info("***dmaBufferFilled=%i", dmaBufferFilled);
Log.info("*dmaBufferFilled=%i", dmaBufferFilled);
lastDmaBufferFilled = dmaBufferFilled;
}
if (lastDmaBufferEmpty != dmaBufferEmpty) {
Log.info("***dmaBufferEmpty=%i", dmaBufferEmpty);
Log.info("*dmaBufferEmpty=%i", dmaBufferEmpty);
lastDmaBufferEmpty = dmaBufferEmpty;
}
}
Expand All @@ -40,7 +40,7 @@ void dma_irq() {
}

void BoxDAC::begin() {
Log.info("Initialize DAC...");
Log.info("Init DAC...");
audioBuffer.init();
audioBuffer.logState();

Expand Down Expand Up @@ -122,7 +122,7 @@ void BoxDAC::begin() {
send(ADDR::PAGE_CONTROL, PAGE::SERIAL_IO);
send(ADDR_P0_SERIAL::DAC_VOL_CTRL, 0x00);

Log.info("...initialized");
Log.info("...done");

//samSay("Hackiebox by Team Revvox!");
}
Expand Down Expand Up @@ -175,7 +175,7 @@ void BoxDAC::opusTest() {
Log.info("Needed heap %ib", opus_decoder_get_size(channels));
decoder = opus_decoder_create(16000, channels, &error);
if (error != OPUS_OK) {
Log.error("Could not create OPUS Decoder error=%i", error);
Log.error("Couldn't create OPUS Decoder error=%i", error);
return;
}
Box.boxPower.feedSleepTimer();
Expand Down Expand Up @@ -272,7 +272,7 @@ bool BoxDAC::_playWAV(const char* path) {
audioSource = new AudioFileSourceFatFs(path);

if (!audioGenerator->begin(audioSource, audioOutput)) {
Log.error("Could not play wav?!");
Log.error("Couldn't play wav?!");
return false;
}
Log.info("WAV file loaded...");
Expand Down Expand Up @@ -530,7 +530,7 @@ void BoxDAC::samSay(const char *text, enum ESP8266SAM::SAMVoice voice, uint8_t s

audioOutput->SetRate(samplerate);
#else
Log.error("Text-To-Speech is not active (FEATURE_FLAG_TEXT2SPEECH not set)");
Log.error("Text-To-Speech off (FEATURE_FLAG_TEXT2SPEECH not set)");
#endif
}

Expand Down Expand Up @@ -581,7 +581,7 @@ bool BoxDAC::increaseVolume() {
Box.delayTask(50);
beepRaw(0x30F9, 0x763F, 0x000140); //16kHz
//beepMidi(84,50,true);
Log.info("Maximum volume reached.");
Log.info("Max volume reached");
}
logVolume();
return result;
Expand All @@ -599,7 +599,7 @@ bool BoxDAC::decreaseVolume() {
Box.delayTask(50);
beepRaw(0x0F0A, 0x7F1A, 0x000140); //16kHz
//beepMidi(62, 50, true);
Log.info("Minimal volume reached.");
Log.info("Min volume reached");
}
logVolume();
return result;
Expand Down

0 comments on commit e7bfc0d

Please sign in to comment.