-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
65c2516
commit b5bdf00
Showing
14 changed files
with
640 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#### | ||
# F prime CMakeLists.txt: | ||
# | ||
# SOURCE_FILES: combined list of source and autocoding files | ||
# MOD_DEPS: (optional) module dependencies | ||
# UT_SOURCE_FILES: list of source files for unit tests | ||
# | ||
#### | ||
set(SOURCE_FILES | ||
"${CMAKE_CURRENT_LIST_DIR}/LedBlinker.fpp" | ||
"${CMAKE_CURRENT_LIST_DIR}/LedBlinker.cpp" | ||
) | ||
|
||
# Uncomment and add any modules that this component depends on, else | ||
# they might not be available when cmake tries to build this component. | ||
|
||
# set(MOD_DEPS | ||
# Adafruit_NeoPixel | ||
# ) | ||
|
||
register_fprime_module() | ||
|
||
set(UT_SOURCE_FILES | ||
"${CMAKE_CURRENT_LIST_DIR}/LedBlinker.fpp" | ||
"${CMAKE_CURRENT_LIST_DIR}/test/ut/LedBlinkerTestMain.cpp" | ||
"${CMAKE_CURRENT_LIST_DIR}/test/ut/LedBlinkerTester.cpp" | ||
) | ||
set(UT_AUTO_HELPERS ON) # Additional Unit-Test autocoding | ||
register_fprime_ut() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
// ====================================================================== | ||
// \title LedBlinker.cpp | ||
// \author nateinaction | ||
// \brief cpp file for LedBlinker component implementation class | ||
// ====================================================================== | ||
|
||
#include "Components/LedBlinker/LedBlinker.hpp" | ||
#include "FpConfig.hpp" | ||
|
||
namespace Components { | ||
|
||
// ---------------------------------------------------------------------- | ||
// Component construction and destruction | ||
// ---------------------------------------------------------------------- | ||
LedBlinker ::LedBlinker(const char* const compName) : LedBlinkerComponentBase(compName) {} | ||
|
||
LedBlinker ::~LedBlinker() {} | ||
|
||
// ---------------------------------------------------------------------- | ||
// Handler implementations for user-defined typed input ports | ||
// ---------------------------------------------------------------------- | ||
|
||
void LedBlinker :: | ||
run_handler( | ||
const NATIVE_INT_TYPE portNum, | ||
NATIVE_UINT_TYPE context) | ||
{ | ||
// Only perform actions when set to blinking | ||
if (this->blinkingState) { | ||
// Blink the LED | ||
blink(); | ||
} else { | ||
// Turn off the LED | ||
this->neoPixelSet_out(0, Drv::NeoPixelColor(0, 0, 0)); | ||
} | ||
|
||
// Report the number of blinks via a telemetry channel | ||
this->tlmWrite_LedBlinks(this->blinkCount); | ||
} | ||
|
||
void LedBlinker ::blink() { | ||
// Get interval from parameter or use default | ||
U32 interval = this->intervalParamOrDefault(); | ||
|
||
// Get color from parameter or use default | ||
Drv::NeoPixelColor color = this->colorParamOrDefault(); | ||
|
||
// Set the LED color or turn it off based on cycle count | ||
this->neoPixelSet_out(0, (this->cycleCount < (interval / 2)) ? color : Drv::NeoPixelColor(0, 0, 0)); | ||
|
||
// Increment blink count at the start of a cycle | ||
this->blinkCount += (this->cycleCount == 0); | ||
|
||
// Increment cycle count | ||
this->cycleCount = (this->cycleCount + 1) % interval; | ||
} | ||
|
||
Drv::NeoPixelColor LedBlinker ::colorParamOrDefault() { | ||
// Read back the parameter value | ||
Fw::ParamValid isColorValid; | ||
Drv::NeoPixelColor color = this->paramGet_BLINK_COLOR(isColorValid); | ||
|
||
// Force color to be red when invalid or not set | ||
return ((Fw::ParamValid::INVALID == isColorValid) || (Fw::ParamValid::UNINIT == isColorValid)) ? Drv::NeoPixelColor(50, 0, 0) : color; | ||
} | ||
|
||
U32 LedBlinker ::intervalParamOrDefault() { | ||
// Read back the parameter value | ||
Fw::ParamValid isIntervalValid; | ||
U32 interval = this->paramGet_BLINK_INTERVAL(isIntervalValid); | ||
|
||
// Force interval to be 10 when invalid or not set | ||
return ((Fw::ParamValid::INVALID == isIntervalValid) || (Fw::ParamValid::UNINIT == isIntervalValid)) ? 10 : interval; | ||
} | ||
|
||
// ---------------------------------------------------------------------- | ||
// Handler implementations for commands | ||
// ---------------------------------------------------------------------- | ||
|
||
void LedBlinker ::BLINKING_ON_OFF_cmdHandler(FwOpcodeType opCode, U32 cmdSeq, Fw::On blinking_state) { | ||
// Create a variable to represent the command response | ||
auto cmdResp = Fw::CmdResponse::OK; | ||
|
||
// Set blinking state | ||
this->blinkingState = blinking_state; | ||
|
||
// Reset cycle count | ||
this->cycleCount = 0; | ||
|
||
// Reports the state as an event | ||
this->log_ACTIVITY_HI_SetBlinkingState(blinking_state); | ||
|
||
// Report the blinking state via a telemetry channel. | ||
this->tlmWrite_BlinkingState(blinking_state); | ||
|
||
// Provide command response | ||
this->cmdResponse_out(opCode, cmdSeq, cmdResp); | ||
} | ||
|
||
void LedBlinker ::parameterUpdated(FwPrmIdType id) { | ||
switch (id) | ||
{ | ||
case PARAMID_BLINK_COLOR: | ||
// Validate and set the color parameter on update | ||
this->parameterValidateColor(); | ||
break; | ||
case PARAMID_BLINK_INTERVAL: | ||
// Validate and set the interval parameter on update | ||
this->parameterValidateInterval(); | ||
break; | ||
default: | ||
FW_ASSERT(1, id); // Should never reach, invalid parameter ID | ||
break; | ||
} | ||
} | ||
|
||
void LedBlinker ::parameterValidateColor() { | ||
// Read back the parameter value | ||
Fw::ParamValid isValid; | ||
Drv::NeoPixelColor color = this->paramGet_BLINK_COLOR(isValid); | ||
|
||
// Fail if the color is invalid | ||
FW_ASSERT(isValid == Fw::ParamValid::VALID, isValid); | ||
|
||
// Log the color change | ||
this->log_ACTIVITY_HI_BlinkColorSet(color); | ||
|
||
// Report the color via a telemetry channel | ||
this->tlmWrite_BlinkingColor(color); | ||
} | ||
|
||
void LedBlinker ::parameterValidateInterval() { | ||
// Read back the parameter value | ||
Fw::ParamValid isValid; | ||
U32 interval = this->paramGet_BLINK_INTERVAL(isValid); | ||
|
||
// Fail if the interval is invalid | ||
FW_ASSERT(isValid == Fw::ParamValid::VALID, isValid); | ||
|
||
// Log the interval change | ||
this->log_ACTIVITY_HI_BlinkIntervalSet(interval); | ||
} | ||
} // namespace Components |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
module Components { | ||
@ Component to blink an LED driven by a rate group | ||
active component LedBlinker { | ||
@ Command to turn on or off the blinking LED | ||
async command BLINKING_ON_OFF( | ||
blinking_state: Fw.On @< Turn the LED blinking on or off. | ||
) | ||
|
||
@ Reports the state we set to blinking. | ||
event SetBlinkingState(state: Fw.On) \ | ||
severity activity high \ | ||
format "Set blinking state to {}." | ||
|
||
@ Reports the color that has been set | ||
event BlinkColorSet(color: Drv.NeoPixelColor) \ | ||
severity activity high \ | ||
format "LED blink color set to {}" | ||
|
||
@ Reports the interval that has been set | ||
event BlinkIntervalSet(interval: U32) \ | ||
severity activity high \ | ||
format "LED blink interval set to {}" | ||
|
||
@ Telemetry channel to report blinking state. | ||
telemetry BlinkingState: Fw.On | ||
|
||
@ Telemetry channel to report blinking state. | ||
telemetry BlinkingColor: Drv.NeoPixelColor | ||
|
||
@ Telemetry channel to report the LED state. | ||
telemetry LedBlinks: U64 | ||
|
||
@ Blinking interval in rate group ticks | ||
param BLINK_INTERVAL: U32 | ||
|
||
@ Blinking interval in rate group ticks | ||
param BLINK_COLOR: Drv.NeoPixelColor | ||
|
||
@ Port receiving calls from the rate group | ||
sync input port run: Svc.Sched | ||
|
||
@ Port sending calls to the GPIO driver | ||
output port neoPixelSet: Drv.NeoPixelSet | ||
|
||
############################################################################### | ||
# Standard AC Ports: Required for Channels, Events, Commands, and Parameters # | ||
############################################################################### | ||
@ Port for requesting the current time | ||
time get port timeCaller | ||
|
||
@ Port for sending command registrations | ||
command reg port cmdRegOut | ||
|
||
@ Port for receiving commands | ||
command recv port cmdIn | ||
|
||
@ Port for sending command responses | ||
command resp port cmdResponseOut | ||
|
||
@ Port for sending textual representation of events | ||
text event port logTextOut | ||
|
||
@ Port for sending events to downlink | ||
event port logOut | ||
|
||
@ Port for sending telemetry channels to downlink | ||
telemetry port tlmOut | ||
|
||
@ Port to return the value of a parameter | ||
param get port prmGetOut | ||
|
||
@Port to set the value of a parameter | ||
param set port prmSetOut | ||
|
||
} | ||
} |
Oops, something went wrong.