Skip to content

Commit

Permalink
still not working
Browse files Browse the repository at this point in the history
  • Loading branch information
nateinaction committed Oct 23, 2024
1 parent 39301a9 commit 9090584
Show file tree
Hide file tree
Showing 14 changed files with 69 additions and 135 deletions.
6 changes: 3 additions & 3 deletions BroncoDeployment/Top/BroncoDeploymentPackets.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
<channel name="hubComDriver.Status"/>
</packet>

<packet name="LedChannels" id="9" level="1">
<channel name="led.LedTransitions"/>
<channel name="led.BlinkingState"/>
<packet name="LedBlinkerChannels" id="9" level="3">
<channel name="ledBlinker.LedBlinks"/>
<channel name="ledBlinker.BlinkingState"/>
</packet>

<!-- Ignored packets -->
Expand Down
6 changes: 0 additions & 6 deletions BroncoDeployment/Top/BroncoDeploymentTopology.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,6 @@ void configureTopology() {
// Framer and Deframer components need to be passed a protocol handler
framer.setup(framing);
deframer.setup(deframing);

// gpioDriver.open(Arduino::DEF_LED_BUILTIN, Arduino::GpioDriver::GpioDirection::OUT);
// bool gpio_success = gpioDriver.open(27, Arduino::GpioDriver::GpioDirection::OUT);
// if (!gpio_success) {
// Fw::Logger::logMsg("[ERROR] Failed to open GPIO pin\n"); // requires os
// }
}

// Public functions for use in main program are namespaced with deployment name BroncoDeployment
Expand Down
7 changes: 3 additions & 4 deletions BroncoDeployment/Top/instances.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module BroncoDeployment {
stack size Default.STACK_SIZE \
priority 97

instance led: Components.Led base id 0x0E00 \
instance ledBlinker: Components.LedBlinker base id 0x0E00 \
queue size Default.QUEUE_SIZE \
stack size Default.STACK_SIZE \
priority 95
Expand Down Expand Up @@ -65,6 +65,8 @@ module BroncoDeployment {

instance rateDriver: Arduino.HardwareRateDriver base id 0x4A00

instance neoPixelDriver: Drv.NeoPixelDriver base id 0x4C00

# Hub Connections

instance hub: Svc.GenericHub base id 0x5000
Expand All @@ -75,10 +77,7 @@ module BroncoDeployment {

instance hubComDriver: Radio.RFM69 base id 0x5300



# Custom Connections

instance broncoOreMessageHandler: Components.BroncoOreMessageHandler base id 0x6000
instance gpioDriver: Arduino.GpioDriver base id 0x4C00
}
10 changes: 5 additions & 5 deletions BroncoDeployment/Top/topology.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ module BroncoDeployment {

#custom instances
instance broncoOreMessageHandler
instance led
instance gpioDriver
instance ledBlinker
instance neoPixelDriver

# ----------------------------------------------------------------------
# Pattern graph specifiers
Expand Down Expand Up @@ -132,9 +132,9 @@ module BroncoDeployment {
# Named connection group
connections LedConnections {
# Rate Group 1 (1Hz cycle) ouput is connected to led's run input
rateGroup1.RateGroupMemberOut[3] -> led.run
# led's gpioSet output is connected to gpioDriver's gpioWrite input
led.gpioSet -> gpioDriver.gpioWrite
rateGroup1.RateGroupMemberOut[3] -> ledBlinker.run
# led's neopixel output is connected to neoPixelDriver's neoPixelOnOff input
ledBlinker.neoPixelSet -> neoPixelDriver.neoPixelWrite
}
}
Expand Down
2 changes: 1 addition & 1 deletion Components/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/BroncoOreMessageHandler/")

add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Radio/")
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Led/")
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/LedBlinker/")
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Drv/")
5 changes: 2 additions & 3 deletions Components/Drv/NeoPixelDriver/NeoPixelDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,15 @@ NeoPixelDriver ::~NeoPixelDriver() {}
// Handler implementations for user-defined typed input ports
// ----------------------------------------------------------------------

void NeoPixelDriver ::neoPixelOnOff_handler(NATIVE_INT_TYPE portNum, const Fw::On& on_off, U8 red, U8 green, U8 blue) {
void NeoPixelDriver ::neoPixelWrite_handler(NATIVE_INT_TYPE portNum, const Fw::On& on_off, U8 red, U8 green, U8 blue) {
this->on_off = on_off;
this->red = red;
this->green = green;
this->blue = blue;

if (Fw::On::ON == this->on_off) {
pixels.setPixelColor(0, pixels.Color(red, green, blue));
}
else {
} else {
pixels.setPixelColor(0, pixels.Color(0, 0, 0));
}

Expand Down
3 changes: 2 additions & 1 deletion Components/Drv/NeoPixelDriver/NeoPixelDriver.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ module Drv {
@ FPrime driver implmementation for Adafruit NeoPixel.
passive component NeoPixelDriver {

sync input port neoPixelOnOff: Drv.NeoPixelOnOff
@ Port to turn modify the NeoPixel state.
sync input port neoPixelWrite: Drv.NeoPixelWrite

###############################################################################
# Standard AC Ports: Required for Channels, Events, Commands, and Parameters #
Expand Down
13 changes: 7 additions & 6 deletions Components/Drv/NeoPixelDriver/NeoPixelDriver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,18 @@ class NeoPixelDriver : public NeoPixelDriverComponentBase {
// ----------------------------------------------------------------------

//! Handler implementation for onOff
void neoPixelOnOff_handler(NATIVE_INT_TYPE portNum, //!< The port number
const Fw::On& on_off,
U8 red,
U8 green,
U8 blue) override;
void neoPixelWrite_handler(NATIVE_INT_TYPE portNum, //!< The port number
const Fw::On& on_off,
U8 red,
U8 green,
U8 blue) override;

PRIVATE:
Fw::On state;
Fw::On on_off;
U8 red;
U8 green;
U8 blue;
Adafruit_NeoPixel pixels;
};

} // namespace Drv
Expand Down
2 changes: 1 addition & 1 deletion Components/Drv/NeoPixelDriverPorts/NeoPixelDriverPorts.fpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Drv {
port NeoPixelOnOff(
port NeoPixelWrite(
on_off: Fw.On
$red: U8
green: U8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#
####
set(SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/Led.fpp"
"${CMAKE_CURRENT_LIST_DIR}/Led.cpp"
"${CMAKE_CURRENT_LIST_DIR}/LedBlinker.fpp"
"${CMAKE_CURRENT_LIST_DIR}/LedBlinker.cpp"
)

# Uncomment and add any modules that this component depends on, else
Expand Down
86 changes: 24 additions & 62 deletions Components/Led/Led.cpp → Components/LedBlinker/LedBlinker.cpp
Original file line number Diff line number Diff line change
@@ -1,37 +1,32 @@
// ======================================================================
// \title Led.cpp
// \title LedBlinker.cpp
// \author nateinaction
// \brief cpp file for Led component implementation class
// \brief cpp file for LedBlinker component implementation class
// ======================================================================

#include "Components/Led/Led.hpp"
#include "Components/LedBlinker/LedBlinker.hpp"
#include "FpConfig.hpp"

namespace Components {

#define PIN 24
#define NUMPIXELS 1

// ----------------------------------------------------------------------
// Component construction and destruction
// ----------------------------------------------------------------------
Led ::Led(const char* const compName) : LedComponentBase(compName),
state(Fw::On::OFF),
transitions(0),
count(0),
blinking(false),
pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800)
LedBlinker ::LedBlinker(const char* const compName) : LedBlinkerComponentBase(compName),
blinking(Fw::On::OFF),
blinkCount(0),
cycleCount(0)
{
pixels.begin();

}

Led ::~Led() {}
LedBlinker ::~LedBlinker() {}

// ----------------------------------------------------------------------
// Handler implementations for user-defined typed input ports
// ----------------------------------------------------------------------

void Led ::
void LedBlinker ::
run_handler(
const NATIVE_INT_TYPE portNum,
NATIVE_UINT_TYPE context)
Expand All @@ -44,62 +39,29 @@ Led ::~Led() {}
interval = ((Fw::ParamValid::INVALID == isValid) || (Fw::ParamValid::UNINIT == isValid)) ? 0 : interval;

// Only perform actions when set to blinking
bool is_blinking = this->blinking;
if (is_blinking)
{
Fw::On new_state = this->state;
// Check for transitions
if ((0 == this->count) && (this->state == Fw::On::OFF))
{
new_state = Fw::On::ON;
}
else if (((interval / 2) == this->count) && (this->state == Fw::On::ON))
{
new_state = Fw::On::OFF;
}
if (this->blinking == Fw::On::ON) {
bool transition_occurred = false;

// A transition has occurred
if (this->state != new_state)
{
this->transitions = this->transitions + 1;
if (0 == this->cycleCount) {
this->neoPixelSet_out(0, Fw::On::ON, 255, 0, 0);

// Report the number of LED transitions (this->transitions)
this->tlmWrite_LedTransitions(this->transitions);

if (Fw::On::ON == new_state) {
pixels.setPixelColor(0, pixels.Color(150, 0, 0));
}
else {
pixels.setPixelColor(0, pixels.Color(0, 0, 0));
}

pixels.show();

this->state = new_state;
this->tlmWrite_BlinkingState(this->state);
this->blinkCount = this->blinkCount + 1;
this->tlmWrite_LedBlinks(this->blinkCount);
} else if ((interval / 2) == this->cycleCount) {
this->neoPixelSet_out(0, Fw::On::OFF, 0, 0, 0);
}

this->count = ((this->count + 1) >= interval) ? 0 : (this->count + 1);
}
else
{
if(this->state == Fw::On::ON)
{
pixels.setPixelColor(0, pixels.Color(0, 0, 0));
pixels.show();

this->state = Fw::On::OFF;

this->tlmWrite_BlinkingState(this->state);
}
this->cycleCount = ((this->cycleCount + 1) >= interval) ? 0 : (this->cycleCount + 1);
} else {
this->neoPixelSet_out(0, Fw::On::OFF, 0, 0, 0);
}
}

// ----------------------------------------------------------------------
// Handler implementations for commands
// ----------------------------------------------------------------------

void Led ::
void LedBlinker ::
BLINKING_ON_OFF_cmdHandler(
const FwOpcodeType opCode,
const U32 cmdSeq,
Expand All @@ -122,7 +84,7 @@ void Led ::
else
{
this->count = 0; // Reset count on any successful command
this->blinking = Fw::On::ON == on_off; // Update blinking state
this->blinking = on_off; // Update blinking state

// Reports the state we set to blinking.
this->log_ACTIVITY_HI_SetBlinkingState(on_off);
Expand All @@ -135,7 +97,7 @@ void Led ::
this->cmdResponse_out(opCode,cmdSeq,cmdResp);
}

void Led ::parameterUpdated(FwPrmIdType id) {
void LedBlinker ::parameterUpdated(FwPrmIdType id) {
// Read back the parameter value
Fw::ParamValid isValid;
U32 interval = this->paramGet_BLINK_INTERVAL(isValid);
Expand Down
27 changes: 4 additions & 23 deletions Components/Led/Led.fpp → Components/LedBlinker/LedBlinker.fpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Components {
@ Component to blink an LED driven by a rate group
active component Led {
active component LedBlinker {

@ Command to turn on or off the blinking LED
async command BLINKING_ON_OFF(
Expand All @@ -21,15 +21,15 @@ module Components {
severity activity high \
format "LED blink interval set to {}"

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

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

@ Telemetry channel to report the LED state.
telemetry LedTransitions: U64
telemetry LedBlinks: U64

@ Blinking interval in rate group ticks
param BLINK_INTERVAL: U32
Expand All @@ -38,26 +38,7 @@ module Components {
sync input port run: Svc.Sched

@ Port sending calls to the GPIO driver
output port neoPixelSet: Drv.NeoPixelDriver

##############################################################################
#### Uncomment the following examples to start customizing your component ####
##############################################################################

# @ Example async command
# async command COMMAND_NAME(param_name: U32)

# @ Example telemetry counter
# telemetry ExampleCounter: U64

# @ Example event
# event ExampleStateEvent(example_state: Fw.On) severity activity high id 0 format "State set to {}"

# @ Example port: receiving calls from the rate group
# sync input port run: Svc.Sched

# @ Example parameter
# param PARAMETER_NAME: U32
output port neoPixelSet: Drv.NeoPixelWrite

###############################################################################
# Standard AC Ports: Required for Channels, Events, Commands, and Parameters #
Expand Down
Loading

0 comments on commit 9090584

Please sign in to comment.