Skip to content

Commit

Permalink
Working
Browse files Browse the repository at this point in the history
  • Loading branch information
nateinaction committed Oct 23, 2024
1 parent 9090584 commit fc5a713
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 29 deletions.
9 changes: 5 additions & 4 deletions Components/Drv/NeoPixelDriver/NeoPixelDriver.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ module Drv {
@ Port to turn modify the NeoPixel state.
sync input port neoPixelWrite: Drv.NeoPixelWrite

@ Event to report current NeoPixel state.
event NeoPixelState(on_off: Fw.On, $red: U8, green: U8, blue: U8) \
severity activity low \
format "LED is {} with color ({}, {}, {})"

###############################################################################
# Standard AC Ports: Required for Channels, Events, Commands, and Parameters #
###############################################################################
Expand All @@ -16,9 +21,5 @@ module Drv {

@ Port for sending events to downlink
event port logOut

@ Port for sending telemetry channels to downlink
telemetry port tlmOut

}
}
33 changes: 19 additions & 14 deletions Components/LedBlinker/LedBlinker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ namespace Components {
// ----------------------------------------------------------------------
LedBlinker ::LedBlinker(const char* const compName) : LedBlinkerComponentBase(compName),
blinking(Fw::On::OFF),
red(0),
green(0),
blue(0),
blinkCount(0),
cycleCount(0)
{
Expand All @@ -36,14 +39,14 @@ LedBlinker ::~LedBlinker() {}
U32 interval = this->paramGet_BLINK_INTERVAL(isValid);

// Force interval to be 0 when invalid or not set
interval = ((Fw::ParamValid::INVALID == isValid) || (Fw::ParamValid::UNINIT == isValid)) ? 0 : interval;
interval = ((Fw::ParamValid::INVALID == isValid) || (Fw::ParamValid::UNINIT == isValid)) ? 10 : interval;

// Only perform actions when set to blinking
if (this->blinking == Fw::On::ON) {
bool transition_occurred = false;

if (0 == this->cycleCount) {
this->neoPixelSet_out(0, Fw::On::ON, 255, 0, 0);
this->neoPixelSet_out(0, Fw::On::ON, this->red, this->green, this->blue);

this->blinkCount = this->blinkCount + 1;
this->tlmWrite_LedBlinks(this->blinkCount);
Expand All @@ -61,30 +64,32 @@ LedBlinker ::~LedBlinker() {}
// Handler implementations for commands
// ----------------------------------------------------------------------

void LedBlinker ::
BLINKING_ON_OFF_cmdHandler(
const FwOpcodeType opCode,
const U32 cmdSeq,
Fw::On on_off
)
{
void LedBlinker ::BLINKING_ON_OFF_cmdHandler(
FwOpcodeType opCode,
U32 cmdSeq,
Fw::On on_off,
U8 red,
U8 green,
U8 blue
) {
// Create a variable to represent the command response
auto cmdResp = Fw::CmdResponse::OK;

// Verify if on_off is a valid argument.
// Note: isValid is an autogenerate helper function for enums defined in fpp.
if(!on_off.isValid())
{
if(!on_off.isValid()) {
// Indicates we received an invalid argument.
this->log_WARNING_LO_InvalidBlinkArgument(on_off);

// Update command response with a validation error
cmdResp = Fw::CmdResponse::VALIDATION_ERROR;
}
else
{
this->count = 0; // Reset count on any successful command
else {
this->cycleCount = 0; // Reset count on any successful command
this->blinking = on_off; // Update blinking state
this->red = red; // Update red color value
this->green = green; // Update green color value
this->blue = blue; // Update blue color value

// Reports the state we set to blinking.
this->log_ACTIVITY_HI_SetBlinkingState(on_off);
Expand Down
8 changes: 4 additions & 4 deletions Components/LedBlinker/LedBlinker.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ module Components {
@ Command to turn on or off the blinking LED
async command BLINKING_ON_OFF(
on_off: Fw.On @< Indicates whether the blinking should be on or off
$red: U8 @< Red color value
green: U8 @< Green color value
blue: U8 @< Blue color value
)

@ Indicates we received an invalid argument.
Expand All @@ -17,14 +20,11 @@ module Components {
severity activity high \
format "Set blinking state to {}."

@ Reports the interval that has been set
event BlinkIntervalSet(interval: U32) \
severity activity high \
format "LED blink interval set to {}"

event LedBlinkerState(on_off: Fw.On) \
severity activity low \
format "LED is {}"

@ Telemetry channel to report blinking state.
telemetry BlinkingState: Fw.On

Expand Down
17 changes: 10 additions & 7 deletions Components/LedBlinker/LedBlinker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ class LedBlinker : public LedBlinkerComponentBase {

//! Implementation for BLINKING_ON_OFF command handler
//! Command to turn on or off the blinking LED
void BLINKING_ON_OFF_cmdHandler(
const FwOpcodeType opCode, /*!< The opcode*/
const U32 cmdSeq, /*!< The command sequence number*/
Fw::On on_off /*!<
Indicates whether the blinking should be on or off
*/
);
void BLINKING_ON_OFF_cmdHandler(FwOpcodeType opCode, //!< The opcode
U32 cmdSeq, //!< The command sequence number
Fw::On on_off, //!< Indicates whether the blinking should be on or off
U8 red, //!< Red color value
U8 green, //!< Green color value
U8 blue //!< Blue color value
) override;

//! Emit parameter updated EVR
//!
Expand All @@ -58,6 +58,9 @@ class LedBlinker : public LedBlinkerComponentBase {

PRIVATE:
Fw::On blinking; //! If LED blinking is on
U8 red; //! Red color value
U8 green; //! Green color value
U8 blue; //! Blue color value
U64 blinkCount; //! The number of on/off transitions that have occurred from FSW boot up
U32 cycleCount; //! Keeps track of how many ticks the LED has been on for
};
Expand Down

0 comments on commit fc5a713

Please sign in to comment.