-
Notifications
You must be signed in to change notification settings - Fork 0
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
20 changed files
with
601 additions
and
217 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,92 @@ | ||
#pragma once | ||
|
||
#include "kaskas/components/clock.hpp" | ||
#include "kaskas/components/relay.hpp" | ||
#include "kaskas/component.hpp" | ||
#include "kaskas/events.hpp" | ||
#include "kaskas/io/clock.hpp" | ||
#include "kaskas/io/relay.hpp" | ||
#include "kaskas/subsystems/fluidsystem.hpp" | ||
#include "kaskas/subsystems/growlights.hpp" | ||
#include "kaskas/subsystems/ui.hpp" | ||
#include "kaskas/subsystems/ventilation.hpp" | ||
|
||
#include <spine/core/exception.hpp> | ||
#include <spine/core/time.hpp> | ||
#include <spine/eventsystem/eventsystem.hpp> | ||
#include <spine/platform/hal.hpp> | ||
#include <spine/structure/pointer.hpp> | ||
#include <spine/structure/vector.hpp> | ||
|
||
using Event = spn::core::Event; | ||
using EventSystem = spn::core::EventSystem; | ||
#include <AH/STL/vector> | ||
namespace kaskas { | ||
|
||
using spn::core::Event; | ||
using spn::core::EventSystem; | ||
using spn::structure::Vector; | ||
|
||
class KasKas { | ||
public: | ||
struct Config { | ||
EventSystem::Config esc_cfg; | ||
Growlights::Config growlights_cfg; | ||
Fluidsystem::Config fluidsystem_cfg; | ||
UI::Config ui_cfg; | ||
uint16_t component_cap = 1; | ||
}; | ||
|
||
public: | ||
explicit KasKas(Config& cfg) | ||
: _cfg(cfg), // | ||
_evsys({cfg.esc_cfg}), // | ||
_growlights({&_evsys, cfg.growlights_cfg}), // | ||
_fluidsystem(&_evsys, cfg.fluidsystem_cfg), // | ||
_ui(&_evsys, cfg.ui_cfg) {} | ||
_components(std::vector<std::unique_ptr<Component>>()) {} | ||
KasKas(const KasKas& other) = delete; | ||
KasKas(KasKas&& other) = delete; | ||
KasKas& operator=(const KasKas&) = delete; | ||
KasKas& operator=(const KasKas&&) = delete; | ||
|
||
~KasKas() = default; | ||
|
||
int setup() { | ||
_growlights.initialize(); | ||
_fluidsystem.initialize(); | ||
_ui.initialize(); | ||
int initialize() { | ||
// set the global exception handler; | ||
spn::core::set_machine_exception_handler(new KasKasExceptionHandler{*this}); | ||
|
||
// initialize all components | ||
for (const auto& component : _components) { | ||
component->initialize(); | ||
} | ||
_evsys.trigger(_evsys.event(Events::WakeUp, time_s(0), Event::Data())); | ||
return 0; | ||
} | ||
|
||
void hotload_component(std::unique_ptr<Component> component) { | ||
// | ||
component->attach_event_system(&_evsys); | ||
_components.emplace_back(std::move(component)); | ||
} | ||
|
||
EventSystem& evsys() { return _evsys; }; | ||
|
||
int loop() { | ||
_evsys.loop(); | ||
return 0; | ||
} | ||
|
||
private: | ||
Config _cfg; | ||
EventSystem _evsys; | ||
class KasKasExceptionHandler final : public spn::core::ExceptionHandler { | ||
public: | ||
KasKasExceptionHandler(KasKas& kaskas) : _kk(kaskas) {} | ||
|
||
void handle_exception(const Exception& exception) override { | ||
// | ||
DBGF("KasKasExceptionHandler: Handling exception: %s", exception.error_type()); | ||
for (auto& sf : _kk._components) { | ||
sf->safe_shutdown(Component::State::CRITICAL); | ||
} | ||
} | ||
|
||
private: | ||
const KasKas& _kk; | ||
}; | ||
|
||
private: | ||
Growlights _growlights; | ||
Fluidsystem _fluidsystem; | ||
UI _ui; | ||
Config _cfg; | ||
EventSystem _evsys; | ||
std::vector<std::unique_ptr<Component>> _components; | ||
}; | ||
} // namespace kaskas |
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,25 @@ | ||
#pragma once | ||
|
||
#include <spine/eventsystem/eventsystem.hpp> | ||
|
||
namespace kaskas { | ||
|
||
using spn::core::EventHandler; | ||
using spn::core::EventSystem; | ||
|
||
class Component : public EventHandler { | ||
public: | ||
enum class State { SAFE, CRITICAL }; | ||
|
||
public: | ||
explicit Component() : Component(nullptr) {} | ||
explicit Component(EventSystem* event_system) : EventHandler(event_system) {} | ||
|
||
// virtual Component& operator=(Component&& other) {} | ||
virtual void initialize() { assert(!"Virtual base function called"); } | ||
virtual void safe_shutdown(State state = State::SAFE) { assert(!"Virtual base function called"); } | ||
|
||
private: | ||
}; | ||
|
||
} // namespace kaskas |
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,2 @@ | ||
#pragma once | ||
|
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
File renamed without changes.
File renamed without changes.
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,2 @@ | ||
#pragma once | ||
|
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.