13void SHBlockHAL::compensate_hardware_offsets(
uint32_t track_time,
uint32_t inject_time) {
15 (void)set_state(SHState::TRACK);
16 delayMicroseconds(track_time);
17 (void)set_state(SHState::INJECT);
18 delayMicroseconds(inject_time);
21metadata::eui_t blocks::SHBlock::get_entity_eui()
const {
23 return hardware->get_entity_eui();
27blocks::SHBlock::SHBlock(SHBlockHAL *hardware) : FunctionBlock(
"SH", hardware), hardware(hardware) {
28 classifier.class_enum = CLASS_;
31void blocks::SHBlock::set_state(SHState state_) { state = state_; }
33blocks::SHState blocks::SHBlock::get_state()
const {
return state; }
35void blocks::SHBlock::reset(entities::ResetAction action) {
36 if (action.has(entities::ResetAction::CIRCUIT_RESET))
37 state = SHState::INJECT;
40UnitResult blocks::SHBlock::write_to_hardware() {
return hardware->set_state(state); }
42void blocks::SHBlock::compensate_hardware_offsets(
uint32_t track_time,
uint32_t inject_time) {
43 hardware->compensate_hardware_offsets(track_time, inject_time);
44 state = SHState::INJECT;
47void SHBlock::extract(entities::ExtractVisitor &collector) {
48 Entity::extract(collector);
49 if (!collector.include_configuration())
return;
50 auto& item = collector.create(pb_Item_shift_hold_config_tag);
51 auto& sh_item = item.kind.shift_hold_config;
55 sh_item.state = pb_ShiftHoldConfig_State_TRACK;
57 case SHState::TRACK_AT_IC:
58 sh_item.state = pb_ShiftHoldConfig_State_TRACK_AT_IC;
61 sh_item.state = pb_ShiftHoldConfig_State_INJECT;
63 case SHState::GAIN_ZERO_TO_SEVEN:
64 sh_item.state = pb_ShiftHoldConfig_State_GAIN_ZERO_TO_SEVEN;
66 case SHState::GAIN_EIGHT_TO_FIFTEEN:
67 sh_item.state = pb_ShiftHoldConfig_State_GAIN_EIGHT_TO_FIFTEEN;
74ConfigResult blocks::SHBlock::config(
const pb_Item &item) {
75 if (item.which_kind != pb_Item_shift_hold_config_tag)
76 return ConfigResult::err(
"expected shift hold config");
78 auto& sh_item = item.kind.shift_hold_config;
81 switch (sh_item.state) {
82 case pb_ShiftHoldConfig_State_TRACK:
83 set_state(blocks::SHState::TRACK);
85 case pb_ShiftHoldConfig_State_TRACK_AT_IC:
86 set_state(blocks::SHState::TRACK_AT_IC);
88 case pb_ShiftHoldConfig_State_INJECT:
89 set_state(blocks::SHState::INJECT);
91 case pb_ShiftHoldConfig_State_GAIN_ZERO_TO_SEVEN:
92 set_state(blocks::SHState::GAIN_ZERO_TO_SEVEN);
94 case pb_ShiftHoldConfig_State_GAIN_EIGHT_TO_FIFTEEN:
95 set_state(blocks::SHState::GAIN_EIGHT_TO_FIFTEEN);
97 case pb_ShiftHoldConfig_State_PASSTHROUGH:
98 set_state(blocks::SHState::PASSTHROUGH);
101 return ConfigResult::err(
"Unknown target state for SH Block");
104 return ConfigResult::ok(
true);