Started reorganizing the code. Put everything existing to OLD and began with a new main.cppy

This commit is contained in:
Matthias Mitscherlich
2024-02-29 16:53:16 +01:00
parent 29e2e14850
commit 4b31b6c618
29 changed files with 446 additions and 359 deletions
+168
View File
@@ -0,0 +1,168 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file bme280.h
/// \brief File description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
#ifndef MAIN_INC_BMP280_H_
#define MAIN_INC_BMP280_H_
/**
* bme280 implementation
* \defgroup bme280
* \brief {group_description}
* \addtogroup {Layer}
*
* Detailed description
* @{
*/
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
// CompilerIncludes
// All include files that are provided by the compiler directly
// ProjectIncludes
// All include files that are provided by the project
#include "i2c.h"
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
#define BMP280_DEVICE_ID ((uint8_t)0x58)
#define BMP280_RESET_VALUE ((uint8_t)0xB6)
// --------------------------------------------------------------------------------------------------------------------
// Type definitions.
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
class BMP280
{
public:
BMP280(I2C* bus, uint8_t slaveAddress);
typedef enum
{
STANDBY = 0,
FORCED = 1,
NORMAL = 3
} BMP280_Mode_t;
typedef enum
{
SKIPPED = 0,
X1 = 1,
X2 = 2,
X4 = 3,
X8 = 4,
X16 = 5
} BMP280_Oversampling_t;
void resetSensor(void);
bool initialize(void);
bool setSensorMode(BMP280_Mode_t mode);
bool setSensorTemperatureOversampling(BMP280_Oversampling_t oversampling);
int getTemperature(void);
private:
struct CompensationParameters
{
// Temperature compensation parameters
uint16_t dig_T1;
int16_t dig_T2;
int16_t dig_T3;
// Pressure compensation parameters
uint16_t dig_P1;
int16_t dig_P2;
int16_t dig_P3;
int16_t dig_P4;
int16_t dig_P5;
int16_t dig_P6;
int16_t dig_P7;
int16_t dig_P8;
int16_t dig_P9;
} compensationParameters;
struct memorymap
{
struct
{
uint8_t msb;
uint8_t lsb;
uint8_t xlsb;
} temperature_raw;
struct
{
uint8_t msb;
uint8_t lsb;
uint8_t xlsb;
} pressure_raw;
struct
{
uint8_t t_sb: 3;
uint8_t filter: 3;
uint8_t unused: 1;
uint8_t spi3w_en: 1;
} config;
struct
{
uint8_t mode : 2;
uint8_t oversampling_pressure : 3;
uint8_t oversampling_temp : 3;
} ctrl_meas;
uint8_t status;
uint8_t reset;
uint8_t id;
} memorymap;
int t_fine;
int temperature;
I2C* bus;
uint8_t slaveAddress;
BMP280_Mode_t mode;
void resetDriver(void);
// Communication with Device
void resetDevice(void);
void getDeviceID(void);
void setSensorControlMeasurement(void);
void setSensorConfiguration(void);
void getCompensationValues(void);
void compensateTemperature(void);
void getPreasureValues(void);
void getTemperatureValues(void);
};
/** @} */
#endif /* MAIN_INC_BMP280_H_ */
+99
View File
@@ -0,0 +1,99 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file clock.h
/// \brief File description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
#ifndef MAIN_INC_CLOCK_H_
#define MAIN_INC_CLOCK_H_
/**
* clock implementation
* \defgroup clock
* \brief {group_description}
* \addtogroup {Layer}
*
* Detailed description
* @{
*/
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
// CompilerIncludes
// All include files that are provided by the compiler directly
#include <string>
#include <list>
// ProjectIncludes
// All include files that are provided by the project
#include "time.h"
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Type definitions.
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
using namespace std;
class Clock
{
public:
enum mode
{
TEN_BEFORE_HALF,
TWENTY_OVER
};
Clock(Clock::mode mode);
void generateWordlist(list<string>* wordlist);
time_t getTime(void);
private:
Clock::mode clockmode;
time_t currentTime;
string toNumbers[20] {"zero", "one", "two", "three", "four",
"five", "six", "seven", "eight",
"nine", "ten", "eleven", "twelve",
"thirteen", "fourteen", "fifteen",
"sixteen", "seventeen", "eighteen",
"nineteen"};
// void toString(TimeStructure* timestructure);
int calculateHours(struct tm time);
};
/** @} */
#endif /* MAIN_INC_CLOCK_H_ */
+72
View File
@@ -0,0 +1,72 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file clockwordmap.h
/// \brief File description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
#ifndef MAIN_INC_CLOCKWORDMAP_H_
#define MAIN_INC_CLOCKWORDMAP_H_
/**
* clockwordmap implementation
* \defgroup clockwordmap
* \brief {group_description}
* \addtogroup {Layer}
*
* Detailed description
* @{
*/
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
// CompilerIncludes
// All include files that are provided by the compiler directly
// ProjectIncludes
// All include files that are provided by the project
#include "wordmap.h"
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Type definitions.
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
class ClockWordmap: public Wordmap
{
public:
ClockWordmap(LEDMatrix* matrix);
protected:
void createList_NL(void);
// void createList_EN(void);
};
/** @} */
#endif /* MAIN_INC_CLOCKWORDMAP_H_ */
+72
View File
@@ -0,0 +1,72 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file daywordmap.h
/// \brief File description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
#ifndef MAIN_INC_DAYWORDMAP_H_
#define MAIN_INC_DAYWORDMAP_H_
/**
* daywordmap implementation
* \defgroup daywordmap
* \brief {group_description}
* \addtogroup {Layer}
*
* Detailed description
* @{
*/
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
// CompilerIncludes
// All include files that are provided by the compiler directly
// ProjectIncludes
// All include files that are provided by the project
#include "wordmap.h"
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Type definitions.
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
class DayWordmap: public Wordmap
{
public:
DayWordmap(LEDMatrix* matrix);
protected:
void createList_NL(void);
// void createList_EN(void);
};
/** @} */
#endif /* MAIN_INC_DAYWORDMAP_H_ */
+83
View File
@@ -0,0 +1,83 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file gpio.h
/// \brief File description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
#ifndef MAIN_INC_GPIO_H_
#define MAIN_INC_GPIO_H_
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
// CompilerIncludes
// All include files that are provided by the compiler directly
// ProjectIncludes
// All include files that are provided by the project
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Type definitions.
// --------------------------------------------------------------------------------------------------------------------
typedef enum
{
GPIO_DIRECTION_INPUT = 0,
GPIO_DIRECTION_OUTPUT = 1
} GPIO_Direction_t;
typedef enum
{
GPIO_VALUE_LOW = 0,
GPIO_VALUE_HIGH = 1
} GPIO_Value_t;
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
class GPIO
{
public:
GPIO(int number, GPIO_Direction_t direction);
bool SetOutput(GPIO_Value_t value);
GPIO_Value_t GetInput(void);
private:
int number;
GPIO_Direction_t direction;
GPIO_Value_t value = GPIO_VALUE_LOW;
};
/** @} */
#endif /* MAIN_INC_GPIO_H_ */
+86
View File
@@ -0,0 +1,86 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file i2c.h
/// \brief File description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
#ifndef MAIN_INC_I2C_H_
#define MAIN_INC_I2C_H_
/**
* i2c implementation
* \defgroup i2c
* \brief {group_description}
* \addtogroup {Layer}
*
* Detailed description
* @{
*/
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
// CompilerIncludes
// All include files that are provided by the compiler directly
#include "stdint.h"
// ProjectIncludes
// All include files that are provided by the project
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Type definitions.
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
class I2C
{
public:
I2C(unsigned int SCL, unsigned int SDA);
bool write_register(uint8_t slaveAddress, uint8_t registerAddress, uint8_t* const data, uint8_t length);
bool read_register(uint8_t slaveAddress, uint8_t registerAddress, uint8_t* data, uint8_t length);
private:
static unsigned int number;
unsigned int thisNumber;
unsigned int SCL;
unsigned int SDA;
unsigned int frequency;
unsigned int timeout_ms;
void write(uint8_t slaveAddress, uint8_t registerAddress, uint8_t* const data, uint8_t length);
void read(uint8_t slaveAddress, uint8_t registerAddress, uint8_t* data, uint8_t length);
};
/** @} */
#endif /* MAIN_INC_I2C_H_ */
+36
View File
@@ -0,0 +1,36 @@
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <stdint.h>
#include "driver/rmt_encoder.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Type of led strip encoder configuration
*/
typedef struct {
uint32_t resolution; /*!< Encoder resolution, in Hz */
} led_strip_encoder_config_t;
/**
* @brief Create RMT encoder for encoding LED strip pixels into RMT symbols
*
* @param[in] config Encoder configuration
* @param[out] ret_encoder Returned encoder handle
* @return
* - ESP_ERR_INVALID_ARG for any invalid arguments
* - ESP_ERR_NO_MEM out of memory when creating led strip encoder
* - ESP_OK if creating encoder successfully
*/
esp_err_t rmt_new_led_strip_encoder(const led_strip_encoder_config_t *config, rmt_encoder_handle_t *ret_encoder);
#ifdef __cplusplus
}
#endif
+156
View File
@@ -0,0 +1,156 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file ledmatrix.h
/// \brief File description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
#ifndef MAIN_INC_LEDMATRIX_H_
#define MAIN_INC_LEDMATRIX_H_
/**
* ledmatrix implementation
* \defgroup ledmatrix
* \brief {group_description}
* \addtogroup {Layer}
*
* Detailed description
* @{
*/
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
// CompilerIncludes
// All include files that are provided by the compiler directly
#include <stdint.h>
// ProjectIncludes
// All include files that are provided by the project
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/semphr.h"
#include "driver/rmt_tx.h"
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
#define LEDMATRIX_RED_INDEX ((uint32_t)1)
#define LEDMATRIX_GREEN_INDEX ((uint32_t)0)
#define LEDMATRIX_BLUE_INDEX ((uint32_t)2)
// --------------------------------------------------------------------------------------------------------------------
// Type definitions.
// --------------------------------------------------------------------------------------------------------------------
typedef enum
{
LEDMATRIX_ORIENTATION_ROW_LEFT_RIGHT,
LEDMATRIX_ORIENTATION_ROW_RIGHT_LEFT
} LEDMatrix_Orientation_Row_t;
typedef enum
{
LEDMATRIX_ORIENTATION_COLUM_UP_DOWN,
LEDMATRIX_ORIENTATION_COLUM_DOWN_UP
} LEDMatrix_Orientation_Colum_t;
typedef enum
{
LEDMATRIX_ORIENTATION_ROW,
LEDMATRIX_ORIENTATION_COLUM
}LEDMatrix_Orientation_t;
typedef struct
{
LEDMatrix_Orientation_Row_t rowOrientation;
LEDMatrix_Orientation_Colum_t columOrientation;
LEDMatrix_Orientation_t matrixOrientation;
unsigned int width;
unsigned int height;
// RMT objects for transmission
rmt_channel_handle_t* rmtChannel;
rmt_encoder_handle_t* rmtEncoder;
rmt_transmit_config_t* rmtConfig;
} LEDMatrix_Parameters_t;
typedef struct
{
bool on;
uint8_t red;
uint8_t green;
uint8_t blue;
} LEDMatrix_Pixel_t;
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
class LEDMatrix
{
public:
struct coordinate
{
int x;
int y;
};
LEDMatrix(LEDMatrix_Parameters_t* parameters);
bool setPixelValue(unsigned int colum, unsigned int row, bool value);
void setGlobalColour(uint8_t red, uint8_t green, uint8_t blue);
void setPixelColour(unsigned int colum, unsigned int row, uint8_t red, uint8_t green, uint8_t blue);
void clear(void);
BaseType_t tick(void);
protected:
unsigned int findPixelIndexFromCoordinates(unsigned int colum, unsigned int row);
private:
LEDMatrix_Parameters_t parameters;
LEDMatrix_Pixel_t* matrix;
uint8_t* tx_matrix;
unsigned int numberOfPixels;
static bool initialized;
static TaskHandle_t matrixTaskHandle;
static SemaphoreHandle_t taskSemaphore;
static void matrixTask(void* parameters);
};
inline BaseType_t LEDMatrix::tick(void)
{
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
if (LEDMatrix::initialized)
{
xSemaphoreGiveFromISR(LEDMatrix::taskSemaphore, &xHigherPriorityTaskWoken);
}
return xHigherPriorityTaskWoken;
}
/** @} */
#endif /* MAIN_INC_LEDMATRIX_H_ */
+196
View File
@@ -0,0 +1,196 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file logger.h
/// \brief File description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
#ifndef MAIN_INC_LOGGER_H_
#define MAIN_INC_LOGGER_H_
/**
* Logger implementation
* \defgroup Logger
* \brief Implementation of a non-blocking logger for debug purpose
* \ingroup Platform
*
* A non-blocking logger that implements its own task with very low (unimportant)
* priority
* @{
*/
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
// CompilerIncludes
// All include files that are provided by the compiler directly
#include <stdbool.h>
#include <stdint.h>
// ProjectIncludes
// All include files that are provided by the project
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "freertos/semphr.h"
#include "driver/uart_select.h"
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
/**
* Logs an error
* \memberof Logger
*/
#define LOGGER_ERROR(...) \
Logger::Logger_log(__FILE__, __func__, __LINE__, LOGTYPE_ERROR, ##__VA_ARGS__)
/**
* Logs a success
* \memberof Logger
*/
#define LOGGER_SUCCESS(...) \
Logger::Logger_log(__FILE__, __func__, __LINE__, LOGTYPE_SUCCESS, ##__VA_ARGS__)
/**
* Logs an error
* \memberof Logger
*/
#define LOGGER_WARNING(...) \
Logger::Logger_log(__FILE__, __func__, __LINE__, LOGTYPE_WARNING, ##__VA_ARGS__)
/**
* Logs an error
* \memberof Logger
*/
#define LOGGER_INFO(...) \
Logger::Logger_log(__FILE__, __func__, __LINE__, LOGTYPE_INFO, ##__VA_ARGS__)
/**
* Logs an error
* \memberof Logger
*/
#define LOGGER_DEBUG(...) \
Logger::Logger_log(__FILE__, __func__, __LINE__, LOGTYPE_DEBUG, ##__VA_ARGS__)
/**
* Logs an error
* \memberof Logger
*/
#define LOGGER_PRINT(...) \
Logger::Logger_log("", "", 0, LOGTYPE_PRINT, ##__VA_ARGS__)
/**
* Logs an error
* \memberof Logger
*/
#define LOGGER_ERROR_ISR(...) \
Logger::Logger_logISR(__FILE__, __func__, __LINE__, LOGTYPE_ERROR, ##__VA_ARGS__)
/**
* Logs a success
* \memberof Logger
*/
#define LOGGER_SUCCESS_ISR(...) \
Logger::Logger_logISR(__FILE__, __func__, __LINE__, LOGTYPE_ERROR, ##__VA_ARGS__)
/**
* Logs an error
* \memberof Logger
*/
#define LOGGER_WARNING_ISR(...) \
Logger::Logger_logISR(__FILE__, __func__, __LINE__, LOGTYPE_WARNING, ##__VA_ARGS__)
/**
* Logs an error
* \memberof Logger
*/
#define LOGGER_INFO_ISR(...) \
Logger::Logger_logISR(__FILE__, __func__, __LINE__, LOGTYPE_INFO, ##__VA_ARGS__)
/**
* Logs an error
* \memberof Logger
*/
#define LOGGER_DEBUG_ISR(a, ...) \
Logger::Logger_logISR(a, __FILE__, __func__, __LINE__, LOGTYPE_DEBUG, ##__VA_ARGS__)
/**
* Logs an error
* \memberof Logger
*/
#define LOGGER_PRINT_ISR(a, ...) \
Logger::Logger_logISR(a, "", "", 0, LOGTYPE_PRINT, ##__VA_ARGS__)
// --------------------------------------------------------------------------------------------------------------------
// Type definitions.
// --------------------------------------------------------------------------------------------------------------------
typedef enum
{
LOGTYPE_PRINT, /**< Raw print */
LOGTYPE_DEBUG, /**< Debug information only; will not be stored on SD-card */
LOGTYPE_INFO, /**< Informational messages of important events */
LOGTYPE_WARNING, /**< Recoverable fault */
LOGTYPE_SUCCESS, /**< A specific success message */
LOGTYPE_ERROR /**< Unrecoverable fault */
} LogType;
struct LogQueueItem
{
char fileName[32];
char functionName[32];
char context[128];
int lineNumber;
LogType logType;
};
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
class Logger
{
public:
static uart_port_t uartPort;
static int queuesize;
static QueueHandle_t logQueue;
Logger(int queuesize, uart_port_t uartPort);
static void Logger_log(const char* fileName, const char* functionName, int lineNumber, LogType logType, const char* format, ...);
static void Logger_logISR(struct Logger* self, const char* fileName, const char* functionName, int lineNumber, LogType logType, const char* context);
private:
static TaskHandle_t logTaskHandle;
static void loggerTask(void* parameters);
static void composeLogQueueItem(struct LogQueueItem* logQueueItem, const char* fileName, const char* functionName,
int lineNumber, LogType logType, const char* context);
};
/** @} */
#endif /* MAIN_INC_LOGGER_H_ */
+80
View File
@@ -0,0 +1,80 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file temperature.h
/// \brief File description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
#ifndef MAIN_INC_TEMPERATURE_H_
#define MAIN_INC_TEMPERATURE_H_
/**
* temperature implementation
* \defgroup temperature
* \brief {group_description}
* \addtogroup {Layer}
*
* Detailed description
* @{
*/
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
// CompilerIncludes
// All include files that are provided by the compiler directly
#include <string>
#include <list>
// ProjectIncludes
// All include files that are provided by the project
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Type definitions.
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
using namespace std;
class Temperature
{
public:
Temperature(void);
void generateWordlist(int temperature, list<string>* wordlist);
void calculateRGB(int temperature, uint8_t* red, uint8_t* green, uint8_t* blue);
private:
int minTemperature;
int maxTemperature;
};
/** @} */
#endif /* MAIN_INC_TEMPERATURE_H_ */
+73
View File
@@ -0,0 +1,73 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file TemperatureWordmap.h
/// \brief File description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
#ifndef MAIN_INC_TEMPERATUREWORDMAP_H_
#define MAIN_INC_TEMPERATUREWORDMAP_H_
/**
* TemperatureWordmap implementation
* \defgroup TemperatureWordmap
* \brief {group_description}
* \addtogroup {Layer}
*
* Detailed description
* @{
*/
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
// CompilerIncludes
// All include files that are provided by the compiler directly
// ProjectIncludes
// All include files that are provided by the project
#include "wordmap.h"
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Type definitions.
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
class TemperatureWordmap: public Wordmap
{
public:
TemperatureWordmap(LEDMatrix* matrix);
protected:
void createList_NL(void);
// void createList_EN(void);
};
/** @} */
#endif /* MAIN_INC_TEMPERATUREWORDMAP_H_ */
+86
View File
@@ -0,0 +1,86 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file wifi.h
/// \brief File description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
#ifndef MAIN_INC_WIFI_H_
#define MAIN_INC_WIFI_H_
/**
* wifi implementation
* \defgroup wifi
* \brief {group_description}
* \addtogroup {Layer}
*
* Detailed description
* @{
*/
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
// CompilerIncludes
// All include files that are provided by the compiler directly
#include "esp_system.h"
#include "esp_event.h"
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
// ProjectIncludes
// All include files that are provided by the project
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Type definitions.
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
class Wifi
{
public:
Wifi(void);
void start_client(void);
private:
static EventGroupHandle_t s_wifi_event_group;
static int s_retry_num;
static const char *TAG;
static void event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data);
};
/** @} */
#endif /* MAIN_INC_WIFI_H_ */
+107
View File
@@ -0,0 +1,107 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file wordmap.h
/// \brief File description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
#ifndef MAIN_INC_WORDMAP_H_
#define MAIN_INC_WORDMAP_H_
/**
* wordmap implementation
* \defgroup wordmap
* \brief {group_description}
* \addtogroup {Layer}
*
* Detailed description
* @{
*/
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
// CompilerIncludes
// All include files that are provided by the compiler directly
#include <string>
#include <list>
// ProjectIncludes
// All include files that are provided by the project
#include "ledmatrix.h"
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Type definitions.
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
using namespace std;
class Wordmap
{
public:
typedef enum language
{
NL = 0,
EN,
NumberOfLanguages
} Language_t;
Wordmap(LEDMatrix* matrix);
bool setColour(uint8_t red, uint8_t green, uint8_t blue);
bool setWord(Language_t lang, string identifier, bool value);
protected:
struct word
{
string identifier;
list<LEDMatrix::coordinate> pixels;
// LEDMatrix::coordinate position;
// int length;
};
LEDMatrix* matrix;
language language;
list<struct word> wordlist[NumberOfLanguages];
void createList_NL(void);
void createList_EN(void);
uint8_t red;
uint8_t green;
uint8_t blue;
};
/** @} */
#endif /* MAIN_INC_WORDMAP_H_ */
+415
View File
@@ -0,0 +1,415 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file main
/// \brief Description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
#include <string>
#include<cstring>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_event.h"
#include "esp_log.h"
#include "esp_wifi.h"
#include "nvs_flash.h"
#include "driver/gpio.h"
#include "driver/rmt_tx.h"
#include "driver/uart_select.h"
#include "driver/gptimer.h"
#include "inc/bmp280.h"
#include "inc/gpio.h"
#include "inc/i2c.h"
#include "inc/led_strip_encoder.h"
#include "inc/ledmatrix.h"
#include "inc/logger.h"
#include "inc/wifi.h"
#include "clock.h"
#include "clockwordmap.h"
#include "daywordmap.h"
#include "temperaturewordmap.h"
#include "temperature.h"
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
#define RMT_LED_STRIP_RESOLUTION_HZ 10000000 // 10MHz resolution, 1 tick = 0.1us (led strip needs a high resolution)
#define RMT_LED_STRIP_GPIO_NUM 0
// --------------------------------------------------------------------------------------------------------------------
// Type definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// File-scope variables
// --------------------------------------------------------------------------------------------------------------------
static const uart_port_t uartPort = UART_NUM_0;
static TaskHandle_t devTaskHandle = NULL;
static TaskHandle_t colourMapTaskHandle = NULL;
// GPIOs
static GPIO led_rgb_red(3, GPIO_DIRECTION_OUTPUT);
static GPIO led_rgb_green(4, GPIO_DIRECTION_OUTPUT);
static GPIO led_rgb_blue(5, GPIO_DIRECTION_OUTPUT);
static GPIO led_orange(18, GPIO_DIRECTION_OUTPUT);
// -------------------------------------------------------
// LED Matrix components
static rmt_channel_handle_t led_chan = NULL;
static rmt_transmit_config_t tx_config;
static rmt_encoder_handle_t led_encoder = NULL;
static LEDMatrix_Parameters_t ledmatrix_parameters =
{
LEDMATRIX_ORIENTATION_ROW_LEFT_RIGHT,
LEDMATRIX_ORIENTATION_COLUM_UP_DOWN,
LEDMATRIX_ORIENTATION_ROW,
20,
13,
&led_chan,
&led_encoder,
&tx_config
};
static LEDMatrix matrix(&ledmatrix_parameters);
static ClockWordmap clockWordmap(&matrix);
static DayWordmap dayWordmap(&matrix);
static TemperatureWordmap tempWordmap(&matrix);
static gptimer_handle_t matrixRefreshTimer = NULL;
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
// Simple countdown on display
static void countdown(int delay);
// Timer Callback for the LEDMatrix refresh
static bool timerCallback(gptimer_handle_t timer, const gptimer_alarm_event_data_t *edata, void *user_data);
static void devTask(void* parameters);
static void colourMapTask(void* parameters);
// --------------------------------------------------------------------------------------------------------------------
// Function definitions
// --------------------------------------------------------------------------------------------------------------------
extern "C" void app_main(void)
{
esp_log_level_set("*", ESP_LOG_WARN);
esp_err_t ret = nvs_flash_init();
if(ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND)
{
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
//--------------------------------------------
// UART
//
const uart_config_t uartConfig =
{
.baud_rate = 115200,
.data_bits = UART_DATA_8_BITS,
.parity = UART_PARITY_DISABLE,
.stop_bits = UART_STOP_BITS_1,
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
.rx_flow_ctrl_thresh = 0,
.source_clk = UART_SCLK_DEFAULT
};
ESP_ERROR_CHECK(uart_param_config(uartPort, &uartConfig));
ESP_ERROR_CHECK(uart_set_pin(uartPort, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE));
ESP_ERROR_CHECK(uart_driver_install(uartPort, 1024, 1024, 0, NULL, 0));
//--------------------------------------------
// LOGGER
//
Logger logger(10, uartPort);
LOGGER_PRINT("\n\r-----------------------------------------------------------------------\n\r");
LOGGER_PRINT("System Start\n\r");
LOGGER_PRINT("\n\r");
LOGGER_PRINT("WordClock\n\r");
LOGGER_PRINT("Release: %f\n\r", RELEASE);
LOGGER_PRINT("Compiled on %d %d\n\r\n\r\n\r", __TIME__, __DATE__);
//--------------------------------------------
// RMT Channel
//
LOGGER_INFO("Create RMT TX channel");
rmt_tx_channel_config_t tx_chan_config;
memset(&tx_chan_config, 0, sizeof(tx_chan_config));
tx_chan_config.clk_src = RMT_CLK_SRC_DEFAULT; // select source clock
tx_chan_config.gpio_num = (gpio_num_t)RMT_LED_STRIP_GPIO_NUM;
tx_chan_config.mem_block_symbols = 64; // increase the block size can make the LED less flickering
tx_chan_config.resolution_hz = RMT_LED_STRIP_RESOLUTION_HZ;
tx_chan_config.trans_queue_depth = 4;
ESP_ERROR_CHECK(rmt_new_tx_channel(&tx_chan_config, &led_chan));
LOGGER_INFO("Install led strip encoder");
led_strip_encoder_config_t encoder_config;
memset(&encoder_config, 0, sizeof(encoder_config));
encoder_config.resolution = RMT_LED_STRIP_RESOLUTION_HZ;
ESP_ERROR_CHECK(rmt_new_led_strip_encoder(&encoder_config, &led_encoder));
LOGGER_INFO("Enable RMT TX channel");
ESP_ERROR_CHECK(rmt_enable(led_chan));
memset(&tx_config, 0, sizeof(tx_config));
tx_config.loop_count = 0;
//--------------------------------------------
// I2C
//
// SourceClock: GPIO 8
// SourceData: GPIO 9
I2C i2c0(8, 9);
//--------------------------------------------
// BMP280
//
// Communicates on I2C i2c0
// Has slave address 0x76
BMP280 bmp280(&i2c0, 0x76);
// Reset the sensor
bmp280.resetSensor();
// Make sure to apply a wait cycle between reset and continuous use - 2ms is advised as minimum
vTaskDelay(10);
// Initialize the BMP280
bmp280.initialize();
// Set the temperature Oversampling
bmp280.setSensorTemperatureOversampling(BMP280::BMP280_Oversampling_t::X1);
// Set the sensor to NORMAL mode
bmp280.setSensorMode(BMP280::BMP280_Mode_t::NORMAL);
Temperature temperature;
//--------------------------------------------
// LED Matrix
//
matrix.setGlobalColour(0x10, 0, 0x04);
//--------------------------------------------
// GP Timer for automatic matrix re-draw trigger
//
gptimer_config_t timer_config = { };
gptimer_event_callbacks_t cbs = { };
gptimer_alarm_config_t alarm_config = { };
timer_config.clk_src = GPTIMER_CLK_SRC_DEFAULT;
timer_config.direction = GPTIMER_COUNT_UP;
timer_config.resolution_hz = 1000000; // 1 MHz
cbs.on_alarm = timerCallback;
alarm_config.reload_count = 0;
alarm_config.alarm_count = timer_config.resolution_hz / 60;
alarm_config.flags.auto_reload_on_alarm = true;
ESP_ERROR_CHECK(gptimer_new_timer(&timer_config, &matrixRefreshTimer));
ESP_ERROR_CHECK(gptimer_register_event_callbacks(matrixRefreshTimer, &cbs, NULL));
ESP_ERROR_CHECK(gptimer_enable(matrixRefreshTimer));
ESP_ERROR_CHECK(gptimer_set_alarm_action(matrixRefreshTimer, &alarm_config));
ESP_ERROR_CHECK(gptimer_start(matrixRefreshTimer));
// Create the development task
if(xTaskCreate(devTask, "DevTask", 2048, NULL, 3, &devTaskHandle) != pdPASS)
{
LOGGER_ERROR("Task not created");
}
// Create the colour Map task
if(xTaskCreate(colourMapTask, "ColourTask", 2048, NULL, 3, &colourMapTaskHandle) != pdPASS)
{
LOGGER_ERROR("Task not created");
}
Wifi wifi;
wifi.start_client();
Clock clock(Clock::mode::TEN_BEFORE_HALF);
clockWordmap.setColour(0xFF, 0xFF, 0x00);
dayWordmap.setColour(0x20, 0xCC, 0x80);
// countdown(1000);
list<string> clockWordlist;
list<string> tempWordList;
while (true)
{
clock.generateWordlist(&clockWordlist);
matrix.clear();
std::list<string>::iterator it;
for(it = clockWordlist.begin(); it != clockWordlist.end(); it++)
{
clockWordmap.setWord(Wordmap::Language_t::NL, *it, true);
dayWordmap.setWord(Wordmap::Language_t::NL, *it, true);
}
// Get the temperature from sensor
int currentTemperature = bmp280.getTemperature() / 100;
LOGGER_INFO("The current temperature is: %i (%s)", currentTemperature, to_string(21));
// Generate temperature wordlist
temperature.generateWordlist(currentTemperature, &tempWordList);
for(it = tempWordList.begin(); it != tempWordList.end(); it++)
{
tempWordmap.setWord(Wordmap::Language_t::NL, *it, true);
}
uint8_t tRed, tGreen, tBlue;
temperature.calculateRGB(currentTemperature, &tRed, &tGreen, &tBlue);
tempWordmap.setColour(tRed, tGreen, tBlue);
// Add a seconds indicator
matrix.setPixelValue(11, 11, clock.getTime() % 2);
// Update the matrix
matrix.tick();
// Update the clock every second (1000 ms)
vTaskDelay(1000);
}
}
static void devTask(void* parameters)
{
uint32_t counter = 0;
printf("DevTask created");
while (true)
{
(void)led_orange.SetOutput((GPIO_Value_t)(counter % 2));
counter++;
vTaskDelay(500);
}
}
static void colourMapTask(void* parameters)
{
uint8_t red = 0xF0;
uint8_t green = 0x20;
uint8_t blue = 0xF0;
// uint8_t red = 0x00;
// uint8_t green = 0x00;
// uint8_t blue = 0x00;
uint32_t counter = 0;
while (true)
{
// red = 0;
// green = 0;
// blue = 0;
// if ((counter % 2) == 0)
// {
// red = 0xFF;
// }
// if ((counter % 5) == 0)
// {
// green = 0xFF;
// }
// if ((counter % 9) == 0)
// {
// blue = 0xFF;
// }
// matrix.setGlobalColour(red, green, blue);
// red = counter & 0xFF;
// green = (counter >> 8) & 0xFF;
// blue = (counter >> 16) & 0xFF;
counter++;
vTaskDelay(200);
}
}
static void countdown(int delay)
{
clockWordmap.setWord(Wordmap::Language_t::NL, "ten", true);
vTaskDelay(delay);
clockWordmap.setWord(Wordmap::Language_t::NL, "ten", false);
clockWordmap.setWord(Wordmap::Language_t::NL, "nine", true);
vTaskDelay(delay);
clockWordmap.setWord(Wordmap::Language_t::NL, "nine", false);
clockWordmap.setWord(Wordmap::Language_t::NL, "eight", true);
vTaskDelay(delay);
clockWordmap.setWord(Wordmap::Language_t::NL, "eight", false);
clockWordmap.setWord(Wordmap::Language_t::NL, "seven", true);
vTaskDelay(delay);
clockWordmap.setWord(Wordmap::Language_t::NL, "seven", false);
clockWordmap.setWord(Wordmap::Language_t::NL, "six", true);
vTaskDelay(delay);
clockWordmap.setWord(Wordmap::Language_t::NL, "six", false);
clockWordmap.setWord(Wordmap::Language_t::NL, "five", true);
vTaskDelay(delay);
clockWordmap.setWord(Wordmap::Language_t::NL, "five", false);
clockWordmap.setWord(Wordmap::Language_t::NL, "four", true);
vTaskDelay(delay);
clockWordmap.setWord(Wordmap::Language_t::NL, "four", false);
clockWordmap.setWord(Wordmap::Language_t::NL, "three", true);
vTaskDelay(delay);
clockWordmap.setWord(Wordmap::Language_t::NL, "three", false);
clockWordmap.setWord(Wordmap::Language_t::NL, "two", true);
vTaskDelay(delay);
clockWordmap.setWord(Wordmap::Language_t::NL, "two", false);
clockWordmap.setWord(Wordmap::Language_t::NL, "one", true);
vTaskDelay(delay);
clockWordmap.setWord(Wordmap::Language_t::NL, "one", false);
}
static bool IRAM_ATTR timerCallback(gptimer_handle_t timer, const gptimer_alarm_event_data_t *edata, void *user_data)
{
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
// xHigherPriorityTaskWoken = matrix.tick();
return xHigherPriorityTaskWoken == pdTRUE;
}
+191
View File
@@ -0,0 +1,191 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file bme280.cpp
/// \brief Description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
#include <bmp280.h>
#include "logger.h"
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
// List of registers
#define ADDRESS_COMP_PARAMETERS ((uint32_t)0x88)
#define ADDRESS_REG_ID ((uint32_t)0xD0)
#define ADDRESS_REG_RESET ((uint32_t)0xE0)
#define ADDRESS_REG_STATUS ((uint32_t)0xF3)
#define ADDRESS_REG_CTRL_MEAS ((uint32_t)0xF4)
#define ADDRESS_REG_CONFIG ((uint32_t)0xF5)
#define ADDRESS_REG_PRESSURE_MSB ((uint32_t)0xF7)
#define ADDRESS_REG_PRESSURE_LSB ((uint32_t)0xF8)
#define ADDRESS_REG_PRESSURE_XLSB ((uint32_t)0xF9)
#define ADDRESS_REG_TEMPERATURE_MSB ((uint32_t)0xFA)
#define ADDRESS_REG_TEMPERATURE_LSB ((uint32_t)0xFB)
#define ADDRESS_REG_TEMPERATURE_XLSB ((uint32_t)0xFC)
// --------------------------------------------------------------------------------------------------------------------
// Type definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// File-scope variables
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function definitions
// --------------------------------------------------------------------------------------------------------------------
BMP280::BMP280(I2C* bus, uint8_t slaveAddress)
{
// Take over the bus
BMP280::bus = bus;
// Take over the device slave address
BMP280::slaveAddress = slaveAddress;
// Reset the driver itself
resetDriver();
// Reset the device
}
void BMP280::resetSensor(void)
{
resetDevice();
}
bool BMP280::initialize(void)
{
bool returnValue = true;
// First read the device ID
getDeviceID();
// Device ID must match, otherwise there is a component error
if (memorymap.id != BMP280_DEVICE_ID)
{
returnValue = false;
}
if (returnValue)
{
// Get the compensation values from the device
getCompensationValues();
}
return returnValue;
}
bool BMP280::setSensorMode(BMP280_Mode_t mode)
{
bool returnValue = true;
memorymap.ctrl_meas.mode = mode;
setSensorControlMeasurement();
return returnValue;
}
bool BMP280::setSensorTemperatureOversampling(BMP280_Oversampling_t oversampling)
{
bool returnValue = true;
memorymap.ctrl_meas.oversampling_temp = oversampling;
setSensorControlMeasurement();
return returnValue;
}
int BMP280::getTemperature(void)
{
// Get latest raw values from device
BMP280::getTemperatureValues();
// Calculate temperature
BMP280::compensateTemperature();
// return the value
return temperature;
}
void BMP280::resetDriver(void)
{
// Reset the parameters
BMP280::compensationParameters = {};
// Reset the device memory map
BMP280::memorymap = {};
// Reset the mode
BMP280::mode = STANDBY;
// Reset calculation values
t_fine = 0;
temperature = 0;
}
void BMP280::getDeviceID(void)
{
bus->read_register(slaveAddress, ADDRESS_REG_ID, &memorymap.id, 1);
}
void BMP280::resetDevice(void)
{
uint8_t resetValue = BMP280_RESET_VALUE;
bus->write_register(slaveAddress, ADDRESS_REG_RESET, &resetValue, 1);
}
void BMP280::setSensorControlMeasurement(void)
{
bus->write_register(slaveAddress, ADDRESS_REG_CTRL_MEAS, (uint8_t*)&memorymap.ctrl_meas, 1);
}
void BMP280::setSensorConfiguration(void)
{
bus->write_register(slaveAddress, ADDRESS_REG_CONFIG, (uint8_t*)&memorymap.config, 1);
}
void BMP280::getCompensationValues(void)
{
bus->read_register(slaveAddress, ADDRESS_COMP_PARAMETERS, (uint8_t*)&compensationParameters, sizeof(compensationParameters));
LOGGER_DEBUG("Got compensation values: %04X %04X %04X", compensationParameters.dig_T1, compensationParameters.dig_T2, compensationParameters.dig_T3);
}
void BMP280::getPreasureValues(void)
{
bus->read_register(slaveAddress, ADDRESS_REG_PRESSURE_LSB, (uint8_t*)&memorymap.pressure_raw, sizeof(memorymap.pressure_raw));
}
void BMP280::getTemperatureValues(void)
{
bus->read_register(slaveAddress, ADDRESS_REG_TEMPERATURE_MSB, (uint8_t*)&memorymap.temperature_raw, sizeof(memorymap.temperature_raw));
}
void BMP280::compensateTemperature(void)
{
int adc_T = 0;
// Create a single temperature value from the individual memory entries
adc_T |= memorymap.temperature_raw.msb << 12;
adc_T |= memorymap.temperature_raw.lsb << 4;
// XLSB is only a nibble
adc_T |= memorymap.temperature_raw.xlsb >> 4;
int var1 = ((((adc_T >> 3) - ((int)compensationParameters.dig_T1<<1))) * ((int)compensationParameters.dig_T2)) >> 11;
int var2 = (((((adc_T>>4) - ((int)compensationParameters.dig_T1)) * ((adc_T>>4) - ((int)compensationParameters.dig_T1))) >> 12) * ((int)compensationParameters.dig_T3)) >> 14;
t_fine = var1 + var2;
temperature = (t_fine * 5 + 128) >> 8;
}
+231
View File
@@ -0,0 +1,231 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file clock.cpp
/// \brief Description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
#include "clock.h"
#include "esp_sntp.h"
#include "esp_wifi.h"
#include "logger.h"
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Type definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// File-scope variables
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function definitions
// --------------------------------------------------------------------------------------------------------------------
Clock::Clock(Clock::mode mode)
{
Clock::currentTime = 40000;
Clock::clockmode = mode;
// Start NTP
setenv("TZ", "CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00", 1);
tzset();
esp_sntp_setoperatingmode(ESP_SNTP_OPMODE_POLL);
esp_sntp_setservername(0, "pool.ntp.org");
esp_sntp_init();
}
void Clock::generateWordlist(list<string>* wordlist)
{
struct tm tm;
time(&currentTime);
// currentTime += 100;
localtime_r(&currentTime, &tm);
// LOGGER_INFO("%lld\n\r", currentTime);
// LOGGER_INFO("%02i:%02i:%02i\n\r", tm.tm_hour, tm.tm_min, tm.tm_sec);
wordlist->clear();
wordlist->push_back("it");
wordlist->push_back("is");
wordlist->push_back(toNumbers[calculateHours(tm)]);
if (tm.tm_min < 4)
{
wordlist->push_back("hours");
}
else if (tm.tm_min < 9)
{
wordlist->push_back("ind_five");
wordlist->push_back("after");
}
else if (tm.tm_min < 14)
{
wordlist->push_back("ind_ten");
wordlist->push_back("after");
}
else if (tm.tm_min < 19)
{
wordlist->push_back("ind_quart");
wordlist->push_back("after");
}
else if (tm.tm_min < 24)
{
wordlist->push_back("ind_ten");
wordlist->push_back("before");
wordlist->push_back("half");
}
else if (tm.tm_min < 28)
{
wordlist->push_back("ind_five");
wordlist->push_back("before");
wordlist->push_back("half");
}
else if (tm.tm_min < 30)
{
wordlist->push_back("almost");
wordlist->push_back("half");
}
else if (tm.tm_min < 34)
{
wordlist->push_back("half");
}
else if (tm.tm_min < 39)
{
wordlist->push_back("ind_five");
wordlist->push_back("after");
wordlist->push_back("half");
}
else if (tm.tm_min < 44)
{
wordlist->push_back("ind_ten");
wordlist->push_back("after");
wordlist->push_back("half");
}
else if (tm.tm_min < 49)
{
wordlist->push_back("ind_quart");
wordlist->push_back("before");
}
else if (tm.tm_min < 54)
{
wordlist->push_back("ind_ten");
wordlist->push_back("before");
}
else if (tm.tm_min < 58)
{
wordlist->push_back("ind_five");
wordlist->push_back("before");
}
else
{
wordlist->push_back("almost");
wordlist->push_back("hours");
}
// Attach the day as a word, too
switch (tm.tm_wday)
{
case 0:
wordlist->push_back("sunday");
break;
case 1:
wordlist->push_back("monday");
break;
case 2:
wordlist->push_back("tuesday");
break;
case 3:
wordlist->push_back("wednesday");
break;
case 4:
wordlist->push_back("thursday");
break;
case 5:
wordlist->push_back("friday");
break;
case 6:
wordlist->push_back("saturday");
break;
default:
wordlist->push_back("sunday");
}
}
time_t Clock::getTime(void)
{
// time(&currentTime);
return currentTime;
}
int Clock::calculateHours(struct tm time)
{
int hours = time.tm_hour;
// Add one hour in case the clock is heading towards half
if (time.tm_min > 19)
{
hours = hours + 1;
}
// Calculate hours to 12hour system
if (hours > 12)
{
hours = hours - 12;
}
// Start at 1, not 0
if (hours == 0)
{
hours++;
}
return hours;
}
//void Clock::toString(TimeStructure* timestructure)
//{
// LOGGER_SUCCESS("%s%s%s%s%d%s", timestructure->prefix ? "Het is " : "",
// timestructure->fifths == Five ? "Vijf " :
// timestructure->fifths == Ten ? "Tien " :
// timestructure->fifths == Quarter ? "kwart ": "",
// timestructure->beforeAfter == Before ? "voor " :
// timestructure->beforeAfter == After ? "over " : "",
// timestructure->half ? "half " : "",
// timestructure->hours,
// timestructure->hourPostfix ? " uur" : ""
// );
//}
+95
View File
@@ -0,0 +1,95 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file clockwordmap.cpp
/// \brief Description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
#include "clockwordmap.h"
#include "logger.h"
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Type definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// File-scope variables
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function definitions
// --------------------------------------------------------------------------------------------------------------------
ClockWordmap::ClockWordmap(LEDMatrix* matrix) : Wordmap(matrix)
{
createList_NL();
createList_EN();
}
void ClockWordmap::createList_NL(void)
{
// First, clear the list
wordlist[NL].clear();
// Now lets add all relevant words
wordlist[NL].push_back((struct word){"it", {{0,0},{1,0},{2,0}}});
wordlist[NL].push_back((struct word){"is", {{4,0},{5,0}}});
wordlist[NL].push_back((struct word){"ind_five", {{7,0},{8,0},{9,0},{10,0}}});
wordlist[NL].push_back((struct word){"ind_ten", {{1,1},{2,1},{3,1},{4,1}}});
wordlist[NL].push_back((struct word){"ind_quart", {{6,1},{7,1},{8,1},{9,1},{10,1}}});
wordlist[NL].push_back((struct word){"ind_twenty", {{0,2},{1,2},{2,2},{3,2},{4,2},{5,2},{6,2}}});
wordlist[NL].push_back((struct word){"before", {{6,3},{7,3},{8,3},{9,3}}});
wordlist[NL].push_back((struct word){"after", {{1,3},{2,3},{3,3},{4,3}}});
wordlist[NL].push_back((struct word){"almost", {{0,4},{1,4},{2,4},{3,4},{4,4}}});
wordlist[NL].push_back((struct word){"half", {{7,4},{8,4},{9,4},{10,4}}});
wordlist[NL].push_back((struct word){"one", {{3,5},{4,5},{5,5}}});
wordlist[NL].push_back((struct word){"two", {{1,5},{2,5},{3,5},{4,5}}});
wordlist[NL].push_back((struct word){"three", {{6,5},{7,5},{8,5},{9,5}}});
wordlist[NL].push_back((struct word){"four", {{7,6},{8,6},{9,6},{10,6}}});
wordlist[NL].push_back((struct word){"five", {{0,6},{1,6},{2,6},{3,6}}});
wordlist[NL].push_back((struct word){"six", {{4,6},{5,6},{6,6}}});
wordlist[NL].push_back((struct word){"seven", {{0,7},{1,7},{2,7},{3,7},{4,7}}});
wordlist[NL].push_back((struct word){"eight", {{0,8},{1,8},{2,8},{3,8}}});
wordlist[NL].push_back((struct word){"nine", {{6,7},{7,7},{8,7},{9,7},{10,7}}});
wordlist[NL].push_back((struct word){"ten", {{4,8},{5,8},{6,8},{7,8}}});
wordlist[NL].push_back((struct word){"eleven", {{8,8},{9,8},{10,8}}});
wordlist[NL].push_back((struct word){"twelve", {{0,9},{1,9},{2,9},{3,9},{4,9},{5,9}}});
wordlist[NL].push_back((struct word){"hours", {{8,9},{9,9},{10,9}}});
}
+76
View File
@@ -0,0 +1,76 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file daywordmap.cpp
/// \brief Description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
#include "daywordmap.h"
#include "logger.h"
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Type definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// File-scope variables
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function definitions
// --------------------------------------------------------------------------------------------------------------------
DayWordmap::DayWordmap(LEDMatrix* matrix) : Wordmap(matrix)
{
createList_NL();
createList_EN();
}
void DayWordmap::createList_NL(void)
{
// First, clear the list
wordlist[NL].clear();
// Now lets add all relevant words
wordlist[NL].push_back((struct word){"monday", {{0,12},{1,12},{2,12},{3,12},{4,12},{5,12},{6,12}}});
wordlist[NL].push_back((struct word){"tuesday", {{13,12},{14,12},{15,12},{16,12},{17,12},{18,12},{19,12}}});
wordlist[NL].push_back((struct word){"wednesday", {{11,10},{12,10},{13,10},{14,10},{15,10},{16,10},{17,10},{18,10}}});
wordlist[NL].push_back((struct word){"thursday", {{2,11},{3,11},{4,11},{5,11},{6,11},{7,11},{8,11},{9,11},{10,11}}});
wordlist[NL].push_back((struct word){"friday", {{12,11},{13,11},{14,11},{15,11},{16,11},{17,11},{18,11}}});
wordlist[NL].push_back((struct word){"saturday", {{0,10},{1,10},{2,10},{3,10},{4,10},{5,10},{6,10},{7,10}}});
wordlist[NL].push_back((struct word){"sunday", {{7,12},{8,12},{9,12},{10,12},{11,12},{12,12}}});
}
+106
View File
@@ -0,0 +1,106 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file gpio.cpp
/// \brief Description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
#include <gpio.h>
#include "driver/gpio.h"
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Type definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// File-scope variables
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function definitions
// --------------------------------------------------------------------------------------------------------------------
GPIO::GPIO(int number, GPIO_Direction_t direction)
{
this->number = number;
this->direction = direction;
//zero-initialize the config structure.
gpio_config_t io_conf = {};
//disable interrupt
io_conf.intr_type = GPIO_INTR_DISABLE;
//set as output mode
io_conf.mode = (this->direction == GPIO_DIRECTION_OUTPUT) ? GPIO_MODE_OUTPUT : GPIO_MODE_INPUT;
//bit mask of the pins that you want to set
io_conf.pin_bit_mask = (1ULL << this->number);
//disable pull-down mode
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
//disable pull-up mode
io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
//configure GPIO with the given settings
ESP_ERROR_CHECK(gpio_config(&io_conf));
}
bool GPIO::SetOutput(GPIO_Value_t value)
{
bool returnValue = false;
if (this->direction == GPIO_DIRECTION_OUTPUT)
{
ESP_ERROR_CHECK(gpio_set_level((gpio_num_t)this->number, (uint32_t)value));
this->value = value;
returnValue = true;
}
else
{
returnValue = false;
}
return returnValue;
}
GPIO_Value_t GPIO::GetInput(void)
{
if (gpio_get_level((gpio_num_t)this->number))
{
this->value = GPIO_VALUE_HIGH;
}
else
{
this->value = GPIO_VALUE_LOW;
}
return this->value;
}
+122
View File
@@ -0,0 +1,122 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file i2c.cpp
/// \brief Description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
#include "i2c.h"
#include "driver/i2c.h"
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
#define I2C_MASTER_FREQ_HZ 400000 /*!< I2C master clock frequency */
#define I2C_MASTER_TX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
#define I2C_MASTER_RX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
#define I2C_MASTER_TIMEOUT_MS 1000
// --------------------------------------------------------------------------------------------------------------------
// Type definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// File-scope variables
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function definitions
// --------------------------------------------------------------------------------------------------------------------
// Reset the class variable
unsigned int I2C::number = 0;
I2C::I2C(unsigned int SCL, unsigned int SDA)
{
I2C::thisNumber = number++;
I2C::SCL = SCL;
I2C::SDA = SDA;
I2C::frequency = I2C_MASTER_FREQ_HZ;
I2C::timeout_ms = I2C_MASTER_TIMEOUT_MS;
//
i2c_port_t i2c_master_port = (i2c_port_t)I2C::thisNumber;
i2c_config_t conf = {
.mode = I2C_MODE_MASTER,
.sda_io_num = (int)I2C::SDA,
.scl_io_num = (int)I2C::SCL,
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_pullup_en = GPIO_PULLUP_ENABLE,
.master = {I2C::frequency},
.clk_flags = 0
};
ESP_ERROR_CHECK(i2c_param_config(i2c_master_port, &conf));
ESP_ERROR_CHECK(i2c_driver_install(i2c_master_port, conf.mode, I2C_MASTER_RX_BUF_DISABLE, I2C_MASTER_TX_BUF_DISABLE, 0));
}
bool I2C::write_register(uint8_t slaveAddress, uint8_t registerAddress, uint8_t* const data, uint8_t length)
{
bool returnValue = true;
write(slaveAddress, registerAddress, data, length);
return returnValue;
}
bool I2C::read_register(uint8_t slaveAddress, uint8_t registerAddress, uint8_t* data, uint8_t length)
{
bool returnValue = true;
read(slaveAddress, registerAddress, data, length);
return returnValue;
}
void I2C::write(uint8_t slaveAddress, uint8_t registerAddress, uint8_t* const data, uint8_t length)
{
uint8_t buffer[length + 1];
buffer[0] = registerAddress;
for (int i = 0; i < length; i++)
{
buffer[i+1] = data[i];
}
ESP_ERROR_CHECK(i2c_master_write_to_device((i2c_port_t)thisNumber, slaveAddress, buffer, sizeof(buffer), timeout_ms / portTICK_PERIOD_MS));
}
void I2C::read(uint8_t slaveAddress, uint8_t registerAddress, uint8_t* data, uint8_t length)
{
ESP_ERROR_CHECK(i2c_master_write_read_device((i2c_port_t)thisNumber, slaveAddress, &registerAddress, 1, data, length, timeout_ms / portTICK_PERIOD_MS));
}
+124
View File
@@ -0,0 +1,124 @@
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "esp_check.h"
#include "led_strip_encoder.h"
static const char *TAG = "led_encoder";
typedef struct {
rmt_encoder_t base;
rmt_encoder_t *bytes_encoder;
rmt_encoder_t *copy_encoder;
int state;
rmt_symbol_word_t reset_code;
} rmt_led_strip_encoder_t;
static size_t rmt_encode_led_strip(rmt_encoder_t *encoder, rmt_channel_handle_t channel, const void *primary_data, size_t data_size, rmt_encode_state_t *ret_state)
{
rmt_led_strip_encoder_t *led_encoder = __containerof(encoder, rmt_led_strip_encoder_t, base);
rmt_encoder_handle_t bytes_encoder = led_encoder->bytes_encoder;
rmt_encoder_handle_t copy_encoder = led_encoder->copy_encoder;
rmt_encode_state_t session_state = 0;
rmt_encode_state_t state = 0;
size_t encoded_symbols = 0;
switch (led_encoder->state) {
case 0: // send RGB data
encoded_symbols += bytes_encoder->encode(bytes_encoder, channel, primary_data, data_size, &session_state);
if (session_state & RMT_ENCODING_COMPLETE) {
led_encoder->state = 1; // switch to next state when current encoding session finished
}
if (session_state & RMT_ENCODING_MEM_FULL) {
state |= RMT_ENCODING_MEM_FULL;
goto out; // yield if there's no free space for encoding artifacts
}
// fall-through
case 1: // send reset code
encoded_symbols += copy_encoder->encode(copy_encoder, channel, &led_encoder->reset_code,
sizeof(led_encoder->reset_code), &session_state);
if (session_state & RMT_ENCODING_COMPLETE) {
led_encoder->state = 0; // back to the initial encoding session
state |= RMT_ENCODING_COMPLETE;
}
if (session_state & RMT_ENCODING_MEM_FULL) {
state |= RMT_ENCODING_MEM_FULL;
goto out; // yield if there's no free space for encoding artifacts
}
}
out:
*ret_state = state;
return encoded_symbols;
}
static esp_err_t rmt_del_led_strip_encoder(rmt_encoder_t *encoder)
{
rmt_led_strip_encoder_t *led_encoder = __containerof(encoder, rmt_led_strip_encoder_t, base);
rmt_del_encoder(led_encoder->bytes_encoder);
rmt_del_encoder(led_encoder->copy_encoder);
free(led_encoder);
return ESP_OK;
}
static esp_err_t rmt_led_strip_encoder_reset(rmt_encoder_t *encoder)
{
rmt_led_strip_encoder_t *led_encoder = __containerof(encoder, rmt_led_strip_encoder_t, base);
rmt_encoder_reset(led_encoder->bytes_encoder);
rmt_encoder_reset(led_encoder->copy_encoder);
led_encoder->state = 0;
return ESP_OK;
}
esp_err_t rmt_new_led_strip_encoder(const led_strip_encoder_config_t *config, rmt_encoder_handle_t *ret_encoder)
{
esp_err_t ret = ESP_OK;
rmt_led_strip_encoder_t *led_encoder = NULL;
ESP_GOTO_ON_FALSE(config && ret_encoder, ESP_ERR_INVALID_ARG, err, TAG, "invalid argument");
led_encoder = calloc(1, sizeof(rmt_led_strip_encoder_t));
ESP_GOTO_ON_FALSE(led_encoder, ESP_ERR_NO_MEM, err, TAG, "no mem for led strip encoder");
led_encoder->base.encode = rmt_encode_led_strip;
led_encoder->base.del = rmt_del_led_strip_encoder;
led_encoder->base.reset = rmt_led_strip_encoder_reset;
// different led strip might have its own timing requirements, following parameter is for WS2812
rmt_bytes_encoder_config_t bytes_encoder_config = {
.bit0 = {
.level0 = 1,
.duration0 = 0.3 * config->resolution / 1000000, // T0H=0.3us
.level1 = 0,
.duration1 = 0.9 * config->resolution / 1000000, // T0L=0.9us
},
.bit1 = {
.level0 = 1,
.duration0 = 0.9 * config->resolution / 1000000, // T1H=0.9us
.level1 = 0,
.duration1 = 0.3 * config->resolution / 1000000, // T1L=0.3us
},
.flags.msb_first = 1 // WS2812 transfer bit order: G7...G0R7...R0B7...B0
};
ESP_GOTO_ON_ERROR(rmt_new_bytes_encoder(&bytes_encoder_config, &led_encoder->bytes_encoder), err, TAG, "create bytes encoder failed");
rmt_copy_encoder_config_t copy_encoder_config = {};
ESP_GOTO_ON_ERROR(rmt_new_copy_encoder(&copy_encoder_config, &led_encoder->copy_encoder), err, TAG, "create copy encoder failed");
uint32_t reset_ticks = config->resolution / 1000000 * 50 / 2; // reset code duration defaults to 50us
led_encoder->reset_code = (rmt_symbol_word_t) {
.level0 = 0,
.duration0 = reset_ticks,
.level1 = 0,
.duration1 = reset_ticks,
};
*ret_encoder = &led_encoder->base;
return ESP_OK;
err:
if (led_encoder) {
if (led_encoder->bytes_encoder) {
rmt_del_encoder(led_encoder->bytes_encoder);
}
if (led_encoder->copy_encoder) {
rmt_del_encoder(led_encoder->copy_encoder);
}
free(led_encoder);
}
return ret;
}
+259
View File
@@ -0,0 +1,259 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file ledmatrix.cpp
/// \brief Description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
#include "ledmatrix.h"
#include "logger.h"
#include "string.h"
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Type definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// File-scope variables
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function definitions
// --------------------------------------------------------------------------------------------------------------------
SemaphoreHandle_t LEDMatrix::taskSemaphore = 0;
TaskHandle_t LEDMatrix::matrixTaskHandle = NULL;
bool LEDMatrix::initialized = false;
LEDMatrix::LEDMatrix(LEDMatrix_Parameters_t* parameters)
{
// Take the parameters
LEDMatrix::parameters = *parameters;
// Calculate the total number of pixels
LEDMatrix::numberOfPixels = parameters->width * parameters->height;
// Create the matrix storage
matrix = new LEDMatrix_Pixel_t[parameters->width * parameters->height];
// Create the second matrix, that is actually transmitted to the periphery
// Create the task Semaphore
vSemaphoreCreateBinary(LEDMatrix::taskSemaphore);
// Take the semaphore immediately so the task cannot run
xSemaphoreTake(LEDMatrix::taskSemaphore, 0);
// Create the matrix task
xTaskCreate(matrixTask, (const char*)"matrixTask", 4096, this, 3, &LEDMatrix::matrixTaskHandle);
// Clear the matrix initially
LEDMatrix::clear();
initialized = true;
}
bool LEDMatrix::setPixelValue(unsigned int colum, unsigned int row, bool value)
{
bool returnValue = true;
// unsigned int rowC = 0;
// unsigned int colC = 0;
unsigned int pixelAddress = 0;
if ((row < parameters.height) && (colum < parameters.width))
{
returnValue = true;
}
else
{
returnValue = false;
}
if (returnValue)
{
// // Determine the actual row coordinate based on the matrix orientation
// if (parameters.columOrientation == LEDMATRIX_ORIENTATION_COLUM_UP_DOWN)
// {
// rowC = row;
// }
// else if (parameters.columOrientation == LEDMATRIX_ORIENTATION_COLUM_DOWN_UP)
// {
// rowC = (parameters.height - 1) - row;
// }
//
// // Determine the actual row coordinate based on the matrix orientation
// if (parameters.rowOrientation == LEDMATRIX_ORIENTATION_ROW_LEFT_RIGHT)
// {
// colC = colum;
// }
// else if (parameters.rowOrientation == LEDMATRIX_ORIENTATION_ROW_RIGHT_LEFT)
// {
// colC = (parameters.width - 1) - colum;
// }
//
// // Calculate the pixel address in the pixel array based on the previous information
// if (parameters.matrixOrientation == LEDMATRIX_ORIENTATION_COLUM)
// {
// pixelAddress = rowC + (colC * parameters.height);
// }
// else if (parameters.matrixOrientation == LEDMATRIX_ORIENTATION_ROW)
// {
// pixelAddress = (rowC * parameters.width) + colC;
// }
pixelAddress = LEDMatrix::findPixelIndexFromCoordinates(colum, row);
// Update the pixel value
matrix[pixelAddress].on = value;
}
return returnValue;
}
void LEDMatrix::setGlobalColour(uint8_t red, uint8_t green, uint8_t blue)
{
for (int i = 0; i < numberOfPixels; i++)
{
matrix[i].red = red;
matrix[i].green = green;
matrix[i].blue = blue;
}
}
void LEDMatrix::setPixelColour(unsigned int colum, unsigned int row, uint8_t red, uint8_t green, uint8_t blue)
{
unsigned int index;
index = LEDMatrix::findPixelIndexFromCoordinates(colum, row);
matrix[index].red = red;
matrix[index].green = green;
matrix[index].blue = blue;
}
void LEDMatrix::clear(void)
{
for (int i = 0; i < numberOfPixels; i++)
{
matrix[i].on = false;
}
}
unsigned int LEDMatrix::findPixelIndexFromCoordinates(unsigned int colum, unsigned int row)
{
bool returnValue = true;
unsigned int index = 0;
unsigned int rowC = 0;
unsigned int colC = 0;
if ((row < parameters.height) && (colum < parameters.width))
{
returnValue = true;
}
else
{
returnValue = false;
}
if (returnValue)
{
// Determine the actual row coordinate based on the matrix orientation
if (parameters.columOrientation == LEDMATRIX_ORIENTATION_COLUM_UP_DOWN)
{
rowC = row;
}
else if (parameters.columOrientation == LEDMATRIX_ORIENTATION_COLUM_DOWN_UP)
{
rowC = (parameters.height - 1) - row;
}
// Determine the actual row coordinate based on the matrix orientation
if (parameters.rowOrientation == LEDMATRIX_ORIENTATION_ROW_LEFT_RIGHT)
{
colC = colum;
}
else if (parameters.rowOrientation == LEDMATRIX_ORIENTATION_ROW_RIGHT_LEFT)
{
colC = (parameters.width - 1) - colum;
}
// Calculate the pixel address in the pixel array based on the previous information
if (parameters.matrixOrientation == LEDMATRIX_ORIENTATION_COLUM)
{
index = rowC + (colC * parameters.height);
}
else if (parameters.matrixOrientation == LEDMATRIX_ORIENTATION_ROW)
{
index = (rowC * parameters.width) + colC;
}
}
return index;
}
void LEDMatrix::matrixTask(void* parameters)
{
LEDMatrix* ledmatrix = (LEDMatrix*)parameters;
uint8_t matrix[ledmatrix->numberOfPixels * 3];
memset(&matrix, 0, sizeof(matrix));
while(1)
{
xSemaphoreTake(ledmatrix->taskSemaphore, portMAX_DELAY);
for (int i = 0; i < ledmatrix->numberOfPixels; i++)
{
if (ledmatrix->matrix[i].on)
{
matrix[i * 3 + LEDMATRIX_RED_INDEX] = ledmatrix->matrix[i].red;
matrix[i * 3 + LEDMATRIX_GREEN_INDEX] = ledmatrix->matrix[i].green;
matrix[i * 3 + LEDMATRIX_BLUE_INDEX] = ledmatrix->matrix[i].blue;
}
else
{
matrix[i * 3 + 0] = 0;
matrix[i * 3 + 1] = 0;
matrix[i * 3 + 2] = 0;
}
}
rmt_transmit(*ledmatrix->parameters.rmtChannel, *ledmatrix->parameters.rmtEncoder, matrix, sizeof(matrix), ledmatrix->parameters.rmtConfig);
}
}
+254
View File
@@ -0,0 +1,254 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file logger.cpp
/// \brief Description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
#include <string.h>
#include <stdarg.h>
#include "logger.h"
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
#define ENABLE_SERIAL_LOGGING
//#undef ENABLE_SERIAL_LOGGING
// --------------------------------------------------------------------------------------------------------------------
// Type definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// File-scope variables
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function definitions
// --------------------------------------------------------------------------------------------------------------------
TaskHandle_t Logger::logTaskHandle = NULL;
uart_port_t Logger::uartPort = 0;
QueueHandle_t Logger::logQueue = NULL;
int Logger::queuesize = 0;
Logger::Logger(int queuesize, uart_port_t uartPort)
{
Logger::uartPort = uartPort;
Logger::queuesize = queuesize;
logQueue = xQueueCreate(queuesize, sizeof(struct LogQueueItem));
xTaskCreate(loggerTask, (const char*)"loggerTask", 3072, NULL, 3, &logTaskHandle);
}
void Logger::Logger_log(const char* fileName, const char* functionName, int lineNumber, LogType logType, const char* format, ...)
{
#if defined(ENABLE_SERIAL_LOGGING)
static int nrLostMessages = 0;
static bool overflowRecovery = false;
int nrOfMessages;
struct LogQueueItem logQueueItem;
va_list ap;
nrOfMessages = uxQueueMessagesWaiting(Logger::logQueue);
if((nrOfMessages == queuesize - 1) && !overflowRecovery)
{
// Queue almost full, only one entry left. Log a warning instead
composeLogQueueItem(&logQueueItem, __FILE__, __func__, __LINE__, LOGTYPE_WARNING, "Log queue overflow");
(void)xQueueSend(logQueue, &logQueueItem, 0);
overflowRecovery = true;
nrLostMessages = 1;
}
else if((nrOfMessages == 0) && overflowRecovery)
{
// Queue empty again after an overflow
char str[128];
snprintf(str, sizeof(str) / sizeof(str[0]), "%d messages lost", nrLostMessages);
composeLogQueueItem(&logQueueItem, __FILE__, __func__, __LINE__, LOGTYPE_WARNING, str);
(void)xQueueSend(logQueue, &logQueueItem, 0);
overflowRecovery = false;
}
else if(!overflowRecovery)
{
// Normal behaviour, queue not full
char str[128];
va_start(ap, format);
vsnprintf(str, sizeof(str) / sizeof(str[0]), format, ap);
va_end(ap);
composeLogQueueItem(&logQueueItem, fileName, functionName, lineNumber, logType, str);
(void)xQueueSend(logQueue, &logQueueItem, 0);
}
else
{
// Count number of lost messages
++nrLostMessages;
}
#endif
}
void Logger_logISR(struct Logger* self, const char* fileName, const char* functionName, int lineNumber, LogType logType, const char* context)
{
#if defined(ENABLE_LOGGING)
if (self->initialized)
{
struct LogQueueItem logQueueItem;
portBASE_TYPE higherPriorityTaskWoken = pdFALSE;
composeLogQueueItem(&logQueueItem, fileName, functionName, lineNumber, logType, context);
if(xQueueSendFromISR(self->logQueue, &logQueueItem, &higherPriorityTaskWoken) != pdTRUE)
{
// Queue failed
}
portEND_SWITCHING_ISR(higherPriorityTaskWoken);
}
#endif
}
#if defined(ENABLE_SERIAL_LOGGING)
void Logger::composeLogQueueItem(struct LogQueueItem* logQueueItem, const char* fileName, const char* functionName,
int lineNumber, LogType logType, const char* context)
{
const size_t fileNameSize = sizeof(logQueueItem->fileName) / sizeof(logQueueItem->fileName[0]);
const size_t functionNameSize = sizeof(logQueueItem->functionName) / sizeof(logQueueItem->functionName[0]);
const size_t contextSize = sizeof(logQueueItem->context) / sizeof(logQueueItem->context[0]);
logQueueItem->logType = logType;
strncpy(&(logQueueItem->context[0]), context, contextSize);
logQueueItem->context[contextSize - 1] = '\0';
if(logType != LOGTYPE_PRINT)
{
int fileNameIndex = 0;
// If filename starts with "src/", strip this part
if((fileName[0] == 's') &&
(fileName[1] == 'r') &&
(fileName[2] == 'c') &&
(fileName[3] == '/'))
{
fileNameIndex = 4;
}
// It is known that the strncpy use can potentially truncate the source string, meaning
// that the target string size is smaller then the original string
// This is not a problem in this particular case, so the compiler warning is disabled
// for this situation
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstringop-truncation"
// All logtypes except LOGTYPE_PRINT need filename, functionname and linenumber.
strncpy(&(logQueueItem->fileName[0]), &fileName[fileNameIndex], fileNameSize);
strncpy(&(logQueueItem->functionName[0]), functionName, functionNameSize);
#pragma GCC diagnostic pop
logQueueItem->lineNumber = lineNumber;
// Fix terminating null byte in strncpy in case string to be copied is too long
logQueueItem->fileName[fileNameSize - 1] = '\0';
logQueueItem->functionName[functionNameSize - 1] = '\0';
}
}
#endif
void Logger::loggerTask(void* parameters)
{
while(true)
{
struct LogQueueItem logQueueItem;
xQueueReceive(logQueue, &logQueueItem, portMAX_DELAY);
if(logQueueItem.logType == LOGTYPE_PRINT)
{
// Raw print
#if defined(ENABLE_SERIAL_LOGGING)
uart_write_bytes(uartPort, logQueueItem.context, strlen(logQueueItem.context));
#endif
}
else
{
#if defined(ENABLE_SERIAL_LOGGING)
char str[256];
char* vt100Prefix = "";
const char* vt100Postfix = "\033[0m";
#endif
#if defined(ENABLE_SERIAL_LOGGING)
if(logQueueItem.logType == LOGTYPE_INFO)
{
vt100Prefix = "\033[33m";
}
else if(logQueueItem.logType == LOGTYPE_WARNING)
{
vt100Prefix = "\033[35m";
}
else if(logQueueItem.logType == LOGTYPE_ERROR)
{
vt100Prefix = "\033[31m";
}
else if(logQueueItem.logType == LOGTYPE_SUCCESS)
{
vt100Prefix = "\033[32m";
}
#endif
unsigned int seconds = 0;
#if defined(ENABLE_SERIAL_LOGGING)
// Formatted print
snprintf(str, sizeof(str) / sizeof(str[0]), "%s[%s] %09d %s, %s, %d: %s%s\n\r",
vt100Prefix,
(logQueueItem.logType == LOGTYPE_DEBUG) ? "DBG" :
(logQueueItem.logType == LOGTYPE_INFO) ? "INF" :
(logQueueItem.logType == LOGTYPE_SUCCESS) ? "SCS" :
(logQueueItem.logType == LOGTYPE_WARNING) ? "WRN" : "ERR",
seconds,
logQueueItem.fileName,
logQueueItem.functionName,
logQueueItem.lineNumber,
logQueueItem.context,
vt100Postfix);
#endif
#if defined(ENABLE_SERIAL_LOGGING)
uart_write_bytes(uartPort, str, strlen(str));
#endif
}
}
vTaskDelete(NULL);
}
+123
View File
@@ -0,0 +1,123 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file temperature.cpp
/// \brief Description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
#include "temperature.h"
#include "logger.h"
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Type definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// File-scope variables
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function definitions
// --------------------------------------------------------------------------------------------------------------------
Temperature::Temperature()
{
Temperature::minTemperature = 14;
Temperature::maxTemperature = 29;
};
void Temperature::generateWordlist(int temperature, list<string>* wordlist)
{
// Clear the list
wordlist->clear();
// Add fixed preamble
wordlist->push_back("it");
wordlist->push_back("is");
// Temperature value to string
if (temperature < minTemperature)
{
wordlist->push_back("below");
wordlist->push_back(to_string(minTemperature));
}
else if (temperature > maxTemperature)
{
wordlist->push_back("above");
wordlist->push_back(to_string(maxTemperature));
}
else
{
wordlist->push_back(to_string(temperature));
}
// Add fixed postamble
wordlist->push_back("degrees");
}
void Temperature::calculateRGB(int temperature, uint8_t* red, uint8_t* green, uint8_t* blue)
{
int calcBlue = 0;
int calcRed = 0;
int factor = 100 / (maxTemperature - minTemperature);
LOGGER_INFO("Incoming Temperature is: %i (min: %i, max: %i", temperature, minTemperature, maxTemperature);
if (temperature < minTemperature)
{
calcBlue = 0xFF;
calcRed = 0x00;
}
else if (temperature > maxTemperature)
{
calcBlue = 0x00;
calcRed = 0xFF;
}
else
{
calcBlue = (((maxTemperature - temperature) * factor) * 0xFF) / 100;
calcRed = (((temperature - minTemperature) * factor) * 0xFF) / 100;
}
LOGGER_PRINT("\n\rRed %i %x (%i)", calcRed, calcRed, (temperature - minTemperature) * factor);
LOGGER_PRINT("\n\rGreen %i %x", 0, 0);
LOGGER_PRINT("\n\rBlue %i %x (%i)", calcBlue, calcBlue, (maxTemperature - temperature) * factor);
*red = calcRed & 0xFF;
*green = 0x00;
*blue = calcBlue & 0xFF;
}
+96
View File
@@ -0,0 +1,96 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file temperaturewordmap.cpp
/// \brief Description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
#include "temperaturewordmap.h"
#include "logger.h"
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Type definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// File-scope variables
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function definitions
// --------------------------------------------------------------------------------------------------------------------
TemperatureWordmap::TemperatureWordmap(LEDMatrix* matrix) : Wordmap(matrix)
{
createList_NL();
createList_EN();
}
void TemperatureWordmap::createList_NL(void)
{
// First, clear the list
wordlist[NL].clear();
// Now lets add all relevant words
wordlist[NL].push_back((struct word){"it", {{14,0},{15,0},{16,0}}});
wordlist[NL].push_back((struct word){"is", {{18,0},{19,0}}});
wordlist[NL].push_back((struct word){"above", {{11,1},{12,1},{13,1},{14,1},{15,1},{18,2},{19,2}}});
wordlist[NL].push_back((struct word){"below", {{12,2},{13,2},{14,2},{15,2},{16,2},{18,2},{19,2}}});
// Tenth
wordlist[NL].push_back((struct word){"14", {{11,4},{12,4},{13,4},{14,4},{16,7},{17,7},{18,7},{19,7}}});
wordlist[NL].push_back((struct word){"15", {{15,4},{16,4},{17,4},{18,4},{16,7},{17,7},{18,7},{19,7}}});
wordlist[NL].push_back((struct word){"16", {{11,5},{12,5},{13,5},{16,7},{17,7},{18,7},{19,7}}});
wordlist[NL].push_back((struct word){"17", {{14,5},{15,5},{16,5},{17,5},{18,5},{16,7},{17,7},{18,7},{19,7}}});
wordlist[NL].push_back((struct word){"18", {{11,6},{12,6},{13,6},{14,6},{16,7},{17,7},{18,7},{19,7}}});
wordlist[NL].push_back((struct word){"19", {{15,6},{16,6},{17,6},{18,6},{19,6},{16,7},{17,7},{18,7},{19,7}}});
// Twentieth
wordlist[NL].push_back((struct word){"20", {{11,8},{12,8},{13,8},{14,8},{15,8},{16,8},{17,8}}});
wordlist[NL].push_back((struct word){"21", {{13,3},{14,3},{15,3},{12,7},{13,7},{11,8},{12,8},{13,8},{14,8},{15,8},{16,8},{17,8}}});
wordlist[NL].push_back((struct word){"22", {{11,3},{12,3},{13,3},{14,3},{12,7},{13,7},{11,8},{12,8},{13,8},{14,8},{15,8},{16,8},{17,8}}});
wordlist[NL].push_back((struct word){"23", {{16,3},{17,3},{18,3},{19,3},{12,7},{13,7},{11,8},{12,8},{13,8},{14,8},{15,8},{16,8},{17,8}}});
wordlist[NL].push_back((struct word){"24", {{11,4},{12,4},{13,4},{14,4},{12,7},{13,7},{11,8},{12,8},{13,8},{14,8},{15,8},{16,8},{17,8}}});
wordlist[NL].push_back((struct word){"25", {{15,4},{16,4},{17,4},{18,4},{12,7},{13,7},{11,8},{12,8},{13,8},{14,8},{15,8},{16,8},{17,8}}});
wordlist[NL].push_back((struct word){"26", {{11,5},{12,5},{13,5},{12,7},{13,7},{11,8},{12,8},{13,8},{14,8},{15,8},{16,8},{17,8}}});
wordlist[NL].push_back((struct word){"27", {{14,5},{15,5},{16,5},{17,5},{18,5},{12,7},{13,7},{11,8},{12,8},{13,8},{14,8},{15,8},{16,8},{17,8}}});
wordlist[NL].push_back((struct word){"28", {{11,6},{12,6},{13,6},{14,6},{12,7},{13,7},{11,8},{12,8},{13,8},{14,8},{15,8},{16,8},{17,8}}});
wordlist[NL].push_back((struct word){"29", {{15,6},{16,6},{17,6},{18,6},{19,6},{12,7},{13,7},{11,8},{12,8},{13,8},{14,8},{15,8},{16,8},{17,8}}});
wordlist[NL].push_back((struct word){"degrees", {{14,9},{15,9},{16,9},{17,9},{18,9},{19,9}}});
}
+162
View File
@@ -0,0 +1,162 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file wifi.cpp
/// \brief Description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
#include "string.h"
#include "esp_log.h"
#include "esp_wifi.h"
#include "wifi.h"
#include "logger.h"
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
#define EXAMPLE_ESP_MAXIMUM_RETRY 5
/* The event group allows multiple bits for each event, but we only care about two events:
* - we are connected to the AP with an IP
* - we failed to connect after the maximum amount of retries */
#define WIFI_CONNECTED_BIT BIT0
#define WIFI_FAIL_BIT BIT1
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA_WPA2_PSK
// --------------------------------------------------------------------------------------------------------------------
// Type definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// File-scope variables
// --------------------------------------------------------------------------------------------------------------------
static const char* ssid = "Kowalski";
static const char* pass = "madagascar";
//static const char* ssid = "vbchaos";
//static const char* pass = "mijninternet";
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function definitions
// --------------------------------------------------------------------------------------------------------------------
int Wifi::s_retry_num = 0;
const char* Wifi::TAG = "wifi station";
EventGroupHandle_t Wifi::s_wifi_event_group = xEventGroupCreate();
Wifi::Wifi()
{
}
void Wifi::event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
{
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START)
{
esp_wifi_connect();
}
else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED)
{
if (Wifi::s_retry_num < EXAMPLE_ESP_MAXIMUM_RETRY)
{
esp_wifi_connect();
s_retry_num++;
LOGGER_INFO("%s - retry to connect to the AP", TAG);
}
else
{
xEventGroupSetBits(s_wifi_event_group, WIFI_FAIL_BIT);
}
LOGGER_ERROR("%S - connect to the AP fail", TAG);
}
else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP)
{
ip_event_got_ip_t *event = (ip_event_got_ip_t*) event_data;
LOGGER_SUCCESS("%s - got ip: %d:%d:%d:%d", TAG, IP2STR(&event->ip_info.ip));
s_retry_num = 0;
xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT);
}
}
void Wifi::start_client(void)
{
ESP_ERROR_CHECK(esp_netif_init());
ESP_ERROR_CHECK(esp_event_loop_create_default());
esp_netif_create_default_wifi_sta();
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
esp_event_handler_instance_t instance_any_id;
esp_event_handler_instance_t instance_got_ip;
ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL, &instance_any_id));
ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL, &instance_got_ip));
wifi_config_t wifi_config;
memset(&wifi_config, 0, sizeof(wifi_config));
strncpy((char*)wifi_config.sta.ssid, ssid, sizeof(wifi_config.sta.ssid));
strncpy((char*)wifi_config.sta.password, pass, sizeof(wifi_config.sta.password));
wifi_config.sta.threshold.authmode = ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD;
wifi_config.sta.sae_pwe_h2e = WPA3_SAE_PWE_BOTH;
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config));
ESP_ERROR_CHECK(esp_wifi_start());
LOGGER_INFO("%s - wifi_init_sta finished", TAG);
/* Waiting until either the connection is established (WIFI_CONNECTED_BIT) or connection failed for the maximum
* number of re-tries (WIFI_FAIL_BIT). The bits are set by event_handler() (see above) */
EventBits_t bits = xEventGroupWaitBits(s_wifi_event_group,
WIFI_CONNECTED_BIT | WIFI_FAIL_BIT,
pdFALSE,
pdFALSE,
portMAX_DELAY);
/* xEventGroupWaitBits() returns the bits before the call returned, hence we can test which event actually
* happened. */
if (bits & WIFI_CONNECTED_BIT)
{
LOGGER_SUCCESS("%s - connected to ap SSID:%s password:%s", TAG, ssid, pass);
}
else if (bits & WIFI_FAIL_BIT)
{
LOGGER_ERROR("%s - Failed to connect to SSID:%s, password:%s", TAG, ssid, pass);
}
else
{
LOGGER_ERROR("%s - UNEXPECTED EVENT", TAG);
}
}
+131
View File
@@ -0,0 +1,131 @@
// --------------------------------------------------------------------------------------------------------------------
/// \file wordmap.cpp
/// \brief Description
// --------------------------------------------------------------------------------------------------------------------
//
// vbchaos software design
//
// --------------------------------------------------------------------------------------------------------------------
/// $Revision: $
/// $Author: $
/// $Date: $
// (c) 2023 vbchaos
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Include files
// --------------------------------------------------------------------------------------------------------------------
#include "wordmap.h"
#include "logger.h"
#include <algorithm>
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Type definitions
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// File-scope variables
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function declarations
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Function definitions
// --------------------------------------------------------------------------------------------------------------------
Wordmap::Wordmap(LEDMatrix* matrix)
{
Wordmap::matrix = matrix;
Wordmap::language = NL;
Wordmap::red = 0xFF;
Wordmap::green = 0xFF;
Wordmap::blue = 0xFF;
}
bool Wordmap::setWord(Language_t lang, string identifier, bool value)
{
bool returnValue;
auto _compare = [&](struct word currentword)
{
if (identifier.compare(currentword.identifier) == 0)
{
return true;
}
else
{
return false;
}
};
// Create a list Iterator
std::list<struct word>::iterator it;
// Fetch the iterator of element with value 'the'
it = find_if(wordlist[lang].begin(), wordlist[lang].end(), _compare);
// Check if iterator points to end or not
if(it != wordlist[lang].end())
{
returnValue = true;
}
else
{
returnValue = false;
}
if (returnValue)
{
std::list<LEDMatrix::coordinate>::iterator pixel;
for (pixel = it->pixels.begin(); pixel != it->pixels.end(); pixel++)
{
matrix->setPixelValue(pixel->x, pixel->y, value);
matrix->setPixelColour(pixel->x, pixel->y, Wordmap::red, Wordmap::green, Wordmap::blue);
}
}
return returnValue;
}
bool Wordmap::setColour(uint8_t red, uint8_t green, uint8_t blue)
{
bool returnValue = true;
Wordmap::red = red;
Wordmap::green = green;
Wordmap::blue = blue;
return returnValue;
}
void Wordmap::createList_NL(void)
{
// First, clear the list
wordlist[NL].clear();
}
void Wordmap::createList_EN(void)
{
// First, clear the list
wordlist[EN].clear();
}