Second ADC debugging in process
This commit is contained in:
@@ -16,20 +16,24 @@
|
||||
#include <ui.h>
|
||||
#include <led.h>
|
||||
|
||||
// Defines to enable channel B
|
||||
#define CH_A_ENABLE
|
||||
#define CH_B_ENABLE
|
||||
#define CH_A_RT_ENABLE
|
||||
#define CH_B_RT_ENABLE
|
||||
// #define I2C_ENABLE
|
||||
// #define WEB_ENABLE
|
||||
|
||||
// Debug Defines
|
||||
#define WIFI_SSID "AstroRotaxMonitor"
|
||||
#define WIFI_PASSWORD "maledettirotax"
|
||||
#define PSRAM_MAX 4096
|
||||
#define QUEUE_MAX 256
|
||||
#define PSRAM_MAX 1024
|
||||
#define QUEUE_MAX 32
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
delay(250);
|
||||
Serial.setTimeout(30000);
|
||||
Serial.setTimeout(5000);
|
||||
|
||||
// Setup Logger
|
||||
LOG_ATTACH_SERIAL(Serial);
|
||||
@@ -47,28 +51,30 @@ void setup()
|
||||
LOG_DEBUG("ESP32 Heap:", ESP.getHeapSize());
|
||||
LOG_DEBUG("ESP32 Sketch:", ESP.getFreeSketchSpace());
|
||||
|
||||
// Init Wifi station
|
||||
// LOG_INFO("Initializing WiFi...");
|
||||
// WiFi.mode(WIFI_AP);
|
||||
// IPAddress local_IP(10, 11, 12, 1);
|
||||
// IPAddress gateway(10, 11, 12, 1);
|
||||
// IPAddress subnet(255, 255, 255, 0);
|
||||
// WiFi.softAPConfig(local_IP, gateway, subnet);
|
||||
// WiFi.setTxPower(WIFI_POWER_5dBm); // reduce wifi power
|
||||
// if (WiFi.softAP(WIFI_SSID, WIFI_PASSWORD))
|
||||
// {
|
||||
// LOG_INFO("WiFi AP Mode Started");
|
||||
// LOG_INFO("Wifi SSID:", WIFI_SSID);
|
||||
// LOG_INFO("Wifi Password:", WIFI_PASSWORD);
|
||||
// LOG_INFO("WiFi IP:" + WiFi.softAPIP().toString());
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// LOG_ERROR("Failed to start WiFi AP Mode");
|
||||
// LOG_ERROR("5 seconds to restart...");
|
||||
// vTaskDelay(pdMS_TO_TICKS(5000));
|
||||
// esp_restart();
|
||||
// }
|
||||
// Init Wifi station
|
||||
#ifdef WEB_ENABLE
|
||||
LOG_INFO("Initializing WiFi...");
|
||||
WiFi.mode(WIFI_AP);
|
||||
IPAddress local_IP(10, 11, 12, 1);
|
||||
IPAddress gateway(10, 11, 12, 1);
|
||||
IPAddress subnet(255, 255, 255, 0);
|
||||
WiFi.softAPConfig(local_IP, gateway, subnet);
|
||||
WiFi.setTxPower(WIFI_POWER_5dBm); // reduce wifi power
|
||||
if (WiFi.softAP(WIFI_SSID, WIFI_PASSWORD))
|
||||
{
|
||||
LOG_INFO("WiFi AP Mode Started");
|
||||
LOG_INFO("Wifi SSID:", WIFI_SSID);
|
||||
LOG_INFO("Wifi Password:", WIFI_PASSWORD);
|
||||
LOG_INFO("WiFi IP:" + WiFi.softAPIP().toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR("Failed to start WiFi AP Mode");
|
||||
LOG_ERROR("5 seconds to restart...");
|
||||
vTaskDelay(pdMS_TO_TICKS(5000));
|
||||
esp_restart();
|
||||
}
|
||||
#endif
|
||||
|
||||
// Initialize Interrupt pins on PICKUP detectors
|
||||
initTriggerPinsInputs();
|
||||
@@ -84,7 +90,7 @@ void loop()
|
||||
led.setBrightness(0.025f);
|
||||
led.setStatus(RGBled::LedStatus::INIT);
|
||||
|
||||
std::shared_ptr<Devices> dev = std::make_shared<Devices>();
|
||||
Devices dev;
|
||||
bool running = true;
|
||||
std::mutex fs_mutex;
|
||||
LITTLEFSGuard fsGuard;
|
||||
@@ -94,34 +100,40 @@ void loop()
|
||||
bool spiB_ok = true;
|
||||
//////// INIT SPI INTERFACES ////////
|
||||
LOG_DEBUG("Init SPI Interfaces");
|
||||
SPIClass SPI_A(FSPI);
|
||||
#ifdef CH_A_ENABLE
|
||||
LOG_DEBUG("Begin Init SPI_A");
|
||||
SPIClass SPI_A(HSPI);
|
||||
spiA_ok = SPI_A.begin(SPI_A_SCK, SPI_A_MISO, SPI_A_MOSI);
|
||||
SPI_A.setDataMode(SPI_MODE1); // ADS1256 requires SPI mode 1
|
||||
LOG_DEBUG("Init SPI A ok");
|
||||
Serial.readStringUntil('\n');
|
||||
dev->m_spi_a.reset(&SPI_A);
|
||||
dev->m_adc_a = std::make_unique<ADS1256>(ADC_A_DRDY, ADS1256::PIN_UNUSED, ADS1256::PIN_UNUSED, ADC_A_CS, 2.5, &SPI_A);
|
||||
dev->m_adc_a->InitializeADC();
|
||||
dev->m_adc_a->setPGA(PGA_1);
|
||||
dev->m_adc_a->setDRATE(DRATE_7500SPS);
|
||||
LOG_DEBUG("Init ADC A ok");
|
||||
Serial.readStringUntil('\n');
|
||||
|
||||
delay(250);
|
||||
|
||||
#ifdef CH_B_ENABLE
|
||||
SPIClass SPI_B(HSPI);
|
||||
LOG_DEBUG("Init SPI_A -> OK");
|
||||
delay(500);
|
||||
LOG_DEBUG("Begin Init ADC_A");
|
||||
ADS1256 ADC_A(ADC_A_DRDY, ADS1256::PIN_UNUSED, ADS1256::PIN_UNUSED, ADC_A_CS, 2.5, &SPI_A);
|
||||
ADC_A.InitializeADC();
|
||||
ADC_A.setPGA(PGA_1);
|
||||
ADC_A.setDRATE(DRATE_7500SPS);
|
||||
dev.m_adc_a = &ADC_A;
|
||||
dev.m_spi_a = &SPI_A;
|
||||
LOG_DEBUG("Init ADC_A -> OK");
|
||||
delay(1000);
|
||||
#endif
|
||||
|
||||
#ifdef CH_B_ENABLE
|
||||
LOG_DEBUG("Begin Init SPI_B");
|
||||
SPIClass SPI_B(FSPI);
|
||||
spiB_ok = SPI_B.begin(SPI_B_SCK, SPI_B_MISO, SPI_B_MOSI);
|
||||
SPI_B.setDataMode(SPI_MODE1); // ADS1256 requires SPI mode 1
|
||||
LOG_DEBUG("Init SPI B ok");
|
||||
Serial.readStringUntil('\n');
|
||||
dev->m_spi_b.reset(&SPI_B);
|
||||
dev->m_adc_b = std::make_unique<ADS1256>(ADC_B_DRDY, ADS1256::PIN_UNUSED, ADS1256::PIN_UNUSED, ADC_B_CS, 2.5, &SPI_B);
|
||||
dev->m_adc_b->InitializeADC();
|
||||
dev->m_adc_b->setPGA(PGA_1);
|
||||
dev->m_adc_b->setDRATE(DRATE_7500SPS);
|
||||
LOG_DEBUG("Init ADC B ok");
|
||||
Serial.readStringUntil('\n');
|
||||
LOG_DEBUG("Init SPI_B -> OK");
|
||||
delay(500);
|
||||
LOG_DEBUG("Begin Init ADC_B");
|
||||
ADS1256 ADC_B(ADC_B_DRDY, ADS1256::PIN_UNUSED, ADS1256::PIN_UNUSED, ADC_B_CS, 2.5, &SPI_B);
|
||||
ADC_B.InitializeADC();
|
||||
ADC_B.setPGA(PGA_1);
|
||||
ADC_B.setDRATE(DRATE_7500SPS);
|
||||
dev.m_adc_b = &ADC_B;
|
||||
dev.m_spi_b = &SPI_B;
|
||||
LOG_DEBUG("Init ADC_B -> OK");
|
||||
delay(1000);
|
||||
#endif
|
||||
|
||||
if (!spiA_ok || !spiB_ok)
|
||||
@@ -132,27 +144,29 @@ void loop()
|
||||
esp_restart();
|
||||
}
|
||||
|
||||
LOG_DEBUG("Init SPI OK");
|
||||
LOG_DEBUG("Init SPI -> OK");
|
||||
|
||||
//////// INIT I2C INTERFACES ////////
|
||||
#ifdef I2C_ENABLE
|
||||
LOG_DEBUG("Init I2C Interfaces");
|
||||
bool i2c_ok = true;
|
||||
i2c_ok = Wire.begin(SDA, SCL, 100000);
|
||||
if (!i2c_ok)
|
||||
{
|
||||
LOG_ERROR("Unable to Initialize I2C Bus");
|
||||
LOG_ERROR("5 seconds to restart...");
|
||||
vTaskDelay(pdMS_TO_TICKS(5000));
|
||||
esp_restart();
|
||||
}
|
||||
LOG_DEBUG("Init I2c ok");
|
||||
Serial.readStringUntil('\n');
|
||||
|
||||
//////// INIT I2C INTERFACES ////////
|
||||
// LOG_DEBUG("Init I2C Interfaces");
|
||||
// bool i2c_ok = true;
|
||||
// i2c_ok = Wire.begin(SDA, SCL, 100000);
|
||||
// if (!i2c_ok)
|
||||
// {
|
||||
// LOG_ERROR("Unable to Initialize I2C Bus");
|
||||
// LOG_ERROR("5 seconds to restart...");
|
||||
// vTaskDelay(pdMS_TO_TICKS(5000));
|
||||
// esp_restart();
|
||||
// }
|
||||
// LOG_DEBUG("Init I2c ok");
|
||||
// Serial.readStringUntil('\n');
|
||||
|
||||
// Init IO Expanders
|
||||
// dev->m_ext_io = std::make_unique<ExternalIO>(Wire, dev->m_i2c_mutex, EXPANDER_ALL_INTERRUPT);
|
||||
dev->m_ext_io = std::make_unique<ExternalIO>(Wire, dev->m_i2c_mutex, EXPANDER_ALL_INTERRUPT);
|
||||
#endif
|
||||
|
||||
//////// INIT REALTIME TASKS PARAMETERS ////////
|
||||
//////// INIT REALTIME TASKS PARAMETERS ////////
|
||||
#ifdef CH_A_RT_ENABLE
|
||||
const rtIgnitionTask::rtTaskParams taskA_params{
|
||||
.rt_running = true,
|
||||
.name = "rtIgnTask_A",
|
||||
@@ -182,8 +196,9 @@ void loop()
|
||||
.relay_out_34 = RELAY_OUT_A34,
|
||||
},
|
||||
.rt_queue = nullptr,
|
||||
.dev = dev};
|
||||
|
||||
.dev = &dev};
|
||||
#endif
|
||||
#ifdef CH_B_RT_ENABLE
|
||||
const rtIgnitionTask::rtTaskParams taskB_params{
|
||||
.rt_running = true,
|
||||
.name = "rtIgnTask_B",
|
||||
@@ -213,18 +228,30 @@ void loop()
|
||||
.relay_out_34 = RELAY_OUT_B34,
|
||||
},
|
||||
.rt_queue = nullptr,
|
||||
.dev = dev};
|
||||
.dev = &dev};
|
||||
#endif
|
||||
|
||||
//////// SPAWN REALTIME TASKS ////////
|
||||
auto task_A = rtIgnitionTask(taskA_params, PSRAM_MAX, QUEUE_MAX, CORE_0, fs_mutex);
|
||||
delay(50);
|
||||
Serial.readStringUntil('\n');
|
||||
bool tasK_A_rt = true;
|
||||
bool task_B_rt = true;
|
||||
BaseType_t ignA_task_success = pdPASS;
|
||||
BaseType_t ignB_task_success = pdPASS;
|
||||
|
||||
#ifdef CH_A_RT_ENABLE
|
||||
auto task_A = rtIgnitionTask(taskA_params, PSRAM_MAX, QUEUE_MAX, CORE_1, fs_mutex);
|
||||
ignA_task_success = task_A.getStatus() == rtIgnitionTask::OK ? pdPASS : pdFAIL;
|
||||
//tasK_A_rt = task_A.start();
|
||||
delay(1000);
|
||||
#endif
|
||||
|
||||
#ifdef CH_B_RT_ENABLE
|
||||
auto task_B = rtIgnitionTask(taskB_params, PSRAM_MAX, QUEUE_MAX, CORE_1, fs_mutex);
|
||||
Serial.readStringUntil('\n');
|
||||
ignB_task_success = task_B.getStatus() == rtIgnitionTask::OK ? pdPASS : pdFAIL;
|
||||
//task_B_rt = task_B.start();
|
||||
delay(1000);
|
||||
#endif
|
||||
|
||||
// Ignition A on Core 0
|
||||
auto ignA_task_success = task_A.getStatus() == rtIgnitionTask::OK ? pdPASS : pdFAIL;
|
||||
auto ignB_task_success = task_B.getStatus() == rtIgnitionTask::OK ? pdPASS : pdFAIL;
|
||||
if (ignA_task_success != pdPASS || ignB_task_success != pdPASS)
|
||||
{
|
||||
LOG_ERROR("Unable to initialize ISR task");
|
||||
@@ -232,10 +259,6 @@ void loop()
|
||||
vTaskDelay(pdMS_TO_TICKS(5000));
|
||||
esp_restart();
|
||||
}
|
||||
|
||||
const bool tasK_A_rt = task_A.start();
|
||||
delay(50);
|
||||
const bool task_B_rt = task_B.start();
|
||||
if (tasK_A_rt != true || task_B_rt != true)
|
||||
{
|
||||
led.setStatus(RGBled::LedStatus::ERROR);
|
||||
@@ -248,18 +271,23 @@ void loop()
|
||||
}
|
||||
|
||||
//////// SPAWN WEBSERVER and WEBSOCKET ////////
|
||||
AstroWebServer webPage(80, LittleFS);
|
||||
ArduinoJson::JsonDocument json_data;
|
||||
bool data_a, data_b;
|
||||
bool data_a = false, data_b = false;
|
||||
#ifdef WEB_ENABLE
|
||||
AstroWebServer webPage(80, LittleFS);
|
||||
delay(1000);
|
||||
task_A.onMessage([&webPage, &json_data, &data_a](ignitionBoxStatusFiltered sts)
|
||||
{
|
||||
json_data["box_a"] = sts.toJson();
|
||||
data_a = true; });
|
||||
json_data["box_a"] = sts.toJson();
|
||||
data_a = true; });
|
||||
|
||||
#ifdef CH_B_RT_ENABLE
|
||||
task_B.onMessage([&webPage, &json_data, &data_b](ignitionBoxStatusFiltered sts)
|
||||
{
|
||||
json_data["box_b"] = sts.toJson();
|
||||
data_b = true; });
|
||||
json_data["box_b"] = sts.toJson();
|
||||
data_b = true; });
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// task_A.enableSave(true, "ignitionA_test.csv");
|
||||
// task_B.enableSave(true, "ignitionB_test.csv");
|
||||
@@ -270,12 +298,14 @@ void loop()
|
||||
while (running)
|
||||
{
|
||||
uint32_t this_loop = millis();
|
||||
if (this_loop - monitor_loop > 2000)
|
||||
if (this_loop - monitor_loop > 5000)
|
||||
{
|
||||
clearScreen();
|
||||
printRunningTasksMod(Serial);
|
||||
monitor_loop = millis();
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(10));
|
||||
#ifdef WEB_ENABLE
|
||||
if ((data_a && data_b) || (this_loop - data_loop > 500))
|
||||
{
|
||||
webPage.sendWsData(json_data.as<String>());
|
||||
@@ -283,6 +313,7 @@ void loop()
|
||||
data_a = data_b = false;
|
||||
data_loop = millis();
|
||||
}
|
||||
#endif
|
||||
} //////////////// INNER LOOP /////////////////////
|
||||
|
||||
} ////////////////////// MAIN LOOP //////////////////////
|
||||
|
||||
Reference in New Issue
Block a user