mirror of
https://gitlab.com/fabinfra/fabhardware/fablight2.git
synced 2025-04-20 10:16:26 +02:00
118 lines
3.4 KiB
C
118 lines
3.4 KiB
C
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/task.h"
|
|
#include "freertos/queue.h"
|
|
#include <string.h>
|
|
|
|
#include "esp_log.h"
|
|
#include "esp_netif.h"
|
|
#include "nvs_flash.h"
|
|
#include "esp_mac.h"
|
|
|
|
#include "LEDController_Task.h"
|
|
#include "MQTTClient_Task.h"
|
|
|
|
static const char *TAG_MAIN = "MAIN";
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
// WARNING
|
|
// NEED FIXS:
|
|
// https://github.com/espressif/esp-idf/pull/12675
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
|
|
void app_main(void)
|
|
{
|
|
ESP_LOGI(TAG_MAIN, "Init");
|
|
|
|
// INIT for WLAN
|
|
ESP_ERROR_CHECK(nvs_flash_init());
|
|
ESP_ERROR_CHECK(esp_netif_init());
|
|
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
|
|
|
int Segment_GPIOs[3] = {10, 12, 14};
|
|
QueueHandle_t ledcontroller_queue = xQueueCreate(9+1, sizeof(LEDController_Command));
|
|
LEDController_Config ledcontroller_config =
|
|
{
|
|
.Ring_Count = 10,
|
|
.LED_Count = 2,
|
|
.Segment_Count = sizeof(Segment_GPIOs) / sizeof(int),
|
|
.Segment_Pins = Segment_GPIOs,
|
|
.Effect_Queue = &ledcontroller_queue
|
|
};
|
|
xTaskCreate(&LEDController_Task, "LEDController_Task", 4096, (void*) &ledcontroller_config, 5, NULL);
|
|
|
|
unsigned char mac_base[6] = {0};
|
|
esp_efuse_mac_get_default(mac_base);
|
|
esp_read_mac(mac_base, ESP_MAC_WIFI_STA);
|
|
char mac[] = "00:00:00:00:00:00";
|
|
sprintf(mac, "%02X:%02X:%02X:%02X:%02X:%02X", mac_base[0],mac_base[1],mac_base[2],mac_base[3],mac_base[4],mac_base[5]);
|
|
|
|
MQTTClient_Config mqttclient_config =
|
|
{
|
|
.SSID = CONFIG_FABLIGHT_WIFI_SSID,
|
|
.PSK = CONFIG_FABLIGHT_WIFI_PASSWORD,
|
|
.Host = CONFIG_FABLIGHT_MQTT_HOST,
|
|
.Username = CONFIG_FABLIGHT_MQTT_USER,
|
|
.Password = CONFIG_FABLIGHT_MQTT_PASSWORD,
|
|
.ID = mac,
|
|
.Effect_Queue = &ledcontroller_queue
|
|
};
|
|
xTaskCreate(&MQTTClient_Task, "MQTTClient_Task", 4096, (void*) &mqttclient_config, 5, NULL);
|
|
|
|
ESP_LOGI(TAG_MAIN, "Run");
|
|
|
|
LEDController_Command command1 =
|
|
{
|
|
.Effect = (enum LEDController_Effect)STATIC,
|
|
.Segment = -1,
|
|
.Ring = -1,
|
|
.Red = 255,
|
|
.Green = 200,
|
|
.Blue = 0
|
|
};
|
|
|
|
LEDController_Command command2 =
|
|
{
|
|
.Effect = (enum LEDController_Effect)STATIC,
|
|
.Segment = -1,
|
|
.Ring = -1,
|
|
.Red = 0,
|
|
.Green = 0,
|
|
.Blue = 0
|
|
};
|
|
|
|
int active = 0;
|
|
while(42)
|
|
{
|
|
// for(int i=0; i < ledcontroller_config.Segment_Count; i++)
|
|
// {
|
|
// if(i == active)
|
|
// {
|
|
// command1.Segment = i;
|
|
// xQueueSend(ledcontroller_queue, (void*) &command1, (TickType_t)0);
|
|
// }
|
|
// else
|
|
// {
|
|
// command2.Segment = i;
|
|
// xQueueSend(ledcontroller_queue, (void*) &command2, (TickType_t)0);
|
|
// }
|
|
// }
|
|
|
|
// vTaskDelay(256 / portTICK_PERIOD_MS);
|
|
// active++;
|
|
|
|
// if(active >= ledcontroller_config.Segment_Count)
|
|
// {
|
|
// active = 0;
|
|
// }
|
|
|
|
|
|
vTaskDelay(10000 / portTICK_PERIOD_MS);
|
|
ESP_LOGD(TAG_MAIN, "Update");
|
|
// //xQueueSend(ledcontroller_queue, (void*) &command1, (TickType_t)0);
|
|
|
|
// vTaskDelay(1000 / portTICK_PERIOD_MS);
|
|
// ESP_LOGD(TAG_MAIN, "Update");
|
|
// //xQueueSend(ledcontroller_queue, (void*) &command2, (TickType_t)0);
|
|
}
|
|
} |