1+ // ======================================================================
2+ // \title Led.cpp
3+ // \author ortega
4+ // \brief cpp file for Led component implementation class
5+ // ======================================================================
6+
7+ #include " FprimeZephyrReference/Components/Led/Led.hpp"
8+ #include " config/FpConfig.hpp"
9+
10+ namespace Components {
11+
12+ // ----------------------------------------------------------------------
13+ // Component construction and destruction
14+ // ----------------------------------------------------------------------
15+
16+ Led ::Led (const char * const compName) : LedComponentBase(compName) {}
17+
18+ Led ::~Led () {}
19+
20+ // ----------------------------------------------------------------------
21+ // Handler implementations for user-defined typed input ports
22+ // ----------------------------------------------------------------------
23+
24+ void Led ::run_handler (FwIndexType portNum, U32 context) {
25+
26+ U32 interval = this ->m_blinkInterval ; // Get the blink interval from the member variable
27+
28+ // Only perform actions when set to blinking
29+ if (this ->m_blinking && (interval != 0 )) {
30+ // If toggling state
31+ if (this ->m_toggleCounter == 0 ) {
32+ // Toggle state
33+ this ->m_state = (this ->m_state == Fw::On::ON) ? Fw::On::OFF : Fw::On::ON;
34+ this ->m_transitions ++;
35+ this ->tlmWrite_LedTransitions (this ->m_transitions );
36+
37+ // Port may not be connected, so check before sending output
38+ if (this ->isConnected_gpioSet_OutputPort (0 )) {
39+ this ->gpioSet_out (0 , (Fw::On::ON == this ->m_state ) ? Fw::Logic::HIGH : Fw::Logic::LOW);
40+ }
41+
42+ this ->log_ACTIVITY_LO_LedState (this ->m_state );
43+ }
44+
45+ this ->m_toggleCounter = (this ->m_toggleCounter + 1 ) % interval;
46+ }
47+ // We are not blinking
48+ else {
49+ if (this ->m_state == Fw::On::ON) {
50+ // Port may not be connected, so check before sending output
51+ if (this ->isConnected_gpioSet_OutputPort (0 )) {
52+ this ->gpioSet_out (0 , Fw::Logic::LOW);
53+ }
54+
55+ this ->m_state = Fw::On::OFF;
56+ this ->log_ACTIVITY_LO_LedState (this ->m_state );
57+ }
58+ }
59+ }
60+
61+ // ----------------------------------------------------------------------
62+ // Handler implementations for commands
63+ // ----------------------------------------------------------------------
64+
65+ void Led ::BLINKING_ON_OFF_cmdHandler (FwOpcodeType opCode, U32 cmdSeq, Fw::On onOff) {
66+ this ->m_toggleCounter = 0 ; // Reset count on any successful command
67+ this ->m_blinking = Fw::On::ON == onOff; // Update blinking state
68+
69+ this ->log_ACTIVITY_HI_SetBlinkingState (onOff);
70+
71+ this ->tlmWrite_BlinkingState (onOff);
72+
73+ // Provide command response
74+ this ->cmdResponse_out (opCode, cmdSeq, Fw::CmdResponse::OK);
75+ }
76+
77+ void Led ::SET_BLINK_INTERVAL_cmdHandler (FwOpcodeType opCode, U32 cmdSeq, U32 interval) {
78+ // Update the member variable
79+ this ->m_blinkInterval = interval;
80+
81+ // Log the event
82+ this ->log_ACTIVITY_HI_BlinkIntervalSet (interval);
83+
84+ // Provide command response
85+ this ->cmdResponse_out (opCode, cmdSeq, Fw::CmdResponse::OK);
86+ }
87+
88+ } // namespace Components
0 commit comments