@@ -28,6 +28,12 @@ bool InputService::OnRegisterInputConfigsChanged(const void* data, size_t length
2828 }
2929 num_active_lift_ = 0 ;
3030
31+ // Add virtual inputs.
32+ lift_input_ = &all_inputs_.emplace_back ();
33+ lift_input_->idx = Input::VIRTUAL;
34+ lift_input_->emergency_reason = EmergencyReason::LIFT | EmergencyReason::LATCH;
35+ lift_input_->emergency_delay_ms = 10 ;
36+
3137 input_config_json_data_t json_data;
3238 json_data.callback = etl::make_delegate<InputService, &InputService::InputConfigsJsonCallback>(*this );
3339 return ProcessJson (source, json_data);
@@ -65,7 +71,7 @@ bool InputService::InputConfigsJsonCallback(lwjson_stream_parser_t* jsp, lwjson_
6571 JsonExpectTypeOrEnd (OBJECT);
6672 if (type == LWJSON_STREAM_TYPE_OBJECT) {
6773 if (all_inputs_.full ()) {
68- ULOG_ERROR (" Too many inputs (max. %d)" , all_inputs_.max_size ());
74+ ULOG_ERROR (" Too many inputs (max. %d)" , all_inputs_.max_size () - NUM_VIRTUAL_INPUTS );
6975 return false ;
7076 }
7177 data->current_input = &all_inputs_.emplace_back ();
@@ -166,7 +172,7 @@ uint32_t InputService::OnLoop(uint32_t, uint32_t) {
166172void InputService::SendStatus () {
167173 uint64_t active_inputs_mask = 0 ;
168174 for (auto & input : all_inputs_) {
169- if (input.IsActive ()) {
175+ if (input.IsActive () && input. idx != input. VIRTUAL ) {
170176 active_inputs_mask |= 1 << input.idx ;
171177 }
172178 }
@@ -184,7 +190,7 @@ void InputService::OnInputChanged(Input& input, const bool active, const uint32_
184190
185191 if ((input.emergency_reason & EmergencyReason::TILT) != 0 ) {
186192 uint8_t lift_active = active ? ++num_active_lift_ : --num_active_lift_;
187- lift_input_. Update (lift_active >= 2 );
193+ lift_input_-> Update (lift_active >= 2 );
188194 }
189195
190196 // TODO: This will be called in the middle of the driver's update loop.
@@ -219,12 +225,5 @@ etl::pair<uint16_t, uint32_t> InputService::GetEmergencyReasons(uint32_t now) {
219225 reasons |= input.emergency_reason ;
220226 }
221227 }
222-
223- if (lift_input_.IsActive ()) {
224- if (TimeoutReached (lift_input_.ActiveDuration (now), lift_input_.emergency_delay_ms * 1'000 , block_time)) {
225- reasons |= lift_input_.emergency_reason ;
226- }
227- }
228-
229228 return {reasons, block_time};
230229}
0 commit comments