@@ -57,23 +57,33 @@ class WindowManager
57
57
58
58
struct Cover
59
59
{
60
- void Init (chip::EndpointId endpoint);
61
-
62
- void LiftUpdate (bool newTarget);
63
- void LiftGoToTarget () { LiftUpdate (true ); }
64
- void LiftContinueToTarget () { LiftUpdate (false ); }
65
- void LiftStepToward (OperationalState direction);
66
- void LiftSchedulePositionSet (chip::Percent100ths position) { SchedulePositionSet (position, false ); }
67
- void LiftScheduleOperationalStateSet (OperationalState opState) { ScheduleOperationalStateSet (opState, false ); }
60
+ enum ControlAction : uint8_t
61
+ {
62
+ Lift = 0 ,
63
+ Tilt = 1
64
+ };
68
65
69
- void TiltUpdate (bool newTarget);
70
- void TiltGoToTarget () { TiltUpdate (true ); }
71
- void TiltContinueToTarget () { TiltUpdate (false ); }
72
- void TiltStepToward (OperationalState direction);
73
- void TiltSchedulePositionSet (chip::Percent100ths position) { SchedulePositionSet (position, true ); }
74
- void TiltScheduleOperationalStateSet (OperationalState opState) { ScheduleOperationalStateSet (opState, true ); }
66
+ void Init (chip::EndpointId endpoint);
75
67
76
- void UpdateTargetPosition (OperationalState direction, bool isTilt);
68
+ /* *
69
+ * @brief Schedule a lift or a tilt related attribute transition on the ChipEvent queue
70
+ * **This function allocates a CoverWorkData which needs to be freed by the Worker callback**
71
+ *
72
+ * @param action : ControlAction::Lift will ScheduleWork LiftUpdateWorker, while ControlAction::Tilt will ScheduleWork
73
+ * TilitUpdateWorker
74
+ * @param setNewTarget : True will stop any ongoing transition and start a new one. False will continue the active transition
75
+ * updates
76
+ */
77
+ void ScheduleControlAction (ControlAction action, bool setNewTarget);
78
+ // Helper functions that schedule Lift transitions
79
+ inline void LiftGoToTarget () { ScheduleControlAction (ControlAction::Lift, true ); }
80
+ inline void LiftContinueToTarget () { ScheduleControlAction (ControlAction::Lift, false ); }
81
+ // Helper functions that schedule Tilt transitions
82
+ inline void TiltGoToTarget () { ScheduleControlAction (ControlAction::Tilt, true ); }
83
+ inline void TiltContinueToTarget () { ScheduleControlAction (ControlAction::Tilt, false ); }
84
+
85
+ void PositionSet (chip::EndpointId endpointId, chip::Percent100ths position, ControlAction action);
86
+ void UpdateTargetPosition (OperationalState direction, ControlAction action);
77
87
78
88
Type CycleType ();
79
89
@@ -88,22 +98,23 @@ class WindowManager
88
98
OperationalState mLiftOpState = OperationalState::Stall;
89
99
OperationalState mTiltOpState = OperationalState::Stall;
90
100
91
- struct CoverWorkData
92
- {
93
- chip::EndpointId mEndpointId ;
94
- bool isTilt;
95
-
96
- union
97
- {
98
- chip::Percent100ths percent100ths;
99
- OperationalState opState;
100
- };
101
- };
101
+ /* *
102
+ * @brief Worker callbacks for the ScheduleControlAction.
103
+ * Those functions compute the operational state, and transititon movement based on the current and target positions
104
+ * for the cover.
105
+ * @param arg Context passed to the schedule worker. In this case, a CoverWorkData pointer
106
+ * The referenced CoverWorkData was allocated by ScheduleControlAction and must be freed by the worker.
107
+ */
108
+ static void LiftUpdateWorker (intptr_t arg);
109
+ static void TiltUpdateWorker (intptr_t arg);
110
+ };
102
111
103
- void SchedulePositionSet (chip::Percent100ths position, bool isTilt);
104
- static void CallbackPositionSet (intptr_t arg);
105
- void ScheduleOperationalStateSet (OperationalState opState, bool isTilt);
106
- static void CallbackOperationalStateSet (intptr_t arg);
112
+ struct CoverWorkData
113
+ {
114
+ Cover * cover = nullptr ;
115
+ bool setNewTarget = false ;
116
+ CoverWorkData (Cover * c, bool t) : cover(c), setNewTarget(t) {}
117
+ ~CoverWorkData () { cover = nullptr ; }
107
118
};
108
119
109
120
static WindowManager & Instance ();
0 commit comments