Skip to content

Commit

Permalink
Improved driver
Browse files Browse the repository at this point in the history
  • Loading branch information
nateinaction committed Nov 5, 2024
1 parent ce5db31 commit 58078d2
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 55 deletions.
2 changes: 0 additions & 2 deletions BroncoDeployment/Top/instances.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ module BroncoDeployment {

instance rateDriver: Arduino.HardwareRateDriver base id 0x4A00

instance neoPixelDriver: Drv.NeoPixelDriver base id 0x4B00

# Hub Connections

instance hub: Svc.GenericHub base id 0x5000
Expand Down
4 changes: 0 additions & 4 deletions Components/Drv/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
# Ports
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/NeoPixelDriverPorts/")

# Components
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/NeoPixelDriver/")
21 changes: 6 additions & 15 deletions Components/Drv/NeoPixelDriver/NeoPixelDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ namespace Drv {
#define NUMPIXELS 1

NeoPixelDriver ::NeoPixelDriver(const char* const compName) : NeoPixelDriverComponentBase(compName),
on_off(Fw::On::OFF),
red(0),
green(0),
blue(0),
pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800)
{
pixels.begin();
Expand All @@ -32,18 +28,13 @@ NeoPixelDriver ::~NeoPixelDriver() {}
// Handler implementations for user-defined typed input ports
// ----------------------------------------------------------------------

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 {
pixels.setPixelColor(0, pixels.Color(0, 0, 0));
}
Drv::NeoPixelColor NeoPixelDriver ::neoPixelRead_handler(NATIVE_INT_TYPE portNum) {
uint16_t color = pixels.getPixelColor(0);
return Drv::NeoPixelColor((color >> 16) & 0xFF, (color >> 8) & 0xFF, color & 0xFF);
}

void NeoPixelDriver ::neoPixelSet_handler(NATIVE_INT_TYPE portNum, const Drv::NeoPixelColor& color) {
pixels.setPixelColor(0, pixels.Color(color.getred(), color.getgreen(), color.getblue()));
pixels.show();
}

Expand Down
26 changes: 22 additions & 4 deletions Components/Drv/NeoPixelDriver/NeoPixelDriver.fpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
# Type definition
module Drv {
struct NeoPixelColor {
$red: U8 @< Red color value.
green: U8 @< Green color value.
blue: U8 @< Blue color value.
}
}

# Port definition
module Drv {
port NeoPixelSet(color: NeoPixelColor)
port NeoPixelRead -> NeoPixelColor
}

# Component definition
module Drv {
@ FPrime driver implmementation for Adafruit NeoPixel.
passive component NeoPixelDriver {

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

@ Port to read the current NeoPixel state.
sync input port neoPixelRead: NeoPixelRead

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

###############################################################################
# Standard AC Ports: Required for Channels, Events, Commands, and Parameters #
Expand Down
21 changes: 11 additions & 10 deletions Components/Drv/NeoPixelDriver/NeoPixelDriver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,19 @@ class NeoPixelDriver : public NeoPixelDriverComponentBase {
// Handler implementations for user-defined typed input ports
// ----------------------------------------------------------------------

//! Handler implementation for onOff
void neoPixelWrite_handler(NATIVE_INT_TYPE portNum, //!< The port number
const Fw::On& on_off,
U8 red,
U8 green,
U8 blue) override;
//! Handler implementation for neoPixelRead
//!
//! Port to read the current NeoPixel state.
Drv::NeoPixelColor neoPixelRead_handler(NATIVE_INT_TYPE portNum //!< The port number
) override;

//! Handler implementation for neoPixelSet
//!
//! Port to turn modify the NeoPixel state.
void neoPixelSet_handler(NATIVE_INT_TYPE portNum, //!< The port number
const Drv::NeoPixelColor& color) override;

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

Expand Down
12 changes: 0 additions & 12 deletions Components/Drv/NeoPixelDriverPorts/CMakeLists.txt

This file was deleted.

8 changes: 0 additions & 8 deletions Components/Drv/NeoPixelDriverPorts/NeoPixelDriverPorts.fpp

This file was deleted.

1 change: 1 addition & 0 deletions lib/Adafruit_NeoPixel
Submodule Adafruit_NeoPixel added at aa798f

0 comments on commit 58078d2

Please sign in to comment.