cleanup
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
# This file was automatically generated for projects
|
||||
# without default 'CMakeLists.txt' file.
|
||||
add_compile_options(" -Wno-unused-variable -Wno-unused-function -Wno-error")
|
||||
|
||||
FILE(GLOB_RECURSE app_sources ${CMAKE_SOURCE_DIR}/src/*.*)
|
||||
|
||||
|
||||
80
src/MyBLEServer.cpp
Normal file
80
src/MyBLEServer.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
#include "MyBLEServer.hpp"
|
||||
#include "config.hpp"
|
||||
|
||||
#include "tlc.hpp"
|
||||
#include <EEPROM.h>
|
||||
#include <string>
|
||||
|
||||
MyServerCallbacks::MyServerCallbacks(bool * connectionState) {
|
||||
_BLEClientConnected = connectionState;
|
||||
}
|
||||
|
||||
void MyServerCallbacks::onConnect(BLEServer * pServer) {
|
||||
// Serial.println("Callback connected");
|
||||
|
||||
deviceConnected = true;
|
||||
*_BLEClientConnected = true;
|
||||
}
|
||||
|
||||
void MyServerCallbacks::onDisconnect(BLEServer * pServer) {
|
||||
*_BLEClientConnected = false;
|
||||
deviceConnected = false;
|
||||
}
|
||||
|
||||
bool MyServerCallbacks::getConnectionState() {
|
||||
return *_BLEClientConnected;
|
||||
}
|
||||
|
||||
MyAlarmCallback::MyAlarmCallback(enum Alarm * alarm, enum Dimmer * dimmer) {
|
||||
this->alarmFired = alarm;
|
||||
this->dimmerState = dimmer;
|
||||
}
|
||||
void MyAlarmCallback::onWrite(BLECharacteristic * pCharacteristic) {
|
||||
String value = pCharacteristic->getValue().c_str();
|
||||
|
||||
if (value.compareTo("X") == 0) {
|
||||
// Serial.println("found X");
|
||||
// Serial.println(deviceConnected);
|
||||
*this->alarmFired = ALARM_1KM;
|
||||
}
|
||||
else if (value.compareTo("XX") == 0) {
|
||||
// Serial.println("found XX");
|
||||
// alarmFired_500m = 1;
|
||||
*alarmFired = ALARM_500M;
|
||||
}
|
||||
else if (value.compareTo("XXX") == 0) {
|
||||
// Serial.println("found XXX");
|
||||
// alarmFired_300m = 1;
|
||||
*alarmFired = ALARM_300M;
|
||||
}
|
||||
else if (value.compareTo("XXXX") == 0) {
|
||||
// Serial.println("found XXXX");
|
||||
// alarmFired_100m = 1;
|
||||
*alarmFired = ALARM_100M;
|
||||
}
|
||||
else if (value.compareTo("brighter") == 0) {
|
||||
// Serial.println("found brighter");
|
||||
// alarmFired_100m = 1;
|
||||
// alarmFired = ALARM_100M;
|
||||
// state = 0;
|
||||
// brightnessFired = BRIGHTER;
|
||||
*dimmerState = BRIGHTNESS_UP;
|
||||
}
|
||||
else if (value.compareTo("darker") == 0) {
|
||||
// Serial.println("found darker");
|
||||
// alarmFired_100m = 1;
|
||||
// alarmFired = ALARM_100M;
|
||||
// state = 0;
|
||||
// brightnessFired = DARKER;
|
||||
*dimmerState = BRIGHTNESS_DOWN;
|
||||
}
|
||||
else if (value.compareTo("U") == 0) {
|
||||
// reboot in WifiMode
|
||||
// Serial.println("Found U");
|
||||
EEPROM.write(MODE_ADDRESS, MODE_WIFI);
|
||||
EEPROM.commit();
|
||||
|
||||
// reboot
|
||||
ESP.restart();
|
||||
}
|
||||
}
|
||||
29
src/MyBLEServer.hpp
Normal file
29
src/MyBLEServer.hpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef MYBLESERVER_H
|
||||
#define MYBLESERVER_H
|
||||
#include "BLEServer.h"
|
||||
#include "datatypes.hpp"
|
||||
#include "tlc.hpp"
|
||||
|
||||
class MyServerCallbacks : public BLEServerCallbacks {
|
||||
public:
|
||||
MyServerCallbacks(bool *);
|
||||
bool getConnectionState();
|
||||
void onConnect(BLEServer * pServer);
|
||||
void onDisconnect(BLEServer * pServer);
|
||||
|
||||
private:
|
||||
bool * _BLEClientConnected;
|
||||
bool deviceConnected = false;
|
||||
};
|
||||
|
||||
class MyAlarmCallback : public BLECharacteristicCallbacks {
|
||||
public:
|
||||
MyAlarmCallback(enum Alarm *, enum Dimmer *);
|
||||
|
||||
private:
|
||||
void onWrite(BLECharacteristic * pCharacteristic);
|
||||
enum Alarm * alarmFired;
|
||||
enum Dimmer * dimmerState;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -15,5 +15,4 @@
|
||||
|
||||
#define NUM_LEDS 7 // do not touch
|
||||
|
||||
|
||||
#endif
|
||||
233
src/main.cpp
233
src/main.cpp
@@ -1,17 +1,17 @@
|
||||
#include <Arduino.h>
|
||||
#include <string>
|
||||
#include "HWCDC.h"
|
||||
#include "esp32-hal-gpio.h"
|
||||
#include "esp32-hal.h"
|
||||
#include "freertos/portmacro.h"
|
||||
#include "hal/gpio_types.h"
|
||||
#include "secrets.hpp"
|
||||
#include <Arduino.h>
|
||||
#include <EEPROM.h>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "freertos/task.h"
|
||||
|
||||
#include <BLE2902.h>
|
||||
#include <BLEDevice.h>
|
||||
@@ -23,20 +23,19 @@
|
||||
#include <WiFi.h>
|
||||
#include <WiFiUdp.h>
|
||||
|
||||
#include <driver/rmt.h>
|
||||
#include "tlc.hpp"
|
||||
#include "MyBLEServer.hpp"
|
||||
#include "config.hpp"
|
||||
#include "datatypes.hpp"
|
||||
#include "tlc.hpp"
|
||||
#include <driver/rmt.h>
|
||||
|
||||
// both lines are useless, when using rmt mode
|
||||
int pTime = 3; // in useconds
|
||||
int tCycle = pTime * 6; // time for one bit. Per datasheet tCycle is between 0.33 useconds and 10 useconds
|
||||
int tCycle =
|
||||
pTime * 6; // time for one bit. Per datasheet tCycle is between 0.33 useconds and 10 useconds
|
||||
|
||||
// #define TESTMODE 1
|
||||
|
||||
const char * ssid = SECRET_SSID;
|
||||
const char * password = SECRET_PASS;
|
||||
|
||||
bool _BLEClientConnected = false;
|
||||
|
||||
#define AlarmService BLEUUID((uint16_t)0x1811) // ialert notification 0x1802
|
||||
@@ -46,9 +45,6 @@ BLEDescriptor AlarmLevelDescriptor(BLEUUID((uint16_t)0x2901));
|
||||
// BLEServer * pServer = NULL;
|
||||
// bool volatile deviceConnected = false;
|
||||
bool volatile oldDeviceConnected = false;
|
||||
// uint32_t value = 0;
|
||||
|
||||
enum NET_MODE mode;
|
||||
|
||||
void displayWarning(void * params);
|
||||
void dimmer(void * params);
|
||||
@@ -56,126 +52,32 @@ void dimmer(void * params);
|
||||
enum Alarm alarmFired = NO_ALARM;
|
||||
enum Dimmer dimmerState = NO_DIMMER;
|
||||
|
||||
// class MyServerCallbacks : public BLEServerCallbacks {
|
||||
// bool deviceConnected = false;
|
||||
|
||||
// void onConnect(BLEServer * pServer) {
|
||||
// Serial.println("Callback connected");
|
||||
|
||||
class MyServerCallbacks : public BLEServerCallbacks {
|
||||
bool deviceConnected = false;
|
||||
// deviceConnected = true;
|
||||
// _BLEClientConnected = true;
|
||||
// };
|
||||
|
||||
void onConnect(BLEServer * pServer) {
|
||||
Serial.println("Callback connected");
|
||||
// void onDisconnect(BLEServer * pServer) {
|
||||
// _BLEClientConnected = false;
|
||||
// deviceConnected = false;
|
||||
// }
|
||||
|
||||
// public:
|
||||
// bool getConnectionState() { return deviceConnected; }
|
||||
// };
|
||||
|
||||
deviceConnected = true;
|
||||
_BLEClientConnected = true;
|
||||
};
|
||||
|
||||
void onDisconnect(BLEServer * pServer) {
|
||||
_BLEClientConnected = false;
|
||||
deviceConnected = false;
|
||||
}
|
||||
public:
|
||||
bool getConnectionState(){
|
||||
return deviceConnected;
|
||||
}
|
||||
};
|
||||
|
||||
bool brighter = false;
|
||||
bool darker = false;
|
||||
|
||||
enum Alarm saveFiredAlarm;
|
||||
uint8_t saveAlarmState;
|
||||
|
||||
int state = 0;
|
||||
|
||||
byte brightnessState = 0;
|
||||
|
||||
Cockpit cockpit(ALARM_PIN, NUM_LEDS, pTime, tCycle, brightnessState);
|
||||
|
||||
TaskHandle_t thDisplayWarning;
|
||||
|
||||
struct taskParams pvParams = {
|
||||
.cockpit = &cockpit,
|
||||
.alarmFired = &alarmFired,
|
||||
.dimmerState = &dimmerState,
|
||||
.thDisplayWarning = &thDisplayWarning
|
||||
};
|
||||
|
||||
// var to count to with state for different distances
|
||||
int stateLimit = 50;
|
||||
|
||||
// save state of buttons
|
||||
bool brightnessUpPressed = false;
|
||||
bool brightnessDownPressed = false;
|
||||
|
||||
enum Brightness brightnessFired = NO_CHANGE;
|
||||
|
||||
|
||||
|
||||
class MyAlarmCallback : public BLECharacteristicCallbacks {
|
||||
void onWrite(BLECharacteristic * pCharacteristic) {
|
||||
String value = pCharacteristic->getValue().c_str();
|
||||
|
||||
if (value.compareTo("X") == 0) {
|
||||
Serial.println("found X");
|
||||
// Serial.println(deviceConnected);
|
||||
alarmFired = ALARM_1KM;
|
||||
state = 0;
|
||||
}
|
||||
else if (value.compareTo("XX") == 0) {
|
||||
Serial.println("found XX");
|
||||
// alarmFired_500m = 1;
|
||||
alarmFired = ALARM_500M;
|
||||
state = 0;
|
||||
}
|
||||
else if (value.compareTo("XXX") == 0) {
|
||||
Serial.println("found XXX");
|
||||
// alarmFired_300m = 1;
|
||||
alarmFired = ALARM_300M;
|
||||
state = 0;
|
||||
}
|
||||
else if (value.compareTo("XXXX") == 0) {
|
||||
Serial.println("found XXXX");
|
||||
// alarmFired_100m = 1;
|
||||
alarmFired = ALARM_100M;
|
||||
state = 0;
|
||||
}
|
||||
else if (value.compareTo("brighter") == 0) {
|
||||
Serial.println("found brighter");
|
||||
// alarmFired_100m = 1;
|
||||
// alarmFired = ALARM_100M;
|
||||
// state = 0;
|
||||
// brightnessFired = BRIGHTER;
|
||||
dimmerState = BRIGHTNESS_UP;
|
||||
|
||||
}
|
||||
else if (value.compareTo("darker") == 0) {
|
||||
Serial.println("found darker");
|
||||
// alarmFired_100m = 1;
|
||||
// alarmFired = ALARM_100M;
|
||||
// state = 0;
|
||||
// brightnessFired = DARKER;
|
||||
dimmerState = BRIGHTNESS_DOWN;
|
||||
|
||||
}
|
||||
else if (value.compareTo("U") == 0) {
|
||||
// reboot in WifiMode
|
||||
Serial.println("Found U");
|
||||
EEPROM.write(MODE_ADDRESS, MODE_WIFI);
|
||||
EEPROM.commit();
|
||||
|
||||
// reboot
|
||||
ESP.restart();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void InitBLE(BLEServer *pServer, MyServerCallbacks * serverCallback, MyAlarmCallback * myAlarmCallback) {
|
||||
void InitBLE(BLEServer * pServer, MyServerCallbacks * serverCallback,
|
||||
MyAlarmCallback * myAlarmCallback) {
|
||||
BLEDevice::init("OilCheck");
|
||||
pServer = BLEDevice::createServer();
|
||||
|
||||
Serial.println("Start BLE");
|
||||
|
||||
|
||||
pServer->setCallbacks(serverCallback);
|
||||
|
||||
// Create BLE Service
|
||||
@@ -196,26 +98,22 @@ void InitBLE(BLEServer *pServer, MyServerCallbacks * serverCallback, MyAlarmCa
|
||||
pAdvertising->addServiceUUID(AlarmService);
|
||||
pAdvertising->setScanResponse(true);
|
||||
BLEDevice::startAdvertising();
|
||||
|
||||
}
|
||||
|
||||
volatile int ctr = 0;
|
||||
hw_timer_t * timer = NULL;
|
||||
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;
|
||||
|
||||
void IRAM_ATTR onTimer() {
|
||||
portENTER_CRITICAL_ISR(&timerMux);
|
||||
ctr++;
|
||||
portEXIT_CRITICAL_ISR(&timerMux);
|
||||
}
|
||||
|
||||
// volatile int pc = 0;
|
||||
|
||||
// Create the BLE Server
|
||||
BLEServer * pServer = NULL;
|
||||
MyServerCallbacks *serverCallback = new MyServerCallbacks();
|
||||
MyAlarmCallback * myAlarmCallback = new MyAlarmCallback();
|
||||
MyServerCallbacks * serverCallback = new MyServerCallbacks(&_BLEClientConnected);
|
||||
MyAlarmCallback * myAlarmCallback = new MyAlarmCallback(&alarmFired, &dimmerState);
|
||||
|
||||
enum NET_MODE mode;
|
||||
byte brightnessState = 0;
|
||||
Cockpit cockpit(ALARM_PIN, NUM_LEDS, pTime, tCycle, brightnessState);
|
||||
|
||||
TaskHandle_t thDisplayWarning;
|
||||
struct taskParams pvParams = {.cockpit = &cockpit,
|
||||
.alarmFired = &alarmFired,
|
||||
.dimmerState = &dimmerState,
|
||||
.thDisplayWarning = &thDisplayWarning};
|
||||
void setup() {
|
||||
|
||||
// //setup GPIO
|
||||
@@ -239,18 +137,9 @@ void setup() {
|
||||
#endif
|
||||
|
||||
mode = static_cast<enum NET_MODE>(EEPROM.read(MODE_ADDRESS));
|
||||
// mode = MODE_WIFI;
|
||||
|
||||
if (mode == MODE_BLE) {
|
||||
|
||||
// upcounting timer 1MHz
|
||||
timer = timerBegin(1, 80, true);
|
||||
timerAttachInterrupt(timer, &onTimer, true);
|
||||
timerAlarmWrite(timer, 100000, true);
|
||||
timerAlarmEnable(timer);
|
||||
|
||||
|
||||
|
||||
rmt_config_t config = RMT_DEFAULT_CONFIG_TX(ALARM_PIN, RMT_CHANNEL_0);
|
||||
config.clk_div = 160; // 80
|
||||
config.tx_config.carrier_en = false;
|
||||
@@ -260,20 +149,19 @@ void setup() {
|
||||
|
||||
InitBLE(pServer, serverCallback, myAlarmCallback);
|
||||
|
||||
xTaskCreate(displayWarning, "Warning", 1000, &pvParams, tskIDLE_PRIORITY, &thDisplayWarning);
|
||||
xTaskCreate(displayWarning, "Warning", 1000, &pvParams, tskIDLE_PRIORITY,
|
||||
&thDisplayWarning);
|
||||
xTaskCreate(dimmer, "Dimmer", 10000, &pvParams, tskIDLE_PRIORITY, NULL);
|
||||
|
||||
}
|
||||
else if (mode == MODE_WIFI) {
|
||||
// boot next time into ble mode
|
||||
|
||||
EEPROM.write(MODE_ADDRESS, MODE_BLE);
|
||||
EEPROM.commit();
|
||||
|
||||
// delay(3000);
|
||||
|
||||
Serial.println("Booting in Wifimode");
|
||||
WiFi.mode(WIFI_STA);
|
||||
const char * ssid = SECRET_SSID;
|
||||
const char * password = SECRET_PASS;
|
||||
WiFi.begin(ssid, password);
|
||||
while (WiFi.waitForConnectResult() != WL_CONNECTED) {
|
||||
Serial.println("Connection Failed! ");
|
||||
@@ -319,13 +207,6 @@ void setup() {
|
||||
Serial.println("Ready");
|
||||
Serial.print("IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
// // WiFi.mode(WIFI_STA);
|
||||
// WiFi.begin(ssid, password);
|
||||
// while (WiFi.waitForConnectResult() != WL_CONNECTED) {
|
||||
// delay(3000);
|
||||
// break;
|
||||
// }
|
||||
// ArduinoOTA.begin();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -340,13 +221,11 @@ void loop() {
|
||||
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||
|
||||
if (serverCallback->getConnectionState()) {
|
||||
|
||||
}
|
||||
// disconnecting
|
||||
if (!serverCallback->getConnectionState() && oldDeviceConnected) {
|
||||
delay(500); // give the bluetooth stack the chance to get thingsready
|
||||
pServer->startAdvertising(); // restart advertising
|
||||
Serial.println("start advertising");
|
||||
pServer->startAdvertising(); // restart advertising Serial.println("startadvertising ");
|
||||
oldDeviceConnected = serverCallback->getConnectionState();
|
||||
}
|
||||
// connecting
|
||||
@@ -354,39 +233,33 @@ void loop() {
|
||||
// do stuff here on connecting
|
||||
oldDeviceConnected = serverCallback->getConnectionState();
|
||||
|
||||
Color c[] = {
|
||||
Cockpit::YELLOW,
|
||||
Cockpit::RED,
|
||||
Cockpit::PURPLE,
|
||||
Cockpit::BLUE,
|
||||
Cockpit::CYAN,
|
||||
Cockpit::GREEN,
|
||||
Cockpit::YELLOW,
|
||||
Cockpit::RED,
|
||||
Cockpit::PURPLE,
|
||||
Cockpit::BLUE,
|
||||
Cockpit::CYAN,
|
||||
Cockpit::GREEN
|
||||
};
|
||||
Color c[] = {Cockpit::YELLOW, Cockpit::RED, Cockpit::PURPLE, Cockpit::BLUE,
|
||||
Cockpit::CYAN, Cockpit::GREEN, Cockpit::YELLOW, Cockpit::RED,
|
||||
Cockpit::PURPLE, Cockpit::BLUE, Cockpit::CYAN, Cockpit::GREEN};
|
||||
// for(int i = 0; i < 36; i++){
|
||||
// // cockpit.knightRiderAdvanced(red, i);
|
||||
// // cockpit.outToIn(red, i);
|
||||
// cockpit.outToInMulticolor(c, 6, i);
|
||||
// // cockpit.knightRiderColored(i, red);
|
||||
// ESP_ERROR_CHECK(rmt_write_items(RMT_CHANNEL_0, cockpit.led_data, sizeof(cockpit.led_data) / sizeof(rmt_item32_t), true));
|
||||
// delay(100);
|
||||
// ESP_ERROR_CHECK(rmt_write_items(RMT_CHANNEL_0, cockpit.led_data,
|
||||
// sizeof(cockpit.led_data) / sizeof(rmt_item32_t), true)); delay(100);
|
||||
// }
|
||||
for(int i = 0; i < 50; i++){
|
||||
for (int i = 0; i < 49; i++) {
|
||||
// cockpit.knightRiderAdvanced(red, i);
|
||||
// cockpit.outToIn(red, i);
|
||||
cockpit.inToOutMulticolor(c, 12, i);
|
||||
// cockpit.speedUpBounce(c[0], i);
|
||||
// cockpit.knightRiderColored(i, red);
|
||||
ESP_ERROR_CHECK(rmt_write_items(RMT_CHANNEL_0, cockpit.led_data, sizeof(cockpit.led_data) / sizeof(rmt_item32_t), true));
|
||||
ESP_ERROR_CHECK(rmt_write_items(RMT_CHANNEL_0, cockpit.led_data,
|
||||
sizeof(cockpit.led_data) / sizeof(rmt_item32_t),
|
||||
true));
|
||||
// uint8_t myDelay = uint8_t(7 / 250.0 * i - 14 / 5.0 * i + 100);
|
||||
delay(100);
|
||||
}
|
||||
delay(10);
|
||||
cockpit.turnOffLeds();
|
||||
ESP_ERROR_CHECK(rmt_write_items(RMT_CHANNEL_0, cockpit.led_data, sizeof(cockpit.led_data) / sizeof(rmt_item32_t), true));
|
||||
ESP_ERROR_CHECK(rmt_write_items(RMT_CHANNEL_0, cockpit.led_data,
|
||||
sizeof(cockpit.led_data) / sizeof(rmt_item32_t), true));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
#include "tasks.hpp"
|
||||
#include "Arduino.h"
|
||||
#include "config.hpp"
|
||||
#include "tasks.hpp"
|
||||
#include "tlc.hpp"
|
||||
#include "datatypes.hpp"
|
||||
#include "tlc.hpp"
|
||||
|
||||
void displayWarning(void * params) {
|
||||
struct taskParams * myParams = (struct taskParams *)params;
|
||||
@@ -31,10 +31,10 @@ void displayWarning( void * params){
|
||||
if (alarmStateChanged) {
|
||||
alarmStatebefore = ALARM_100M;
|
||||
statePreload = 30;
|
||||
|
||||
}
|
||||
cp->flashing(Cockpit::WHITE, statePreload);
|
||||
ESP_ERROR_CHECK(rmt_write_items(RMT_CHANNEL_0, cp->led_data, sizeof(cp->led_data) / sizeof(rmt_item32_t), true));
|
||||
ESP_ERROR_CHECK(rmt_write_items(RMT_CHANNEL_0, cp->led_data,
|
||||
sizeof(cp->led_data) / sizeof(rmt_item32_t), true));
|
||||
statePreload--;
|
||||
if (statePreload == 0) {
|
||||
*alarm = NO_ALARM;
|
||||
@@ -48,7 +48,8 @@ void displayWarning( void * params){
|
||||
statePreload = 20;
|
||||
}
|
||||
cp->flashing(Cockpit::ORANGE, statePreload);
|
||||
ESP_ERROR_CHECK(rmt_write_items(RMT_CHANNEL_0, cp->led_data, sizeof(cp->led_data) / sizeof(rmt_item32_t), true));
|
||||
ESP_ERROR_CHECK(rmt_write_items(RMT_CHANNEL_0, cp->led_data,
|
||||
sizeof(cp->led_data) / sizeof(rmt_item32_t), true));
|
||||
statePreload--;
|
||||
if (statePreload == 0) {
|
||||
*alarm = NO_ALARM;
|
||||
@@ -63,7 +64,8 @@ void displayWarning( void * params){
|
||||
statePreload = 20;
|
||||
}
|
||||
cp->flashing(Cockpit::GREEN, statePreload);
|
||||
ESP_ERROR_CHECK(rmt_write_items(RMT_CHANNEL_0, cp->led_data, sizeof(cp->led_data) / sizeof(rmt_item32_t), true));
|
||||
ESP_ERROR_CHECK(rmt_write_items(RMT_CHANNEL_0, cp->led_data,
|
||||
sizeof(cp->led_data) / sizeof(rmt_item32_t), true));
|
||||
statePreload--;
|
||||
if (statePreload == 0) {
|
||||
*alarm = NO_ALARM;
|
||||
@@ -82,19 +84,20 @@ void displayWarning( void * params){
|
||||
// cp->colorfade(statePreload);
|
||||
cp->flashing(Cockpit::BLUE, statePreload);
|
||||
|
||||
ESP_ERROR_CHECK(rmt_write_items(RMT_CHANNEL_0, cp->led_data, sizeof(cp->led_data) / sizeof(rmt_item32_t), true));
|
||||
ESP_ERROR_CHECK(rmt_write_items(RMT_CHANNEL_0, cp->led_data,
|
||||
sizeof(cp->led_data) / sizeof(rmt_item32_t), true));
|
||||
statePreload--;
|
||||
if (statePreload == 0) {
|
||||
*alarm = NO_ALARM;
|
||||
alarmStatebefore = NO_ALARM;
|
||||
cp->turnOffLeds();
|
||||
ESP_ERROR_CHECK(rmt_write_items(RMT_CHANNEL_0, cp->led_data, sizeof(cp->led_data) / sizeof(rmt_item32_t), true));
|
||||
ESP_ERROR_CHECK(rmt_write_items(RMT_CHANNEL_0, cp->led_data,
|
||||
sizeof(cp->led_data) / sizeof(rmt_item32_t), true));
|
||||
}
|
||||
vTaskDelay(500 / portTICK_PERIOD_MS);
|
||||
break;
|
||||
default:
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
|
||||
}
|
||||
// Serial.println(uxTaskGetStackHighWaterMark(NULL));
|
||||
}
|
||||
@@ -113,7 +116,8 @@ void dimmer(void * params){
|
||||
|
||||
while (1) {
|
||||
|
||||
if((gpio_get_level(BRIGHTER_PIN) == 0 && brighterPressed == 0) || *dimmerState == BRIGHTNESS_UP){
|
||||
if ((gpio_get_level(BRIGHTER_PIN) == 0 && brighterPressed == 0) ||
|
||||
*dimmerState == BRIGHTNESS_UP) {
|
||||
// brighter
|
||||
brighterPressed = 1;
|
||||
ctrBrightnessChanged = 10;
|
||||
@@ -121,18 +125,19 @@ void dimmer(void * params){
|
||||
|
||||
if (eTaskGetState(*thDisplayWarning) != eTaskState::eDeleted) {
|
||||
vTaskSuspend(*thDisplayWarning);
|
||||
|
||||
}
|
||||
cp->brightnessUp();
|
||||
cp->displayBrightness();
|
||||
ESP_ERROR_CHECK(rmt_write_items(RMT_CHANNEL_0, cp->led_data, sizeof(cp->led_data) / sizeof(rmt_item32_t), true));
|
||||
ESP_ERROR_CHECK(rmt_write_items(RMT_CHANNEL_0, cp->led_data,
|
||||
sizeof(cp->led_data) / sizeof(rmt_item32_t), true));
|
||||
}
|
||||
if (gpio_get_level(BRIGHTER_PIN) == 1 && brighterPressed == 1) {
|
||||
// brighter button released
|
||||
brighterPressed = 0;
|
||||
}
|
||||
|
||||
if((gpio_get_level(DARKER_PIN) == 0 && darkerPressed == 0) || *dimmerState == BRIGHTNESS_DOWN){
|
||||
if ((gpio_get_level(DARKER_PIN) == 0 && darkerPressed == 0) ||
|
||||
*dimmerState == BRIGHTNESS_DOWN) {
|
||||
// darker
|
||||
darkerPressed = 1;
|
||||
ctrBrightnessChanged = 10;
|
||||
@@ -140,11 +145,11 @@ void dimmer(void * params){
|
||||
|
||||
if (eTaskGetState(*thDisplayWarning) != eTaskState::eDeleted) {
|
||||
vTaskSuspend(*thDisplayWarning);
|
||||
|
||||
}
|
||||
cp->brightnessDown();
|
||||
cp->displayBrightness();
|
||||
ESP_ERROR_CHECK(rmt_write_items(RMT_CHANNEL_0, cp->led_data, sizeof(cp->led_data) / sizeof(rmt_item32_t), true));
|
||||
ESP_ERROR_CHECK(rmt_write_items(RMT_CHANNEL_0, cp->led_data,
|
||||
sizeof(cp->led_data) / sizeof(rmt_item32_t), true));
|
||||
}
|
||||
if (gpio_get_level(DARKER_PIN) == 1 && darkerPressed == 1) {
|
||||
// darker button released
|
||||
@@ -160,12 +165,16 @@ void dimmer(void * params){
|
||||
// check if there are suspended tasks
|
||||
if (eTaskGetState(*thDisplayWarning) == eTaskState::eSuspended) {
|
||||
cp->turnOffLeds();
|
||||
ESP_ERROR_CHECK(rmt_write_items(RMT_CHANNEL_0, cp->led_data, sizeof(cp->led_data) / sizeof(rmt_item32_t), true));
|
||||
ESP_ERROR_CHECK(rmt_write_items(RMT_CHANNEL_0, cp->led_data,
|
||||
sizeof(cp->led_data) / sizeof(rmt_item32_t),
|
||||
true));
|
||||
vTaskResume(*thDisplayWarning);
|
||||
}
|
||||
else {
|
||||
cp->turnOffLeds();
|
||||
ESP_ERROR_CHECK(rmt_write_items(RMT_CHANNEL_0, cp->led_data, sizeof(cp->led_data) / sizeof(rmt_item32_t), true));
|
||||
ESP_ERROR_CHECK(rmt_write_items(RMT_CHANNEL_0, cp->led_data,
|
||||
sizeof(cp->led_data) / sizeof(rmt_item32_t),
|
||||
true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
48
src/tlc.cpp
48
src/tlc.cpp
@@ -10,7 +10,6 @@ Color Cockpit::BLACK = {.blue=0, .red=0, .green=0};
|
||||
Color Cockpit::YELLOW = {.blue = 0, .red = 0xFF, .green = 0xC0};
|
||||
Color Cockpit::PURPLE = {.blue = 0xBF, .red = 0xBF, .green = 0x40};
|
||||
|
||||
|
||||
Cockpit::Cockpit(gpio_num_t pin, int leds, int pTime, int tCycle, uint8_t brightnessState) {
|
||||
this->pin = pin;
|
||||
this->leds = leds;
|
||||
@@ -20,15 +19,17 @@ Cockpit::Cockpit(gpio_num_t pin, int leds, int pTime, int tCycle, uint8_t bright
|
||||
this->brightnessState = brightnessState;
|
||||
|
||||
this->cp = 0;
|
||||
|
||||
}
|
||||
|
||||
Color Cockpit::scaleBrightness(Color color, uint8_t dimmfactor) {
|
||||
// dimmfactor is an addition option to dimm led
|
||||
Color scaledColor = color;
|
||||
scaledColor.blue = uint8_t(this->brightness[brightnessState] / 255.0 * color.blue * dimmfactor /100.0);
|
||||
scaledColor.red = uint8_t(this->brightness[brightnessState] / 255.0 * color.red * dimmfactor /100.0);
|
||||
scaledColor.green = uint8_t(this->brightness[brightnessState] / 255.0 * color.green * dimmfactor /100.0);
|
||||
scaledColor.blue =
|
||||
uint8_t(this->brightness[brightnessState] / 255.0 * color.blue * dimmfactor / 100.0);
|
||||
scaledColor.red =
|
||||
uint8_t(this->brightness[brightnessState] / 255.0 * color.red * dimmfactor / 100.0);
|
||||
scaledColor.green =
|
||||
uint8_t(this->brightness[brightnessState] / 255.0 * color.green * dimmfactor / 100.0);
|
||||
return scaledColor;
|
||||
}
|
||||
|
||||
@@ -47,6 +48,28 @@ void Cockpit::fillFromLeft(Color color, int state){
|
||||
this->writeLEDs();
|
||||
}
|
||||
|
||||
void Cockpit::speedUpBounce(Color color, int state) {
|
||||
// lights bounces from left to right with increasing speed
|
||||
|
||||
turnOffLeds();
|
||||
|
||||
uint8_t position = state % 12;
|
||||
if (position < NUM_LEDS) {
|
||||
this->stateLEDs[position] = scaleBrightness(color);
|
||||
}
|
||||
else {
|
||||
// 7 -> 5
|
||||
// 8 -> 4
|
||||
// 9 -> 3
|
||||
// 10-> 2
|
||||
// 11-> 1
|
||||
position = -1 * position + 12;
|
||||
this->stateLEDs[position] = scaleBrightness(color);
|
||||
}
|
||||
|
||||
writeLEDs();
|
||||
}
|
||||
|
||||
void Cockpit::outToIn(Color color, int state) {
|
||||
state = state % 5;
|
||||
turnOffLeds();
|
||||
@@ -72,7 +95,8 @@ void Cockpit::outToInMulticolor(Color color[], uint8_t colors, int state){
|
||||
this->stateLEDs[i] = BLACK;
|
||||
}
|
||||
else {
|
||||
if(curColorIndex < colors && i-1 < NUM_LEDS && NUM_LEDS-i < NUM_LEDS){ // just for safety
|
||||
if (curColorIndex < colors && i - 1 < NUM_LEDS &&
|
||||
NUM_LEDS - i < NUM_LEDS) { // just for safety
|
||||
this->stateLEDs[i - 1] = scaleBrightness(color[curColorIndex]);
|
||||
this->stateLEDs[NUM_LEDS - i] = scaleBrightness(color[curColorIndex]);
|
||||
}
|
||||
@@ -88,7 +112,6 @@ void Cockpit::outToInMulticolor(Color color[], uint8_t colors, int state){
|
||||
this->stateLEDs[i] = scaleBrightness(color[curColorIndex]);
|
||||
this->stateLEDs[NUM_LEDS - i - 1] = scaleBrightness(color[curColorIndex]);
|
||||
}
|
||||
|
||||
}
|
||||
writeLEDs();
|
||||
}
|
||||
@@ -117,7 +140,6 @@ void Cockpit::inToOutMulticolor(Color color[], uint8_t colors, int state) {
|
||||
// right part of leds
|
||||
this->stateLEDs[3 + i] = scaleBrightness(color[curColorIndex]);
|
||||
}
|
||||
|
||||
}
|
||||
writeLEDs();
|
||||
}
|
||||
@@ -286,7 +308,6 @@ uint8_t scaleColor(uint8_t color, int scaleFactor){
|
||||
return uint8_t(color * (float)scaleFactor / 255);
|
||||
}
|
||||
|
||||
|
||||
void Cockpit::turnOffLeds() {
|
||||
for (uint8_t led = 0; led < NUM_LEDS; led++) {
|
||||
this->stateLEDs[led] = BLACK;
|
||||
@@ -350,7 +371,6 @@ void Cockpit::displayBrightness(Color color){
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
void Cockpit::alternating(Color color, int state, int frequencyDivider) {
|
||||
if (state % (frequencyDivider * 2) < frequencyDivider) {
|
||||
state = 0;
|
||||
@@ -366,7 +386,6 @@ void Cockpit::alternating(Color color, int state, int frequencyDivider){
|
||||
else {
|
||||
this->stateLEDs[led] = BLACK;
|
||||
}
|
||||
|
||||
}
|
||||
this->writeLEDs();
|
||||
}
|
||||
@@ -378,7 +397,6 @@ void Cockpit::alternating(Color color, int state, int frequencyDivider){
|
||||
else {
|
||||
this->stateLEDs[led] = BLACK;
|
||||
}
|
||||
|
||||
}
|
||||
this->writeLEDs();
|
||||
}
|
||||
@@ -414,8 +432,6 @@ void Cockpit::writeLEDs(){
|
||||
this->waitGSLAT();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Cockpit::writeLED(uint8_t led) {
|
||||
this->writeCommTimer();
|
||||
for (int i = 0; i < this->leds; i++) {
|
||||
@@ -463,7 +479,6 @@ void Cockpit::writeZero() {
|
||||
this->cp++;
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
|
||||
#if defined(MODE_INTERRUPT)
|
||||
@@ -507,7 +522,6 @@ void Cockpit::writeZero() {
|
||||
delayMicroseconds(pTime);
|
||||
delayMicroseconds(pTime);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void Cockpit::writeOne() {
|
||||
@@ -551,7 +565,6 @@ void Cockpit::writeOne() {
|
||||
this->led_data[this->cp].duration1 = 1;
|
||||
this->cp++;
|
||||
|
||||
|
||||
#else
|
||||
|
||||
#if defined(MODE_INTERRUPT)
|
||||
@@ -604,7 +617,6 @@ void Cockpit::writeOne() {
|
||||
delayMicroseconds(pTime);
|
||||
delayMicroseconds(pTime);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void Cockpit::writeCommTimer() {
|
||||
|
||||
36
src/tlc.hpp
36
src/tlc.hpp
@@ -5,8 +5,9 @@
|
||||
#include "Arduino.h"
|
||||
#include <stdint.h>
|
||||
#define INVERSE_MODE
|
||||
#include <inttypes.h>
|
||||
#include "driver/rmt.h"
|
||||
#include <inttypes.h>
|
||||
|
||||
#define BUFFER_SIZE 1818
|
||||
// #include "config.h"
|
||||
|
||||
@@ -17,36 +18,18 @@
|
||||
|
||||
class Cockpit;
|
||||
|
||||
enum Colors {
|
||||
BLUE,
|
||||
RED,
|
||||
GREEN
|
||||
};
|
||||
enum Colors { BLUE, RED, GREEN };
|
||||
typedef struct Color {
|
||||
uint8_t blue;
|
||||
uint8_t red;
|
||||
uint8_t green;
|
||||
} Color;
|
||||
|
||||
enum Alarm {
|
||||
ALARM_1KM,
|
||||
ALARM_500M,
|
||||
ALARM_300M,
|
||||
ALARM_100M,
|
||||
NO_ALARM
|
||||
};
|
||||
enum Alarm { ALARM_1KM, ALARM_500M, ALARM_300M, ALARM_100M, NO_ALARM };
|
||||
|
||||
enum Dimmer {
|
||||
BRIGHTNESS_UP,
|
||||
BRIGHTNESS_DOWN,
|
||||
NO_DIMMER
|
||||
};
|
||||
enum Dimmer { BRIGHTNESS_UP, BRIGHTNESS_DOWN, NO_DIMMER };
|
||||
|
||||
enum Brightness{
|
||||
BRIGHTER,
|
||||
DARKER,
|
||||
NO_CHANGE
|
||||
};
|
||||
enum Brightness { BRIGHTER, DARKER, NO_CHANGE };
|
||||
|
||||
class Cockpit {
|
||||
private:
|
||||
@@ -59,8 +42,10 @@ class Cockpit{
|
||||
uint8_t leds; // amout of leds
|
||||
// int pin; // pin connected to uC
|
||||
gpio_num_t pin;
|
||||
// uint8_t stateLEDs[LEDS][COLOR_CHANNELS] = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}};
|
||||
Color stateLEDs[NUM_LEDS] = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}};
|
||||
// uint8_t stateLEDs[LEDS][COLOR_CHANNELS] = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0,
|
||||
// 0}, {0, 0, 0}, {0, 0, 0}};
|
||||
Color stateLEDs[NUM_LEDS] = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0},
|
||||
{0, 0, 0}, {0, 0, 0}, {0, 0, 0}};
|
||||
Color scaleBrightness(Color color, uint8_t additionDimm = 100);
|
||||
void setColorLed(Color color, uint8_t led);
|
||||
|
||||
@@ -89,6 +74,7 @@ class Cockpit{
|
||||
void colorfade(int state);
|
||||
void fillFromLeft(Color color, int state);
|
||||
// void fillFromRight(Color color, int state);
|
||||
void speedUpBounce(Color color, int state);
|
||||
|
||||
void flashing(Color color, int state);
|
||||
void alternating(Color color, int state, int frequencyDivider);
|
||||
|
||||
Reference in New Issue
Block a user