@@ -355,7 +355,6 @@ class ActiveMappingState : public DigitalButtonState
355355 {
356356 Released rel{ e.pressTime , e.turboTime , e.holdTime };
357357 react (rel);
358- delete _nextState;
359358 // Redirect change of state to the caller of the Sync
360359 if (e.nextState == nullptr )
361360 {
@@ -374,14 +373,14 @@ class ActiveMappingState : public DigitalButtonState
374373 pimpl ()->_masterPress = nullptr ;
375374 pimpl ()->_keyToRelease = *e.activeMapping ;
376375 pimpl ()->_nameToRelease = e.nameToRelease ;
377-
378376 }
379377 else // release diagonal
380378 {
381379 // DEBUG_LOG << "Button " << pimpl()->_id << " releases active diagonal\n";
382380 pimpl ()->ClearKey ();
383381 }
384382 pimpl ()->_press_times = e.pressTime ;
383+ delete _nextState;
385384 _nextState = e.nextState ;
386385 }
387386 }
@@ -514,7 +513,7 @@ class NoPress : public DigitalButtonState
514513 {
515514 DigitalButtonState::react (e);
516515 pimpl ()->_press_times = e.time_now ;
517- if (pimpl ()->_mapping .hasSimMappings ())
516+ if (pimpl ()->_mapping .hasSimMappings () && pimpl ()-> GetPressDurationMS (e. time_now ) < SettingsManager::getV< float >(SettingID::SIM_PRESS_WINDOW)-> value () )
518517 {
519518 changeState<WaitSim>();
520519 }
@@ -709,6 +708,35 @@ class WaitSim : public DigitalButtonState
709708 // Start counting time between two start presses
710709 changeState<DblPressStart>();
711710 }
711+ else if (pimpl ()->_mapping .hasDiagMappings ())
712+ {
713+ size_t counter = 0 ;
714+ optional<MapIterator> diag = nullopt ;
715+ for (auto btn = pimpl ()->_context ->_getMatchingDiagBtn (pimpl ()->_id , diag); btn;
716+ btn = pimpl ()->_context ->_getMatchingDiagBtn (pimpl ()->_id , diag))
717+ {
718+ // DEBUG_LOG << "Button " << pimpl()->_id << " enables diagonal press with " << btn->_id << " who is in state " << btn->getCurrentStateName() << '\n';
719+ pimpl ()->_masterPress = btn;
720+ pimpl ()->_nameToRelease = pimpl ()->_mapping .getDiagPressName ((*diag)->first );
721+ pimpl ()->_keyToRelease = (*diag)->second .value ();
722+ Sync sync;
723+ sync.nameToRelease = pimpl ()->_nameToRelease ;
724+ sync.activeMapping = &*pimpl ()->_keyToRelease ;
725+ sync.pressTime = e.time_now ;
726+ sync.holdTime = e.holdTime ;
727+ sync.turboTime = e.turboTime ;
728+ sync.dblPressWindow = e.dblPressWindow ;
729+ sync.nextState = new DiagPressMaster ();
730+ pimpl ()->_masterPress ->sendEvent (sync);
731+ ++*diag;
732+ counter++;
733+ }
734+
735+ if (counter > 0 )
736+ changeState<DiagPressSlave>();
737+ else
738+ changeState<BtnPress>();
739+ }
712740 else // Handle regular press mapping
713741 {
714742 changeState<BtnPress>();
@@ -756,6 +784,26 @@ class SimRelease : public DigitalButtonState
756784 changeState<NoPress>();
757785 pimpl ()->ClearKey ();
758786 }
787+
788+ REACT (Sync)
789+ final
790+ {
791+ if (e.nextState != nullptr && e.activeMapping != nullptr )
792+ {
793+ Released rel{ e.pressTime , e.turboTime , e.holdTime };
794+ react (rel);
795+ // Redirect change of state to the caller of the Sync
796+
797+ // Activate Diagonal
798+ // DEBUG_LOG << "Button " << pimpl()->_id << " enables active diagonal as master\n";
799+ pimpl ()->_masterPress = nullptr ;
800+ pimpl ()->_keyToRelease = *e.activeMapping ;
801+ pimpl ()->_nameToRelease = e.nameToRelease ;
802+ pimpl ()->_press_times = e.pressTime ;
803+ delete _nextState;
804+ _nextState = e.nextState ;
805+ }
806+ }
759807};
760808
761809
@@ -810,11 +858,6 @@ class DiagPressSlave : public DigitalButtonState
810858 }
811859};
812860
813- class DiagRelease : public DigitalButtonState
814- {
815- DB_CONCRETE_STATE (DiagRelease)
816- };
817-
818861class DblPressStart : public pocket_fsm ::NestedStateMachine<ActiveMappingState, DigitalButtonState>
819862{
820863 DB_CONCRETE_STATE (DblPressStart)
0 commit comments