Save all measured temperatures

This commit is contained in:
jazzpi 2022-06-23 13:53:56 +02:00
parent e58b9ffae0
commit 2acde9d565
2 changed files with 18 additions and 42 deletions

View File

@ -13,7 +13,10 @@
#include "stm32f4xx_hal.h"
#include "stm32f4xx_hal_uart.h"
extern volatile uint16_t temperatures[N_CELLS];
#define N_SENSORS 32
extern volatile uint16_t temperatures[N_SENSORS];
extern volatile uint16_t max_temp;
typedef enum {
TMP144_IDLE,
@ -29,7 +32,6 @@ typedef struct {
uint8_t rxbuf[34];
size_t n_sensors;
uint8_t sensor_mappings[16];
} TMP144Bus;
HAL_StatusTypeDef tmp144_init(UART_HandleTypeDef* busbar_side,

View File

@ -7,13 +7,15 @@
#include "TMP144.h"
#include <stdint.h>
#include <string.h>
static const uint8_t TMP144_SEQ_RESET[] = {0x55, 0xB4};
static const uint8_t TMP144_SEQ_ADDR[] = {0x55, 0x8C, 0x90};
static const uint8_t TMP144_SEQ_READ_TEMPS[] = {0x55, 0xF1};
volatile uint16_t temperatures[N_CELLS];
volatile uint16_t temperatures[N_SENSORS];
volatile uint16_t max_temp;
static volatile TMP144Bus bus_busbar;
static volatile TMP144Bus bus_other;
@ -34,32 +36,8 @@ HAL_StatusTypeDef tmp144_init(UART_HandleTypeDef* busbar_side,
bus_other.state = TMP144_IDLE;
// TODO: Configure this in EEPROM
bus_busbar.n_sensors = 11;
bus_busbar.sensor_mappings[0] = 8;
bus_busbar.sensor_mappings[1] = 8;
bus_busbar.sensor_mappings[2] = 8;
bus_busbar.sensor_mappings[3] = 6;
bus_busbar.sensor_mappings[4] = 6;
bus_busbar.sensor_mappings[5] = 4;
bus_busbar.sensor_mappings[6] = 4;
bus_busbar.sensor_mappings[7] = 4;
bus_busbar.sensor_mappings[8] = 2;
bus_busbar.sensor_mappings[9] = 2;
bus_busbar.sensor_mappings[10] = 2;
bus_other.n_sensors = 13;
bus_other.sensor_mappings[0] = 1;
bus_other.sensor_mappings[1] = 1;
bus_other.sensor_mappings[2] = 1;
bus_other.sensor_mappings[3] = 3;
bus_other.sensor_mappings[4] = 3;
bus_other.sensor_mappings[5] = 5;
bus_other.sensor_mappings[6] = 5;
bus_other.sensor_mappings[7] = 5;
bus_other.sensor_mappings[8] = 5;
bus_other.sensor_mappings[9] = 7;
bus_other.sensor_mappings[10] = 7;
bus_other.sensor_mappings[11] = 9;
bus_other.sensor_mappings[12] = 9;
bus_busbar.n_sensors = 16;
bus_other.n_sensors = 16;
CHECK_STATUS(tmp144_init_reset(&bus_busbar));
CHECK_STATUS(tmp144_init_reset(&bus_other));
@ -156,25 +134,21 @@ HAL_StatusTypeDef tmp144_recv_temps(TMP144Bus* bus) {
return HAL_ERROR;
}
// Find max temperature for each cell
uint8_t current_cell = bus->sensor_mappings[0];
uint16_t max_temp = 0;
size_t temperatures_offset = (bus == &bus_busbar) ? 0 : N_SENSORS / 2;
for (size_t i = 0; i < bus->n_sensors; i++) {
uint8_t cell = bus->sensor_mappings[i];
if (cell != current_cell) {
temperatures[current_cell] = max_temp;
current_cell = cell;
max_temp = 0;
}
size_t buf_offset = headerlen + 2 * i;
uint16_t temp =
(bus->rxbuf[buf_offset] >> 4) | (bus->rxbuf[buf_offset + 1] << 4);
if (temp > max_temp) {
max_temp = temp;
temperatures[temperatures_offset + i] = temp;
}
uint16_t max = temperatures[0];
for (size_t i = 1; i < N_SENSORS; i++) {
if (temperatures[i] > max) {
max = temperatures[i];
}
}
temperatures[current_cell] = max_temp;
max_temp = max;
return HAL_OK;
}