REDAC HybridController
Firmware for LUCIDAC/REDAC Teensy
Loading...
Searching...
No Matches
shblock.cpp
Go to the documentation of this file.
1// Copyright (c) 2024 anabrid GmbH
2// Contact: https://www.anabrid.com/licensing/
3//
4// SPDX-License-Identifier: MIT OR GPL-2.0-or-later
5
6#include <block/shblock.h>
7
8namespace blocks {
9
10FLASHMEM metadata::eui_t blocks::SHBlock::get_entity_eui() const {
11 if (hardware)
12 return hardware->get_entity_eui();
13 return {};
14}
15
16FLASHMEM blocks::SHBlock::SHBlock(SHBlockHAL *hardware) : FunctionBlock("SH", hardware), hardware(hardware) {}
17
18FLASHMEM void blocks::SHBlock::set_state(SHState state_) { state = state_; }
19
20FLASHMEM blocks::SHState blocks::SHBlock::get_state() const { return state; }
21
22FLASHMEM void blocks::SHBlock::reset(entities::ResetAction action) {
23 if (action.has(entities::ResetAction::CIRCUIT_RESET))
24 state = SHState::INJECT;
25}
26
27FLASHMEM utils::status blocks::SHBlock::write_to_hardware() {
28 hardware->set_state(state);
29 return utils::status::success();
30}
31
32FLASHMEM void blocks::SHBlock::compensate_hardware_offsets(uint32_t track_time, uint32_t inject_time) {
33 hardware->compensate_hardware_offsets(track_time, inject_time);
34 state = SHState::INJECT;
35}
36
37FLASHMEM utils::status blocks::SHBlock::config_self_from_json(JsonObjectConst cfg) {
38 // return utils::status("SHBlock does not accept configuration");
39
40 // FOR TESTING
41 if (cfg.containsKey("state")) {
42 if (cfg["state"] == "TRACK")
43 set_state(blocks::SHState::TRACK);
44 else if (cfg["state"] == "TRACK_AT_IC")
45 set_state(blocks::SHState::TRACK_AT_IC);
46 else if (cfg["state"] == "INJECT")
47 set_state(blocks::SHState::INJECT);
48 else if (cfg["state"] == "GAIN_ZERO_TO_SEVEN")
49 set_state(blocks::SHState::GAIN_ZERO_TO_SEVEN);
50 else if (cfg["state"] == "GAIN_EIGHT_TO_FIFTEEN")
51 set_state(blocks::SHState::GAIN_EIGHT_TO_FIFTEEN);
52 else
53 return utils::status("Unknown target state for SH Block");
54 }
55 return utils::status(0);
56}
57} // namespace blocks
uint32_t
Definition flasher.cpp:195