-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
173 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include "BoxI2C.h" | ||
|
||
void BoxI2C::begin() { | ||
//Wire.begin(); //TODO! | ||
} | ||
|
||
bool BoxI2C::send_raw(uint8_t data) { | ||
if (!Wire.write(data)) { | ||
Log.error("Could not write into I2C Buffer"); | ||
return false; | ||
} | ||
return true; | ||
} | ||
bool BoxI2C::send(uint8_t address, uint8_t target_register, uint8_t data) { | ||
Wire.beginTransmission(address); | ||
if (!send_raw(target_register)) return false; | ||
if (!send_raw(data)) return false; | ||
|
||
uint8_t result = Wire.endTransmission(false); | ||
if (!result) return true; | ||
Log.error("Could not send I2C buffer, error=%i", result); | ||
} | ||
|
||
uint8_t BoxI2C::readByte(uint8_t address, uint8_t source_register) { | ||
Wire.beginTransmission(0x18); | ||
if (!send_raw(source_register)) return false; | ||
Wire.endTransmission(false); | ||
if (!Wire.requestFrom(0x18 ,1)) return false; | ||
int result = Wire.read(); | ||
//Log.info("readI2C addr=%i reg=%i result=%i", address, source_register, result); | ||
if (result == -1) return false; | ||
return (uint8_t)result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#ifndef BoxI2C_h | ||
#define BoxI2C_h | ||
|
||
#include "BaseHeader.h" | ||
#include <Wire.h> | ||
|
||
class BoxI2C { | ||
public: | ||
void | ||
begin(); | ||
|
||
bool send(uint8_t address, uint8_t target_register, uint8_t data); | ||
bool send_raw(uint8_t data); | ||
uint8_t readByte(uint8_t address, uint8_t source_register); | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,118 +1,119 @@ | ||
#include "Hackiebox.h" | ||
|
||
BoxConfig Config; | ||
BoxEvents Events; | ||
Hackiebox Box; | ||
void Hackiebox::setup() { | ||
if (!watchdog_start()) { | ||
watchdog_stop(); | ||
//reset box?! | ||
} | ||
|
||
logStreamMulti.setSlot(&logStreamSd, 0); | ||
logStreamMulti.setSlot(&logStreamSse, 1); | ||
Log.init(LOG_LEVEL_VERBOSE, 115200, &logStreamMulti); | ||
Log.info("Booting Hackiebox, Free MEM=%ib...", freeMemory()); | ||
|
||
Wire.begin(); | ||
|
||
boxPower.initPins(); | ||
boxPower.setSdPower(true); | ||
boxPower.setOtherPower(true); | ||
|
||
boxSD.begin(); | ||
Config.begin(); //SD Card needed! | ||
ConfigStruct* config = Config.get(); | ||
|
||
boxPower.begin(); | ||
boxLEDs.begin(); | ||
boxLEDs.setAll(BoxLEDs::CRGB::White); | ||
boxBattery.begin(); | ||
boxLEDs.setAll(BoxLEDs::CRGB::Orange); | ||
boxEars.begin(); | ||
boxLEDs.setAll(BoxLEDs::CRGB::Yellow); | ||
boxAccel.begin(); | ||
boxLEDs.setAll(BoxLEDs::CRGB::Pink); | ||
boxRFID.begin(); | ||
boxLEDs.setAll(BoxLEDs::CRGB::Teal); | ||
boxDAC.begin(); | ||
boxLEDs.setAll(BoxLEDs::CRGB::Fuchsia); | ||
|
||
boxCLI.begin(); | ||
|
||
boxWiFi = WrapperWiFi(config->wifi.ssid, config->wifi.password); | ||
boxWiFi.begin(); | ||
|
||
webServer = WrapperWebServer(); | ||
webServer.begin(); | ||
|
||
_threadController = ThreadController(); | ||
_threadController.add(&boxAccel); | ||
_threadController.add(&boxBattery); | ||
_threadController.add(&boxCLI); | ||
_threadController.add(&boxEars); | ||
_threadController.add(&boxLEDs); | ||
_threadController.add(&boxPower); | ||
_threadController.add(&boxWiFi); | ||
_threadController.add(&webServer); | ||
|
||
Log.info("Config: %s", Config.getAsJson().c_str()); | ||
|
||
boxAccel.onRun(ThreadCallbackHandler([&]() { boxAccel.loop(); })); | ||
boxCLI.onRun(ThreadCallbackHandler([&]() { boxCLI.loop(); })); | ||
boxDAC.onRun(ThreadCallbackHandler([&]() { boxDAC.loop(); })); | ||
boxRFID.onRun(ThreadCallbackHandler([&]() { boxRFID.loop(); })); | ||
boxPower.onRun(ThreadCallbackHandler([&]() { boxPower.loop(); })); | ||
boxLEDs.onRun(ThreadCallbackHandler([&]() { boxLEDs.loop(); })); | ||
boxBattery.onRun(ThreadCallbackHandler([&]() { boxBattery.loop(); })); | ||
boxEars.onRun(ThreadCallbackHandler([&]() { boxEars.loop(); })); | ||
boxWiFi.onRun(ThreadCallbackHandler([&]() { boxWiFi.loop(); })); | ||
webServer.onRun(ThreadCallbackHandler([&]() { webServer.loop(); })); | ||
|
||
boxBattery._batteryTestThread = EnhancedThread(ThreadCallbackHandler([&]() { boxBattery._doBatteryTestStep(); }), 10*60*1000); | ||
boxBattery._batteryTestThread.enabled = false; | ||
|
||
boxLEDs.setIdleAnimation(BoxLEDs::ANIMATION_TYPE::RAINBOW, BoxLEDs::CRGB::White); | ||
Log.info("Hackiebox started! Free MEM=%ib...", freeMemory()); | ||
} | ||
|
||
void Hackiebox::loop() { | ||
watchdog_feed(); | ||
_threadController.run(); | ||
webServer.handle(); | ||
} | ||
|
||
bool Hackiebox::watchdog_isFed() { | ||
return _watchdog_fed; | ||
} | ||
void Hackiebox::watchdog_feed() { | ||
_watchdog_fed = true; | ||
} | ||
void Hackiebox::watchdog_unfeed() { | ||
_watchdog_fed = false; | ||
} | ||
void watchdog_handler() { | ||
if (Box.watchdog_isFed()) { | ||
MAP_WatchdogIntClear(WDT_BASE); | ||
Box.watchdog_unfeed(); | ||
} | ||
} | ||
bool Hackiebox::watchdog_start() { | ||
watchdog_feed(); | ||
|
||
MAP_PRCMPeripheralClkEnable(PRCM_WDT, PRCM_RUN_MODE_CLK); | ||
MAP_WatchdogUnlock(WDT_BASE); | ||
MAP_IntPrioritySet(INT_WDT, INT_PRIORITY_LVL_1); | ||
MAP_WatchdogIntRegister(WDT_BASE, watchdog_handler); | ||
MAP_WatchdogReloadSet(WDT_BASE, 80000000*15); //15s | ||
MAP_WatchdogEnable(WDT_BASE); | ||
|
||
return MAP_WatchdogRunning(WDT_BASE); | ||
} | ||
void Hackiebox::watchdog_stop() { | ||
MAP_WatchdogUnlock(WDT_BASE); | ||
MAP_WatchdogStallDisable(WDT_BASE); | ||
MAP_WatchdogIntClear(WDT_BASE); | ||
MAP_WatchdogIntUnregister(WDT_BASE); | ||
} | ||
|
||
#include "Hackiebox.h" | ||
|
||
BoxConfig Config; | ||
BoxEvents Events; | ||
Hackiebox Box; | ||
void Hackiebox::setup() { | ||
if (!watchdog_start()) { | ||
watchdog_stop(); | ||
//reset box?! | ||
} | ||
|
||
logStreamMulti.setSlot(&logStreamSd, 0); | ||
logStreamMulti.setSlot(&logStreamSse, 1); | ||
Log.init(LOG_LEVEL_VERBOSE, 115200, &logStreamMulti); | ||
Log.info("Booting Hackiebox, Free MEM=%ib...", freeMemory()); | ||
|
||
Wire.begin(); | ||
|
||
boxPower.initPins(); | ||
boxPower.setSdPower(true); | ||
boxPower.setOtherPower(true); | ||
|
||
boxSD.begin(); | ||
Config.begin(); //SD Card needed! | ||
ConfigStruct* config = Config.get(); | ||
|
||
boxPower.begin(); | ||
boxI2C.begin(); | ||
boxLEDs.begin(); | ||
boxLEDs.setAll(BoxLEDs::CRGB::White); | ||
boxBattery.begin(); | ||
boxLEDs.setAll(BoxLEDs::CRGB::Orange); | ||
boxEars.begin(); | ||
boxLEDs.setAll(BoxLEDs::CRGB::Yellow); | ||
boxAccel.begin(); | ||
boxLEDs.setAll(BoxLEDs::CRGB::Pink); | ||
boxRFID.begin(); | ||
boxLEDs.setAll(BoxLEDs::CRGB::Teal); | ||
boxDAC.begin(); | ||
boxLEDs.setAll(BoxLEDs::CRGB::Fuchsia); | ||
|
||
boxCLI.begin(); | ||
|
||
boxWiFi = WrapperWiFi(config->wifi.ssid, config->wifi.password); | ||
boxWiFi.begin(); | ||
|
||
webServer = WrapperWebServer(); | ||
webServer.begin(); | ||
|
||
_threadController = ThreadController(); | ||
_threadController.add(&boxAccel); | ||
_threadController.add(&boxBattery); | ||
_threadController.add(&boxCLI); | ||
_threadController.add(&boxEars); | ||
_threadController.add(&boxLEDs); | ||
_threadController.add(&boxPower); | ||
_threadController.add(&boxWiFi); | ||
_threadController.add(&webServer); | ||
|
||
Log.info("Config: %s", Config.getAsJson().c_str()); | ||
|
||
boxAccel.onRun(ThreadCallbackHandler([&]() { boxAccel.loop(); })); | ||
boxCLI.onRun(ThreadCallbackHandler([&]() { boxCLI.loop(); })); | ||
boxDAC.onRun(ThreadCallbackHandler([&]() { boxDAC.loop(); })); | ||
boxRFID.onRun(ThreadCallbackHandler([&]() { boxRFID.loop(); })); | ||
boxPower.onRun(ThreadCallbackHandler([&]() { boxPower.loop(); })); | ||
boxLEDs.onRun(ThreadCallbackHandler([&]() { boxLEDs.loop(); })); | ||
boxBattery.onRun(ThreadCallbackHandler([&]() { boxBattery.loop(); })); | ||
boxEars.onRun(ThreadCallbackHandler([&]() { boxEars.loop(); })); | ||
boxWiFi.onRun(ThreadCallbackHandler([&]() { boxWiFi.loop(); })); | ||
webServer.onRun(ThreadCallbackHandler([&]() { webServer.loop(); })); | ||
|
||
boxBattery._batteryTestThread = EnhancedThread(ThreadCallbackHandler([&]() { boxBattery._doBatteryTestStep(); }), 10*60*1000); | ||
boxBattery._batteryTestThread.enabled = false; | ||
|
||
boxLEDs.setIdleAnimation(BoxLEDs::ANIMATION_TYPE::RAINBOW, BoxLEDs::CRGB::White); | ||
Log.info("Hackiebox started! Free MEM=%ib...", freeMemory()); | ||
} | ||
|
||
void Hackiebox::loop() { | ||
watchdog_feed(); | ||
_threadController.run(); | ||
webServer.handle(); | ||
} | ||
|
||
bool Hackiebox::watchdog_isFed() { | ||
return _watchdog_fed; | ||
} | ||
void Hackiebox::watchdog_feed() { | ||
_watchdog_fed = true; | ||
} | ||
void Hackiebox::watchdog_unfeed() { | ||
_watchdog_fed = false; | ||
} | ||
void watchdog_handler() { | ||
if (Box.watchdog_isFed()) { | ||
MAP_WatchdogIntClear(WDT_BASE); | ||
Box.watchdog_unfeed(); | ||
} | ||
} | ||
bool Hackiebox::watchdog_start() { | ||
watchdog_feed(); | ||
|
||
MAP_PRCMPeripheralClkEnable(PRCM_WDT, PRCM_RUN_MODE_CLK); | ||
MAP_WatchdogUnlock(WDT_BASE); | ||
MAP_IntPrioritySet(INT_WDT, INT_PRIORITY_LVL_1); | ||
MAP_WatchdogIntRegister(WDT_BASE, watchdog_handler); | ||
MAP_WatchdogReloadSet(WDT_BASE, 80000000*15); //15s | ||
MAP_WatchdogEnable(WDT_BASE); | ||
|
||
return MAP_WatchdogRunning(WDT_BASE); | ||
} | ||
void Hackiebox::watchdog_stop() { | ||
MAP_WatchdogUnlock(WDT_BASE); | ||
MAP_WatchdogStallDisable(WDT_BASE); | ||
MAP_WatchdogIntClear(WDT_BASE); | ||
MAP_WatchdogIntUnregister(WDT_BASE); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters