82 lines
2.1 KiB
C
82 lines
2.1 KiB
C
/*
|
|
* @file lsense.h
|
|
* @brief Light sensor management.
|
|
*
|
|
* Created: 21.09.2025
|
|
* Author: ThePetrovich
|
|
*
|
|
* Copyright YKSA - Sakha Aerospace Systems, LLC.
|
|
* See the LICENSE file for details.
|
|
*
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
*/
|
|
|
|
#ifndef LSENSE_H
|
|
#define LSENSE_H
|
|
|
|
#include <stdint.h>
|
|
|
|
#define NUM_BUSES 3
|
|
#define SENSORS_PER_BUS 2
|
|
|
|
enum { BUS_X = 0, BUS_Y = 1, BUS_Z = 2 };
|
|
enum { SENSOR_NEG = 0, SENSOR_POS = 1 };
|
|
|
|
/**
|
|
* @brief Detection result for the six light sensors across three I2C buses.
|
|
* Reused as the response payload of #CMD_LIGHT_SENSOR_PRESENCE.
|
|
*/
|
|
typedef union lsense_presence_t {
|
|
struct __attribute__((packed)) {
|
|
uint8_t total_detected;
|
|
uint8_t bus_x_count;
|
|
uint8_t bus_x_neg_addr;
|
|
uint8_t bus_x_pos_addr;
|
|
uint8_t bus_y_count;
|
|
uint8_t bus_y_neg_addr;
|
|
uint8_t bus_y_pos_addr;
|
|
uint8_t bus_z_count;
|
|
uint8_t bus_z_neg_addr;
|
|
uint8_t bus_z_pos_addr;
|
|
};
|
|
uint8_t bytes[10];
|
|
} __attribute__((packed)) lsense_presence_t;
|
|
|
|
/**
|
|
* @brief Per-sensor channel values for a single read across all 6 sensors.
|
|
* Reused as the response payload of #CMD_READ_LIGHT_SENSORS.
|
|
*/
|
|
typedef union lsense_channel_values_t {
|
|
struct __attribute__((packed)) {
|
|
uint16_t bus_x_neg_value;
|
|
uint16_t bus_x_pos_value;
|
|
uint16_t bus_y_neg_value;
|
|
uint16_t bus_y_pos_value;
|
|
uint16_t bus_z_neg_value;
|
|
uint16_t bus_z_pos_value;
|
|
};
|
|
uint16_t values[6];
|
|
} __attribute__((packed)) lsense_channel_values_t;
|
|
|
|
/**
|
|
* @brief Detect all sensors on all three buses.
|
|
* Populates internal state used by #lsense_get_presence and
|
|
* #lsense_read_channel.
|
|
*/
|
|
void lsense_detect_all(void);
|
|
|
|
/**
|
|
* @brief Fill @p out with detection results from the most recent
|
|
* #lsense_detect_all call.
|
|
*/
|
|
void lsense_get_presence(lsense_presence_t *out);
|
|
|
|
/**
|
|
* @brief Read a spectral channel from all six sensors into @p out.
|
|
* @param channel 0=red 1=green 2=blue 3=IR 4=green2
|
|
* 5=visible (R+G+B+G2) 6=all (R+G+B+G2+IR)
|
|
* @param out Output values, ordered X_neg, X_pos, Y_neg, Y_pos, Z_neg, Z_pos.
|
|
*/
|
|
void lsense_read_channel(uint8_t channel, lsense_channel_values_t *out);
|
|
|
|
#endif /* LSENSE_H */
|