Compare commits
2 Commits
cc2499e0e5
...
bf4860b509
Author | SHA1 | Date |
---|---|---|
Carsten Schmiemann | bf4860b509 | |
Carsten Schmiemann | 6b9ccf9f7e |
|
@ -121,7 +121,7 @@ int ESP32SJA1000Class::begin(long baudRate)
|
|||
}
|
||||
|
||||
modifyRegister(REG_BTR1, 0x80, 0x80); // SAM = 1
|
||||
writeRegister(REG_IER, 0xff); // enable all interrupts
|
||||
writeRegister(REG_IER, 0xef); // enable all interrupts
|
||||
|
||||
// set filter to allow anything
|
||||
writeRegister(REG_ACRn(0), 0x00);
|
||||
|
|
|
@ -16,6 +16,7 @@ monitor_speed = 115200
|
|||
monitor_filters = esp32_exception_decoder
|
||||
upload_speed = 115200
|
||||
build_flags = -DCORE_DEBUG_LEVEL=5
|
||||
lib_deps = fastled/FastLED@^3.6.0
|
||||
|
||||
[env:nodemcu-32s-prod]
|
||||
platform = espressif32
|
||||
|
@ -23,4 +24,5 @@ board = nodemcu-32s
|
|||
framework = arduino
|
||||
monitor_speed = 115200
|
||||
upload_speed = 115200
|
||||
build_flags = -DCORE_DEBUG_LEVEL=3
|
||||
build_flags = -DCORE_DEBUG_LEVEL=3
|
||||
lib_deps = fastled/FastLED@^3.6.0
|
||||
|
|
86
src/main.cpp
86
src/main.cpp
|
@ -4,6 +4,9 @@
|
|||
#include <CAN.h>
|
||||
#include "esp_log.h"
|
||||
|
||||
#include <FastLED.h>
|
||||
CRGB led[1];
|
||||
|
||||
static SemaphoreHandle_t mutex;
|
||||
|
||||
// Task handles
|
||||
|
@ -63,6 +66,8 @@ unsigned long standbyStartTime = 0; // Tracks the start time of standby mode
|
|||
// Internal variables
|
||||
bool serial_init = false;
|
||||
bool can_enabled = false;
|
||||
bool led_status = false;
|
||||
int serial_ping = 0;
|
||||
|
||||
// Function to initialize CAN bus
|
||||
void initCAN()
|
||||
|
@ -285,11 +290,11 @@ void vSerialConsoleTask(void *pvParameters)
|
|||
ESP_LOGD("State machine", "Try to enable CAN Interface");
|
||||
initCAN();
|
||||
}
|
||||
if (standbyStartTime != 0) {
|
||||
if (standbyStartTime != 0)
|
||||
{
|
||||
standbyStartTime = 0; // Reset standby timer
|
||||
ESP_LOGI("State machine"," Ignition standby timer disabled");
|
||||
ESP_LOGI("State machine", " Ignition standby timer disabled");
|
||||
}
|
||||
|
||||
}
|
||||
else if (input.endsWith("off"))
|
||||
{
|
||||
|
@ -316,10 +321,10 @@ void vSerialConsoleTask(void *pvParameters)
|
|||
standbyStartTime = millis();
|
||||
ESP_LOGI("State machine", "Ignition set to standby mode, retype command to see duration left");
|
||||
if (!can_enabled)
|
||||
{
|
||||
ESP_LOGD("State machine", "Try to enable CAN Interface");
|
||||
initCAN();
|
||||
}
|
||||
{
|
||||
ESP_LOGD("State machine", "Try to enable CAN Interface");
|
||||
initCAN();
|
||||
}
|
||||
standbyState = true;
|
||||
ignitionState = true;
|
||||
}
|
||||
|
@ -396,7 +401,49 @@ void vSerialConsoleTask(void *pvParameters)
|
|||
}
|
||||
}
|
||||
}
|
||||
vTaskDelay(10);
|
||||
vTaskDelay(50);
|
||||
|
||||
if (millis() - serial_ping >= 10000)
|
||||
{
|
||||
serial_ping += 10000;
|
||||
ESP_LOGI("Serial Console", "Ping, Time %d s", millis() / 1000);
|
||||
}
|
||||
|
||||
unsigned long previousMillis = 0;
|
||||
long interval = 1000;
|
||||
|
||||
if (standbyState)
|
||||
{
|
||||
led[0] = CRGB::Yellow;
|
||||
interval = 500;
|
||||
}
|
||||
else if (ignitionState)
|
||||
{
|
||||
led[0] = CRGB::Green;
|
||||
interval = 250;
|
||||
}
|
||||
else if (!ignitionState)
|
||||
{
|
||||
led[0] = CRGB::Red;
|
||||
interval = 1000;
|
||||
}
|
||||
unsigned long currentMillis = millis();
|
||||
if (currentMillis - previousMillis >= interval)
|
||||
{
|
||||
previousMillis = currentMillis;
|
||||
if (led_status)
|
||||
{
|
||||
FastLED.setBrightness(25);
|
||||
led_status = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
FastLED.setBrightness(25);
|
||||
led_status = true;
|
||||
}
|
||||
|
||||
FastLED.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -406,20 +453,31 @@ void setup()
|
|||
Serial.setTimeout(5000);
|
||||
ESP_LOGI("SYS", "Easylink CAN Waker application starting up...");
|
||||
|
||||
//TCAN Enable CAN Interface
|
||||
pinMode(16, OUTPUT);
|
||||
digitalWrite(16, HIGH);
|
||||
|
||||
pinMode(23, OUTPUT);
|
||||
digitalWrite(23, LOW);
|
||||
|
||||
CAN.setPins(26, 27);
|
||||
|
||||
mutex = xSemaphoreCreateMutex();
|
||||
|
||||
//Print state of variables during bootup
|
||||
// Print state of variables during bootup
|
||||
ESP_LOGD("SYS", "Print actual variable states");
|
||||
printVariableSummary();
|
||||
|
||||
xTaskCreatePinnedToCore(vCANSendTask, "CANSendTask", 8096, NULL, 10, &xCANSendTaskHandle, 0);
|
||||
ESP_LOGD("SYS", "Start CANSendTask");
|
||||
xTaskCreatePinnedToCore(vSerialConsoleTask, "SerialConsoleTask", 8096, NULL, 10, &xSerialConsoleTaskHandle, 1);
|
||||
ESP_LOGD("SYS", "Start SerialConsoleTask");
|
||||
FastLED.addLeds<WS2812, 4, GRB>(led, 1);
|
||||
ESP_LOGD("SYS", "Init WS2812 LED");
|
||||
|
||||
xTaskCreatePinnedToCore(vCANSendTask, "CANSendTask", 8096, NULL, 10, &xCANSendTaskHandle, 0);
|
||||
ESP_LOGD("SYS", "Started CANSendTask");
|
||||
xTaskCreatePinnedToCore(vSerialConsoleTask, "SerialConsoleTask", 8096, NULL, 10, &xSerialConsoleTaskHandle, 1);
|
||||
ESP_LOGD("SYS", "Started SerialConsoleTask");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
//We are using tasks instead
|
||||
// We are using tasks instead
|
||||
}
|
Loading…
Reference in New Issue