📟 pmme-device: backporting - GPIO button
This commit is contained in:
parent
f850e86b2f
commit
49c123809a
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include "driver/i2c_master.h"
|
#include "driver/i2c_master.h"
|
||||||
#include "driver/uart.h"
|
#include "driver/uart.h"
|
||||||
|
#include "driver/gpio.h"
|
||||||
#include "ssd1306/ssd1306.h"
|
#include "ssd1306/ssd1306.h"
|
||||||
|
|
||||||
static const char *TAG = "PMME-Device";
|
static const char *TAG = "PMME-Device";
|
||||||
@ -29,6 +30,8 @@ static const char *TAG = "PMME-Device";
|
|||||||
#define UART_BUF_SIZE 128
|
#define UART_BUF_SIZE 128
|
||||||
#define TXD_PIN 17
|
#define TXD_PIN 17
|
||||||
#define RXD_PIN 16
|
#define RXD_PIN 16
|
||||||
|
#define BUTTON_PIN GPIO_NUM_5
|
||||||
|
#define LED_PIN GPIO_NUM_19
|
||||||
|
|
||||||
#define SWAP_BYTES(x) ((x >> 8) | (x << 8))
|
#define SWAP_BYTES(x) ((x >> 8) | (x << 8))
|
||||||
|
|
||||||
@ -202,6 +205,10 @@ void oled_display_task_manual(void *pvParameters) {
|
|||||||
void oled_display_task(void *pvParameters) {
|
void oled_display_task(void *pvParameters) {
|
||||||
init_ssd1306();
|
init_ssd1306();
|
||||||
char pm25_str[128];
|
char pm25_str[128];
|
||||||
|
|
||||||
|
ssd1306_fill_screen();
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(3000));
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
uint16_t pm25_value = 0;
|
uint16_t pm25_value = 0;
|
||||||
if (xSemaphoreTake(sensor_data_mutex, pdMS_TO_TICKS(10))) {
|
if (xSemaphoreTake(sensor_data_mutex, pdMS_TO_TICKS(10))) {
|
||||||
@ -219,6 +226,41 @@ void oled_display_task(void *pvParameters) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void button_led_task(void *pvParameters) {
|
||||||
|
gpio_config_t io_conf = {
|
||||||
|
.pin_bit_mask = (1ULL << LED_PIN),
|
||||||
|
.mode = GPIO_MODE_OUTPUT,
|
||||||
|
.pull_up_en = GPIO_PULLUP_DISABLE,
|
||||||
|
.pull_down_en = GPIO_PULLDOWN_DISABLE,
|
||||||
|
.intr_type = GPIO_INTR_DISABLE,
|
||||||
|
};
|
||||||
|
gpio_config(&io_conf);
|
||||||
|
|
||||||
|
io_conf.pin_bit_mask = (1ULL << BUTTON_PIN);
|
||||||
|
io_conf.mode = GPIO_MODE_INPUT;
|
||||||
|
io_conf.pull_up_en = GPIO_PULLUP_ENABLE;
|
||||||
|
gpio_config(&io_conf);
|
||||||
|
|
||||||
|
gpio_set_level(LED_PIN, 0);
|
||||||
|
|
||||||
|
int curr_state = 1; // HIGH
|
||||||
|
bool is_pressed = false;
|
||||||
|
while (1) {
|
||||||
|
int level = gpio_get_level(BUTTON_PIN);
|
||||||
|
is_pressed = false;
|
||||||
|
if (curr_state == 1 && level == 0) {
|
||||||
|
gpio_set_level(LED_PIN, 1);
|
||||||
|
curr_state = 0;
|
||||||
|
is_pressed = true;
|
||||||
|
} else if (curr_state == 0 && level == 1) {
|
||||||
|
gpio_set_level(LED_PIN, 0);
|
||||||
|
curr_state = 1;
|
||||||
|
is_pressed = true;
|
||||||
|
}
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(is_pressed ? 100 : 10));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void app_main(void) {
|
void app_main(void) {
|
||||||
sensor_data_mutex = xSemaphoreCreateMutex();
|
sensor_data_mutex = xSemaphoreCreateMutex();
|
||||||
if (sensor_data_mutex == NULL) {
|
if (sensor_data_mutex == NULL) {
|
||||||
@ -227,4 +269,5 @@ void app_main(void) {
|
|||||||
}
|
}
|
||||||
xTaskCreate(pm_sensor_task, "pm_sensor_task", 4096, NULL, 5, NULL);
|
xTaskCreate(pm_sensor_task, "pm_sensor_task", 4096, NULL, 5, NULL);
|
||||||
xTaskCreate(oled_display_task, "oled_display_task", 4096, NULL, 5, NULL);
|
xTaskCreate(oled_display_task, "oled_display_task", 4096, NULL, 5, NULL);
|
||||||
|
xTaskCreate(button_led_task, "button_led_task", 2048, NULL, 5, NULL);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -559,3 +559,19 @@ esp_err_t i2c_ssd1306_buffer_to_ram(i2c_ssd1306_handle_t *i2c_ssd1306)
|
|||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// My Functions
|
||||||
|
esp_err_t ssd1306_fill_screen(void) {
|
||||||
|
i2c_ssd1306_buffer_fill(&i2c_ssd1306);
|
||||||
|
return i2c_ssd1306_buffer_to_ram(&i2c_ssd1306);
|
||||||
|
}
|
||||||
|
|
||||||
|
void init_ssd1306_no_splash(void)
|
||||||
|
{
|
||||||
|
i2c_new_master_bus(&i2c_master_bus_config, &i2c_master_bus);
|
||||||
|
i2c_ssd1306_init(i2c_master_bus, i2c_ssd1306_config, &i2c_ssd1306);
|
||||||
|
// i2c_ssd1306_buffer_image(&i2c_ssd1306, 32, 0, (const uint8_t *)ssd1306_logo, 64, 64, false);
|
||||||
|
// i2c_ssd1306_buffer_to_ram(&i2c_ssd1306);
|
||||||
|
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||||
|
i2c_ssd1306_buffer_clear(&i2c_ssd1306);
|
||||||
|
}
|
||||||
|
|||||||
@ -282,3 +282,8 @@ esp_err_t i2c_ssd1306_pages_to_ram(i2c_ssd1306_handle_t *i2c_ssd1306, uint8_t in
|
|||||||
* @return ESP_OK on success, or an error code otherwise.
|
* @return ESP_OK on success, or an error code otherwise.
|
||||||
*/
|
*/
|
||||||
esp_err_t i2c_ssd1306_buffer_to_ram(i2c_ssd1306_handle_t *i2c_ssd1306);
|
esp_err_t i2c_ssd1306_buffer_to_ram(i2c_ssd1306_handle_t *i2c_ssd1306);
|
||||||
|
|
||||||
|
// My Functions;
|
||||||
|
esp_err_t ssd1306_fill_screen(void);
|
||||||
|
void init_ssd1306_no_splash(void);
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user