Save all measured temperatures
This commit is contained in:
parent
e58b9ffae0
commit
2acde9d565
@ -13,7 +13,10 @@
|
|||||||
#include "stm32f4xx_hal.h"
|
#include "stm32f4xx_hal.h"
|
||||||
#include "stm32f4xx_hal_uart.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 {
|
typedef enum {
|
||||||
TMP144_IDLE,
|
TMP144_IDLE,
|
||||||
@ -29,7 +32,6 @@ typedef struct {
|
|||||||
uint8_t rxbuf[34];
|
uint8_t rxbuf[34];
|
||||||
|
|
||||||
size_t n_sensors;
|
size_t n_sensors;
|
||||||
uint8_t sensor_mappings[16];
|
|
||||||
} TMP144Bus;
|
} TMP144Bus;
|
||||||
|
|
||||||
HAL_StatusTypeDef tmp144_init(UART_HandleTypeDef* busbar_side,
|
HAL_StatusTypeDef tmp144_init(UART_HandleTypeDef* busbar_side,
|
||||||
|
@ -7,13 +7,15 @@
|
|||||||
|
|
||||||
#include "TMP144.h"
|
#include "TMP144.h"
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
static const uint8_t TMP144_SEQ_RESET[] = {0x55, 0xB4};
|
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_ADDR[] = {0x55, 0x8C, 0x90};
|
||||||
static const uint8_t TMP144_SEQ_READ_TEMPS[] = {0x55, 0xF1};
|
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_busbar;
|
||||||
static volatile TMP144Bus bus_other;
|
static volatile TMP144Bus bus_other;
|
||||||
@ -34,32 +36,8 @@ HAL_StatusTypeDef tmp144_init(UART_HandleTypeDef* busbar_side,
|
|||||||
bus_other.state = TMP144_IDLE;
|
bus_other.state = TMP144_IDLE;
|
||||||
|
|
||||||
// TODO: Configure this in EEPROM
|
// TODO: Configure this in EEPROM
|
||||||
bus_busbar.n_sensors = 11;
|
bus_busbar.n_sensors = 16;
|
||||||
bus_busbar.sensor_mappings[0] = 8;
|
bus_other.n_sensors = 16;
|
||||||
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;
|
|
||||||
|
|
||||||
CHECK_STATUS(tmp144_init_reset(&bus_busbar));
|
CHECK_STATUS(tmp144_init_reset(&bus_busbar));
|
||||||
CHECK_STATUS(tmp144_init_reset(&bus_other));
|
CHECK_STATUS(tmp144_init_reset(&bus_other));
|
||||||
@ -156,25 +134,21 @@ HAL_StatusTypeDef tmp144_recv_temps(TMP144Bus* bus) {
|
|||||||
return HAL_ERROR;
|
return HAL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find max temperature for each cell
|
size_t temperatures_offset = (bus == &bus_busbar) ? 0 : N_SENSORS / 2;
|
||||||
uint8_t current_cell = bus->sensor_mappings[0];
|
|
||||||
uint16_t max_temp = 0;
|
|
||||||
for (size_t i = 0; i < bus->n_sensors; i++) {
|
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;
|
size_t buf_offset = headerlen + 2 * i;
|
||||||
uint16_t temp =
|
uint16_t temp =
|
||||||
(bus->rxbuf[buf_offset] >> 4) | (bus->rxbuf[buf_offset + 1] << 4);
|
(bus->rxbuf[buf_offset] >> 4) | (bus->rxbuf[buf_offset + 1] << 4);
|
||||||
if (temp > max_temp) {
|
temperatures[temperatures_offset + i] = temp;
|
||||||
max_temp = 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;
|
return HAL_OK;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user