Protocol rework

This commit is contained in:
ThePetrovich 2026-05-10 15:33:08 +08:00
parent 3e77d34ccc
commit 2b713a3e3a
15 changed files with 1347 additions and 1155 deletions

View file

@ -1,8 +1,8 @@
/*
* @file lsense.h
* @brief Light sensor management and command handling
* @brief Light sensor management.
*
* Created: 21.09.2025 05:53:32
* Created: 21.09.2025
* Author: ThePetrovich
*
* Copyright YKSA - Sakha Aerospace Systems, LLC.
@ -14,30 +14,69 @@
#ifndef LSENSE_H
#define LSENSE_H
#include <Arduino.h>
#include <stdint.h>
#define NUM_BUSES 3
#define NUM_BUSES 3
#define SENSORS_PER_BUS 2
enum {
BUS_X = 0, // X-axis (bus 0)
BUS_Y = 1, // Y-axis (bus 1)
BUS_Z = 2 // Z-axis (bus 2)
};
enum {
SENSOR_NEG = 0, // Negative sensor (addresses 0)
SENSOR_POS = 1 // Positive sensor (addresses 1)
};
enum { BUS_X = 0, BUS_Y = 1, BUS_Z = 2 };
enum { SENSOR_NEG = 0, SENSOR_POS = 1 };
/**
* @brief Send light sensor presence information via serial
* @brief Detection result for the six light sensors across three I2C buses.
* Reused as the response payload of #CMD_LIGHT_SENSOR_PRESENCE.
*/
void lsense_cmd_presence(void);
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 Read and send light sensor data via serial
* @brief Per-sensor channel values for a single read across all 6 sensors.
* Reused as the response payload of #CMD_READ_LIGHT_SENSORS.
*/
void lsense_cmd_read(void);
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;
#endif // LSENSE_H
/**
* @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 */