Compare commits

..

No commits in common. "9405b3d8b8204a42bf58b74f940cda9ff19812e5" and "0dfe79e21d4d2c7fe3ea67b24d8a43e77b02bf95" have entirely different histories.

3 changed files with 13 additions and 84 deletions

View file

@ -82,7 +82,7 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle)
GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

View file

@ -93,16 +93,10 @@ PB11.Signal=GPIO_Output
PB12.GPIOParameters=GPIO_Label
PB12.GPIO_Label=DisplayCS
PB12.Signal=GPIO_Output
PB13.GPIOParameters=GPIO_Speed
PB13.GPIO_Speed=GPIO_SPEED_FREQ_MEDIUM
PB13.Mode=Full_Duplex_Master
PB13.Signal=SPI2_SCK
PB14.GPIOParameters=GPIO_Speed
PB14.GPIO_Speed=GPIO_SPEED_FREQ_MEDIUM
PB14.Mode=Full_Duplex_Master
PB14.Signal=SPI2_MISO
PB15.GPIOParameters=GPIO_Speed
PB15.GPIO_Speed=GPIO_SPEED_FREQ_MEDIUM
PB15.Mode=Full_Duplex_Master
PB15.Signal=SPI2_MOSI
PinOutPanel.RotationAngle=0

View file

@ -3,14 +3,12 @@
#include "main.h"
#include "semphr.h"
#include "spi.h"
#include "stm32l1xx_hal_flash_ex.h"
#include "task.h"
#include <cstring>
#include "BME68x-Sensor-API/bme68x.h"
#include "BSEC/bsec_interface.h"
#include "SSD1306_SPI.hpp"
#include "oled-driver/Renderer.hpp"
extern QueueHandle_t spiMutex;
@ -53,10 +51,8 @@ float iaq, rawTemperature, pressure, rawHumidity, gasResistance, stabStatus, run
uint8_t iaqAccuracy, staticIaqAccuracy, co2Accuracy, breathVocAccuracy, compGasAccuracy,
gasPercentageAcccuracy;
uint8_t bsecState[BSEC_MAX_STATE_BLOB_SIZE];
uint8_t workBuffer[BSEC_MAX_WORKBUFFER_SIZE];
constexpr uintptr_t EepromAddress = FLASH_EEPROM_BASE;
// uint8_t bsecState[BSEC_MAX_STATE_BLOB_SIZE];
// uint8_t workBuffer[BSEC_MAX_WORKBUFFER_SIZE];
void setChipSelect(bool state)
{
@ -314,94 +310,33 @@ void printBmeSensorData()
{
renderer.clearAll();
const auto MaxTextWidth = renderer.getLineWidth("1000hPa");
snprintf(buffer, MaximumChars, "%d°C\n%luhPa\n%d%%\nAcc: %d",
snprintf(buffer, MaximumChars,
"%d°C, %luhPa, %d%%\nIAQ: %d, Accuracy: %d\nCO2: %dppm\n%d, %d, %d - %lukOhm",
static_cast<int>(temperature), //
bmeData[numberOfData - 1].pressure / 100, //
static_cast<int>(humidity), //
iaqAccuracy);
renderer.print({128, 0}, buffer, Renderer::Alignment::Right);
renderer.drawVerticalLine(OledWidth - MaxTextWidth - 2, 0, OledPages - 1);
static_cast<int>(iaq), //
iaqAccuracy, //
static_cast<int>(co2Equivalent), //
bmeData[numberOfData - 1].status, //
bmeData[numberOfData - 1].gas_index, //
bmeData[numberOfData - 1].gas_wait, //
bmeData[numberOfData - 1].gas_resistance / 1000);
if (iaqAccuracy == 0)
snprintf(buffer, MaximumChars, "IAQ:---\n---ppm\n");
else
snprintf(buffer, MaximumChars, "IAQ:%d\n%dppm\n",
static_cast<int>(iaq), //
static_cast<int>(co2Equivalent));
renderer.print({0, 0}, buffer, Renderer::Alignment::Left, 2);
renderer.print({0, 0}, buffer);
renderer.render();
}
void readStateFromEeprom()
{
uint8_t sizeOfData = *reinterpret_cast<uint8_t *>(EepromAddress);
if (sizeOfData != BSEC_MAX_STATE_BLOB_SIZE)
return;
// Existing state in EEPROM
for (uint8_t i = 0; i < BSEC_MAX_STATE_BLOB_SIZE; i++)
{
bsecState[i] = *reinterpret_cast<uint8_t *>(EepromAddress + i + 1);
}
bsec_set_state(bsecState, BSEC_MAX_STATE_BLOB_SIZE, workBuffer, sizeof(workBuffer));
}
void writeStateToEeprom()
{
if (iaqAccuracy != 3)
return;
uint32_t numberSerializedState = BSEC_MAX_STATE_BLOB_SIZE;
auto status = bsec_get_state(0, bsecState, BSEC_MAX_STATE_BLOB_SIZE, workBuffer,
BSEC_MAX_STATE_BLOB_SIZE, &numberSerializedState);
if (status != BSEC_OK)
return;
HAL_FLASHEx_DATAEEPROM_Unlock();
// write size
HAL_FLASHEx_DATAEEPROM_Program(FLASH_TYPEPROGRAMDATA_BYTE, EepromAddress,
BSEC_MAX_STATE_BLOB_SIZE);
for (uint8_t i = 0; i < BSEC_MAX_STATE_BLOB_SIZE; i++)
{
HAL_FLASHEx_DATAEEPROM_Program(FLASH_TYPEPROGRAMDATA_BYTE, EepromAddress + i + 1,
bsecState[i]);
}
HAL_FLASHEx_DATAEEPROM_Lock();
}
//--------------------------------------------------------------------------------------------------
extern "C" void sensorTask(void *)
{
initDisplay();
bmeSensorInit();
readStateFromEeprom();
uint16_t counter = 0;
while (1)
{
bmeRun();
bsecRun();
printBmeSensorData();
if (counter++ >= 100)
{
initDisplay();
counter = 0;
writeStateToEeprom();
}
vTaskDelay(pdMS_TO_TICKS(10));
}
}