Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
a563640
Add load switch component
kevinthegreat1 Oct 9, 2025
5d5648f
Fix tables
kevinthegreat1 Oct 23, 2025
8f00e03
Sarah Kevin MoMata Squad Load Switch
hyuncat Oct 23, 2025
628fcbe
Sarah Kevin and MoMata fixed a bug
hyuncat Oct 23, 2025
91b25fe
Commit farming
hyuncat Oct 23, 2025
076bf65
Added mcp23017 to v5 dtsi
moisesmata Oct 23, 2025
24a2e97
Rough initial implementation + add to topology
moisesmata Oct 23, 2025
3761180
Ion even know any mane
moisesmata Oct 23, 2025
bcb6f24
Merged in Main
Mikefly123 Nov 3, 2025
3fec032
Working Device Tree (But F Prime Crash)
Mikefly123 Nov 3, 2025
09c61fd
Update CommandDispatcherImplCfg.hpp
Mikefly123 Nov 3, 2025
b5544e7
Update Submodules
moisesmata Nov 4, 2025
5351c58
Revert "Update Submodules"
Mikefly123 Nov 5, 2025
46e6604
Add Reset port functionality
moisesmata Nov 6, 2025
7b81993
Help
RobertPendergrast Nov 6, 2025
98326f2
Add remaining load switch instances
kevinthegreat1 Nov 6, 2025
9c72d7a
Small updates to extra loadSwitch instances, update max packets
moisesmata Nov 6, 2025
d7fce15
Remove output read port, add output write port
moisesmata Nov 6, 2025
3cde46d
updates i guess
RobertPendergrast Nov 7, 2025
4dff326
Modify LoadSwitch to use ZephyrGpioDriver Component
moisesmata Nov 7, 2025
3d91f1e
Modify gpioDriver name for watchdog for clarity
moisesmata Nov 7, 2025
6095153
Instances of GPIO Drivers, connected to load switches in topology
moisesmata Nov 7, 2025
2b9f0a9
First implementation load_switch_test
Hufamily Nov 7, 2025
b65806b
Labels for devicetree gpios fixed
moisesmata Nov 7, 2025
6f76ed3
Update sdd
moisesmata Nov 8, 2025
183df23
Wahoo
RobertPendergrast Nov 11, 2025
6d010cb
Moises made them active lmao
RobertPendergrast Nov 11, 2025
f61cd6b
DO NOT PUSH
RobertPendergrast Nov 11, 2025
e49e29e
Full device tree? Added another component instance for validation pur…
RobertPendergrast Nov 12, 2025
a1178e4
uped cmdDisp que bc boot loop
ineskhou Nov 12, 2025
0e29d33
Trying the defer stuff
RobertPendergrast Nov 13, 2025
a46bbb8
Revise LightSensor documentation to LightSensorManager
RobertPendergrast Nov 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions FprimeZephyrReference/Components/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/ImuManager/")
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/NullPrmDb/")
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/PowerMonitor/")
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Watchdog")
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/LightSensor/")
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/LoadSwitch/")
36 changes: 36 additions & 0 deletions FprimeZephyrReference/Components/LightSensor/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
####
# F Prime CMakeLists.txt:
#
# SOURCES: list of source files (to be compiled)
# AUTOCODER_INPUTS: list of files to be passed to the autocoders
# DEPENDS: list of libraries that this module depends on
#
# More information in the F´ CMake API documentation:
# https://fprime.jpl.nasa.gov/latest/docs/reference/api/cmake/API/
#
####

# Module names are derived from the path from the nearest project/library/framework
# root when not specifically overridden by the developer. i.e. The module defined by
# `Ref/SignalGen/CMakeLists.txt` will be named `Ref_SignalGen`.

register_fprime_library(
AUTOCODER_INPUTS
"${CMAKE_CURRENT_LIST_DIR}/LightSensor.fpp"
SOURCES
"${CMAKE_CURRENT_LIST_DIR}/LightSensor.cpp"
# DEPENDS
# MyPackage_MyOtherModule
)

### Unit Tests ###
# register_fprime_ut(
# AUTOCODER_INPUTS
# "${CMAKE_CURRENT_LIST_DIR}/LightSensor.fpp"
# SOURCES
# "${CMAKE_CURRENT_LIST_DIR}/test/ut/LightSensorTestMain.cpp"
# "${CMAKE_CURRENT_LIST_DIR}/test/ut/LightSensorTester.cpp"
# DEPENDS
# STest # For rules-based testing
# UT_AUTO_HELPERS
# )
164 changes: 164 additions & 0 deletions FprimeZephyrReference/Components/LightSensor/LightSensor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
// ======================================================================
// \title LightSensor.cpp
// \author robertpendergrast
// \brief cpp file for LightSensor component implementation class
// ======================================================================



#include "FprimeZephyrReference/Components/LightSensor/LightSensor.hpp"
#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/i2c.h>

namespace Components {

// ----------------------------------------------------------------------
// Component construction and destruction
// ----------------------------------------------------------------------

LightSensor ::LightSensor(const char* const compName) : LightSensorComponentBase(compName) {}

LightSensor ::~LightSensor() {}

void LightSensor ::configure(const struct device* dev) {
return;
}

void LightSensor ::ReadData() { // const struct device *dev,
// Return integer
int ret;

// Sensor value structs for reading data
struct sensor_value light;
struct sensor_value als_raw;
struct sensor_value ir_raw;
struct sensor_value sen;

sen.val2 = 0;

Fw::ParamValid valid;
sen.val1 = 5; // pass in saying that the parameter is valid

// Setting the integration time attribute for the light sensor

if (! (this->m_attributes_set)){
ret = sensor_attr_set(this->m_dev, SENSOR_CHAN_LIGHT, (enum sensor_attribute)SENSOR_ATTR_VEML6031_IT, &sen);
if (ret) {
Fw::LogStringArg errMsg("Failed to set it attribute");
this->log_WARNING_HI_LightSensorError(errMsg);
}

// Set the sensor attribute for div4
sen.val1 = paramGet_DIV4(valid);

ret = sensor_attr_set(this->m_dev, SENSOR_CHAN_LIGHT, (enum sensor_attribute)SENSOR_ATTR_VEML6031_DIV4, &sen);
if (ret) {
Fw::LogStringArg errMsg("Failed to set div4 attribute");
this->log_WARNING_HI_LightSensorError(errMsg);
}

// Set the sensor attribute for the gain
sen.val1 = 0;
ret = sensor_attr_set(this->m_dev, SENSOR_CHAN_LIGHT, (enum sensor_attribute)SENSOR_ATTR_VEML6031_GAIN, &sen);
if (ret) {
Fw::LogStringArg errMsg("Failed to set gain attribute ret");
this->log_WARNING_HI_LightSensorError(errMsg);
}

this->m_attributes_set = true;
}

// Get the rate
ret = sensor_sample_fetch(this->m_dev);
if ((ret < 0) && (ret != -E2BIG)) {
Fw::LogStringArg errMsg("sample update error");
this->log_WARNING_HI_LightSensorError(errMsg);
this->log_WARNING_HI_LightSensorErrorInt(ret);
}

// Get the light data
sensor_channel_get(this->m_dev, (enum sensor_channel)SENSOR_CHAN_LIGHT, &light);

// Get the raw ALS
sensor_channel_get(this->m_dev, (enum sensor_channel)SENSOR_CHAN_VEML6031_ALS_RAW_COUNTS, &als_raw);

// Get the raw IR
sensor_channel_get(this->m_dev, (enum sensor_channel)SENSOR_CHAN_VEML6031_IR_RAW_COUNTS, &ir_raw);

this->m_RawLightData = sensor_value_to_double(&light);
this->m_ALSLightData = sensor_value_to_double(&als_raw);
this->m_IRLightData = sensor_value_to_double(&ir_raw);
}

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

void LightSensor ::run_handler(FwIndexType portNum, U32 context) {
Fw::Logic state;
this->gpioRead_out(portNum, state);
if (state == Fw::Logic::HIGH){ // port call to the gpio driver, pass in a specific pin #
this->ReadData();
this->tlmWrite_RawLightData(this->m_RawLightData);
this->tlmWrite_IRLightData(this->m_IRLightData);
this->tlmWrite_ALSLightData(this->m_ALSLightData);
} else {
if (this->m_device_init == true) {
this->m_device_init = false;
}
if(state == Fw::Logic::LOW && this->m_attributes_set == true){
this->m_attributes_set = false;
}
}

}

void LightSensor::init_handler(FwIndexType portNum) {

const struct device *mux = DEVICE_DT_GET(DT_NODELABEL(tca9548a));
const struct device *channel = DEVICE_DT_GET(DT_NODELABEL(face0_i2c));
const struct device *sensor = DEVICE_DT_GET(DT_NODELABEL(face0_light_sens));

if (!mux || !channel || !sensor) {
this->log_WARNING_HI_LightSensorError(Fw::LogStringArg("Device DT_NODELABEL missing"));
return;
}

int ret = device_init(mux);
if (ret < 0) {
this->log_WARNING_HI_LightSensorError(Fw::LogStringArg("TCA9548A init failed"));
return;
}
k_sleep(K_MSEC(30));

ret = device_init(channel);
if (ret < 0) {
this->log_WARNING_HI_LightSensorError(Fw::LogStringArg("Mux channel init failed"));
return;
}
k_sleep(K_MSEC(30));

ret = device_init(sensor);
if (ret < 0) {
this->log_WARNING_HI_LightSensorError(Fw::LogStringArg("Light sensor init failed"));
// Continue anyway - might still work
}
k_sleep(K_MSEC(50));

if (!device_is_ready(sensor)) {
this->log_WARNING_HI_LightSensorError(Fw::LogStringArg("Light sensor not ready after timeout"));
}

this->m_dev = sensor;
this->m_device_init = true;

this->log_ACTIVITY_LO_LightSensorConfigured();
}





} // namespace Components
103 changes: 103 additions & 0 deletions FprimeZephyrReference/Components/LightSensor/LightSensor.fpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
module Components {
@ Component for reading light sensor data
port InitPort

passive component LightSensor {

#### Parameters ####
@ Parameter for setting the gain of the light senors
param GAIN: U32 default 1

@ Parameter for setting the integration time of the light sensors
param INTEGRATION_TIME: U32 default 100

@ Paremeter for setting the div4 mode of the light sensors
param DIV4: U32 default 0

#### Telemetry ####
@ Telemetry for the raw light sensor data
telemetry RawLightData: F32

@ Telemetry for the IR light sensor data
telemetry IRLightData: F32

@ Telemetry for the ALS light sensor data
telemetry ALSLightData: F32

#### Ports ####

@ Port for polling the light sensor data - called by rate group
sync input port run: Svc.Sched

@ Port for reading gpio status
output port gpioRead: Drv.GpioRead

@ Port to tell us when to init the device
sync input port init: InitPort

#### Events ####

@ Event for light sensor errors
event LightSensorError(log: string) severity warning high format "Light Sensor Error: {}"

event LightSensorErrorInt(log: U32) severity warning high format "Light Sensor Error: {}"

@ Event for light sensor configuration
event LightSensorConfigured() severity activity low format "Light Sensor Configured"

event LightSensorRead() severity activity low format "Values Read from the Light Sensor"




##############################################################################
#### 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

###############################################################################
# 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

}
}
77 changes: 77 additions & 0 deletions FprimeZephyrReference/Components/LightSensor/LightSensor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// ======================================================================
// \title LightSensor.hpp
// \author robertpendergrast
// \brief hpp file for LightSensor component implementation class
// ======================================================================

#ifndef Components_LightSensor_HPP
#define Components_LightSensor_HPP

#include "FprimeZephyrReference/Components/LightSensor/LightSensorComponentAc.hpp"

#include <zephyr/kernel.h>

#include <zephyr/sys/printk.h>
#include <zephyr/sys_clock.h>
#include <stdio.h>

#include <zephyr/device.h>
#include <zephyr/drivers/sensor.h>
#include <zephyr/drivers/i2c.h>

#include <zephyr/drivers/sensor/veml6031.h>

namespace Components {

class LightSensor final : public LightSensorComponentBase {
public:
// ----------------------------------------------------------------------
// Component construction and destruction
// ----------------------------------------------------------------------

//! Construct LightSensor object
LightSensor(const char* const compName //!< The component name
);

//! Destroy LightSensor object
~LightSensor();


void ReadData();

void configure(const struct device* dev);

private:
// ----------------------------------------------------------------------
// Handler implementations for typed input ports
// ----------------------------------------------------------------------

//! Handler implementation for run
//!
//! Port for polling the light sensor data - called by rate group
void run_handler(FwIndexType portNum, //!< The port number
U32 context //!< The call order
) override;

void init_handler(FwIndexType portNum);

F32 m_RawLightData;

F32 m_IRLightData;

F32 m_ALSLightData;

bool m_configured = false;

bool m_attributes_set = false;

bool m_device_init = false;

const struct device* m_dev;
};



} // namespace Components

#endif
Loading