Compare commits
2 Commits
ec138553ad
...
6072a603df
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6072a603df | ||
|
|
27ad612844 |
@@ -11,9 +11,11 @@ void trig_isr(void *arg)
|
||||
// exit if invalid args
|
||||
if (!arg)
|
||||
return;
|
||||
// FOR TESTING ONLY
|
||||
digitalWrite(POT_A_CS, HIGH);
|
||||
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
isrParams *params = (isrParams*)arg;
|
||||
isrParams *params = (isrParams *)arg;
|
||||
ignitionBoxStatus *box = params->ign_stat;
|
||||
TaskHandle_t task_handle = *params->rt_handle_ptr;
|
||||
|
||||
@@ -28,10 +30,12 @@ void trig_isr(void *arg)
|
||||
switch (params->flag)
|
||||
{
|
||||
case TRIG_FLAG_12P:
|
||||
case TRIG_FLAG_12N:
|
||||
box->coils12.trig_time = time_us;
|
||||
xTaskNotifyFromISR(task_handle, params->flag, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
break;
|
||||
case TRIG_FLAG_34P:
|
||||
case TRIG_FLAG_34N:
|
||||
box->coils34.trig_time = time_us;
|
||||
xTaskNotifyFromISR(task_handle, params->flag, eSetValueWithOverwrite, &xHigherPriorityTaskWoken);
|
||||
break;
|
||||
@@ -48,6 +52,8 @@ void trig_isr(void *arg)
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// FOR TESTING ONLY
|
||||
digitalWrite(POT_A_CS, LOW);
|
||||
|
||||
if (xHigherPriorityTaskWoken)
|
||||
portYIELD_FROM_ISR();
|
||||
|
||||
@@ -47,8 +47,8 @@ enum sparkStatus
|
||||
|
||||
enum softStartStatus
|
||||
{
|
||||
SOFT_START,
|
||||
NORMAL
|
||||
NORMAL,
|
||||
SOFT_START
|
||||
};
|
||||
|
||||
struct coilsStatus
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <tasks.h>
|
||||
#include <channels.h>
|
||||
#include <devices.h>
|
||||
#include <ui.h>
|
||||
|
||||
void printTaskList()
|
||||
{
|
||||
@@ -58,7 +59,7 @@ void loop()
|
||||
|
||||
QueueHandle_t rt_taskA_queue = xQueueCreate(10, sizeof(ignitionBoxStatus));
|
||||
QueueHandle_t rt_taskB_queue = xQueueCreate(10, sizeof(ignitionBoxStatus));
|
||||
rtTaskParams taskA_params {
|
||||
rtTaskParams taskA_params{
|
||||
.rt_running = true,
|
||||
.dev = &dev,
|
||||
.rt_handle_ptr = &trigA_TaskHandle,
|
||||
@@ -71,15 +72,12 @@ void loop()
|
||||
.trig_pin_34n = TRIG_PIN_A34N,
|
||||
.spark_pin_12 = SPARK_PIN_A12,
|
||||
.spark_pin_34 = SPARK_PIN_A34},
|
||||
.rt_resets = rtTaskResets{
|
||||
.rst_io_12p = RST_EXT_A12P,
|
||||
.rst_io_12n = RST_EXT_A12N,
|
||||
.rst_io_34p = RST_EXT_A34P,
|
||||
.rst_io_34n = RST_EXT_A34N}
|
||||
};
|
||||
.rt_resets = rtTaskResets{.rst_io_12p = RST_EXT_A12P, .rst_io_12n = RST_EXT_A12N, .rst_io_34p = RST_EXT_A34P, .rst_io_34n = RST_EXT_A34N}};
|
||||
|
||||
LOG_INFO("Task Variables OK");
|
||||
#ifndef TEST
|
||||
QueueHandle_t rt_taskB_queue = xQueueCreate(10, sizeof(ignitionBoxStatus));
|
||||
rtTaskParams taskB_params {
|
||||
rtTaskParams taskB_params{
|
||||
.rt_running = true,
|
||||
.dev = &dev,
|
||||
.rt_queue = rt_taskB_queue,
|
||||
@@ -92,21 +90,15 @@ void loop()
|
||||
.trig_pin_34n = TRIG_PIN_B34N,
|
||||
.spark_pin_12 = SPARK_PIN_B12,
|
||||
.spark_pin_34 = SPARK_PIN_B34},
|
||||
.rt_resets = rtTaskResets{
|
||||
.rst_io_12p = RST_EXT_B12P,
|
||||
.rst_io_12n = RST_EXT_B12N,
|
||||
.rst_io_34p = RST_EXT_B34P,
|
||||
.rst_io_34n = RST_EXT_B34N}
|
||||
};
|
||||
.rt_resets = rtTaskResets{.rst_io_12p = RST_EXT_B12P, .rst_io_12n = RST_EXT_B12N, .rst_io_34p = RST_EXT_B34P, .rst_io_34n = RST_EXT_B34N}};
|
||||
#endif
|
||||
|
||||
// Init 2 SPI interfaces
|
||||
bool spiA_ok = true;
|
||||
SPIClass SPI_A(FSPI);
|
||||
spiA_ok = SPI_A.begin(SPI_A_SCK, SPI_A_MISO, SPI_A_MOSI);
|
||||
|
||||
bool spiB_ok = true;
|
||||
#ifndef TEST
|
||||
// Init 2 SPI interfaces
|
||||
SPIClass SPI_A(FSPI);
|
||||
spiA_ok = SPI_A.begin(SPI_A_SCK, SPI_A_MISO, SPI_A_MOSI);
|
||||
SPIClass SPI_B(HSPI);
|
||||
spiB_ok = SPI_B.begin(SPI_B_SCK, SPI_B_MISO, SPI_B_MOSI);
|
||||
#endif
|
||||
@@ -117,23 +109,23 @@ void loop()
|
||||
vTaskDelay(pdMS_TO_TICKS(5000));
|
||||
esp_restart();
|
||||
}
|
||||
LOG_INFO("Init SPI [OK]");
|
||||
LOG_INFO("Init SPI OK");
|
||||
|
||||
#ifndef TEST
|
||||
// Init ADC_A
|
||||
dev.adc_a = new ADS1256(ADC_A_DRDY, ADC_A_RST, ADC_A_SYNC, ADC_A_CS, 2.5, &SPI_A);
|
||||
dev.adc_a->InitializeADC();
|
||||
dev.adc_a->setPGA(PGA_1);
|
||||
dev.adc_a->setDRATE(DRATE_1000SPS);
|
||||
|
||||
#ifndef TEST
|
||||
|
||||
// Init ADC_B
|
||||
dev.adc_a = new ADS1256(ADC_B_DRDY, ADC_B_RST, ADC_B_SYNC, ADC_B_CS, 2.5, &SPI_B);
|
||||
dev.adc_a->InitializeADC();
|
||||
dev.adc_a->setPGA(PGA_1);
|
||||
dev.adc_a->setDRATE(DRATE_1000SPS);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
LOG_INFO("Init ADC [OK]");
|
||||
LOG_INFO("Init ADC OK");
|
||||
|
||||
// Ignition A on Core 0
|
||||
auto ignA_task_success = pdPASS;
|
||||
@@ -151,7 +143,7 @@ void loop()
|
||||
#ifndef TEST
|
||||
ignB_task_success = xTaskCreatePinnedToCore(
|
||||
rtIgnitionTask,
|
||||
"rtIgnitionTask_boxA",
|
||||
"rtIgnitionTask_boxB",
|
||||
TASK_STACK,
|
||||
(void *)&taskB_params,
|
||||
TASK_PRIORITY, // priorità leggermente più alta
|
||||
@@ -171,10 +163,49 @@ void loop()
|
||||
|
||||
////////////////////// MAIN LOOP //////////////////////
|
||||
uint32_t count(0);
|
||||
clearScreen();
|
||||
setCursor(0, 0);
|
||||
|
||||
while (running)
|
||||
{
|
||||
// printTaskList();
|
||||
delay(10000);
|
||||
ignitionBoxStatus ignA;
|
||||
if (xQueueReceive(rt_taskA_queue, &ignA, pdMS_TO_TICKS(100)) == pdTRUE)
|
||||
{
|
||||
printField("++ Timestamp", (uint32_t)ignA.timestamp, 0, 0);
|
||||
if (firstRun)
|
||||
Serial.println("========== Coils 12 =============");
|
||||
printField("Pickup Tim", (uint32_t)ignA.coils12.trig_time, 0, 1);
|
||||
printField("Spark Tim", (uint32_t)ignA.coils12.spark_time, 0, 2);
|
||||
printField("Spark Dly", (uint32_t)ignA.coils12.spark_delay, 0, 3);
|
||||
printField("Spark Sts", (uint32_t)ignA.coils12.spark_status, 0, 4);
|
||||
printField("Peak P_IN", ignA.coils12.peak_p_in, 0, 5);
|
||||
printField("Peak P_OUT", ignA.coils12.peak_p_out, 0, 6);
|
||||
printField("Peak N_IN", ignA.coils12.peak_n_in, 0, 7);
|
||||
printField("Peak N_OUT", ignA.coils12.peak_n_out, 0, 8);
|
||||
printField("SoftStart ", (uint32_t)ignA.coils12.sstart_status, 0, 9);
|
||||
if (firstRun)
|
||||
Serial.println("========== Coils 34 =============");
|
||||
printField("Pickup Tim", (uint32_t)ignA.coils34.trig_time, 0, 11);
|
||||
printField("Spark Tim", (uint32_t)ignA.coils34.spark_time, 0, 12);
|
||||
printField("Spark Dly", (uint32_t)ignA.coils34.spark_delay, 0, 13);
|
||||
printField("Spark Sts", (uint32_t)ignA.coils34.spark_delay, 0, 14);
|
||||
printField("Peak P_IN", ignA.coils34.peak_p_in, 0, 15);
|
||||
printField("Peak P_OUT", ignA.coils34.peak_p_out, 0, 16);
|
||||
printField("Peak N_IN", ignA.coils34.peak_n_in, 0, 17);
|
||||
printField("Peak N_OUT", ignA.coils34.peak_n_out, 0, 18);
|
||||
printField("SoftStart ", (uint32_t)ignA.coils34.sstart_status, 0, 19);
|
||||
if (firstRun)
|
||||
Serial.println("========== END =============");
|
||||
if (count++ % 10 == 0)
|
||||
{
|
||||
firstRun = true;
|
||||
clearScreen();
|
||||
setCursor(0, 0);
|
||||
}
|
||||
else
|
||||
|
||||
firstRun = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (trigA_TaskHandle)
|
||||
|
||||
@@ -9,13 +9,14 @@ void rtIgnitionTask(void *pvParameters)
|
||||
LOG_ERROR("Null rt_task_ptr parameters");
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
LOG_INFO("rtTask Params OK");
|
||||
|
||||
// Task Parameters and Devices
|
||||
rtTaskParams *params = (rtTaskParams *)pvParameters;
|
||||
const rtTaskInterrupts rt_int = params->rt_int; // copy to avoid external override
|
||||
const rtTaskResets rt_rst = params->rt_resets; // copy to avoid external override
|
||||
QueueHandle_t rt_queue = params->rt_queue;
|
||||
TaskHandle_t* rt_handle_ptr = params->rt_handle_ptr;
|
||||
TaskHandle_t *rt_handle_ptr = params->rt_handle_ptr;
|
||||
Devices *dev = params->dev;
|
||||
ADS1256 *adc = dev->adc_a;
|
||||
PCA9555 *io = dev->io;
|
||||
@@ -47,13 +48,19 @@ void rtIgnitionTask(void *pvParameters)
|
||||
.ign_stat = &ign_box_sts,
|
||||
.rt_handle_ptr = rt_handle_ptr};
|
||||
|
||||
LOG_INFO("rtTask ISR Params OK");
|
||||
|
||||
pinMode(POT_A_CS, OUTPUT);
|
||||
|
||||
// Attach Pin Interrupts
|
||||
attachInterruptArg(rt_int.trig_pin_12p, rt_int.isr_ptr, (void *)&isr_params_t12p, RISING);
|
||||
attachInterruptArg(rt_int.trig_pin_12n, rt_int.isr_ptr, (void *)&isr_params_t12n, RISING);
|
||||
attachInterruptArg(rt_int.trig_pin_34p, rt_int.isr_ptr, (void *)&isr_params_t34p, RISING);
|
||||
attachInterruptArg(rt_int.trig_pin_34n, rt_int.isr_ptr, (void *)&isr_params_t34n, RISING);
|
||||
attachInterruptArg(rt_int.spark_pin_12, rt_int.isr_ptr, (void *)&isr_params_sp12, RISING);
|
||||
attachInterruptArg(rt_int.spark_pin_34, rt_int.isr_ptr, (void *)&isr_params_sp34, RISING);
|
||||
attachInterruptArg(digitalPinToInterrupt(rt_int.trig_pin_12p), rt_int.isr_ptr, (void *)&isr_params_t12p, RISING);
|
||||
attachInterruptArg(digitalPinToInterrupt(rt_int.trig_pin_12n), rt_int.isr_ptr, (void *)&isr_params_t12n, RISING);
|
||||
attachInterruptArg(digitalPinToInterrupt(rt_int.trig_pin_34p), rt_int.isr_ptr, (void *)&isr_params_t34p, RISING);
|
||||
attachInterruptArg(digitalPinToInterrupt(rt_int.trig_pin_34n), rt_int.isr_ptr, (void *)&isr_params_t34n, RISING);
|
||||
attachInterruptArg(digitalPinToInterrupt(rt_int.spark_pin_12), rt_int.isr_ptr, (void *)&isr_params_sp12, RISING);
|
||||
attachInterruptArg(digitalPinToInterrupt(rt_int.spark_pin_34), rt_int.isr_ptr, (void *)&isr_params_sp34, RISING);
|
||||
|
||||
LOG_INFO("rtTask ISR Attach OK");
|
||||
|
||||
// Compute Reset Pin Bitmask
|
||||
const uint16_t rst_bitmask = (1 << rt_rst.rst_io_12p) |
|
||||
@@ -61,28 +68,27 @@ void rtIgnitionTask(void *pvParameters)
|
||||
(1 << rt_rst.rst_io_34p) |
|
||||
(1 << rt_rst.rst_io_34n);
|
||||
|
||||
LOG_WARN("rtTask Init Correct");
|
||||
// Global rt_task_ptr variables
|
||||
uint32_t it = 0;
|
||||
uint32_t q_fail_count = 0;
|
||||
|
||||
while (params->rt_running)
|
||||
{
|
||||
// Global rt_task_ptr variables
|
||||
uint32_t pickup_flag = 0;
|
||||
uint32_t spark_flag = 0;
|
||||
|
||||
#ifdef DEBUG
|
||||
Serial.print("\033[2J"); // clear screen
|
||||
Serial.print("\033[H"); // cursor home
|
||||
LOG_INFO("Iteration [", it, "]");
|
||||
#endif
|
||||
|
||||
// WAIT FOR PICKUP SIGNAL
|
||||
xTaskNotifyWait(
|
||||
0x00, // non pulire all'ingresso
|
||||
ULONG_MAX, // non pulire all'ingresso
|
||||
ULONG_MAX, // pulisci i primi 8 bit
|
||||
&pickup_flag, // valore ricevuto
|
||||
portMAX_DELAY);
|
||||
|
||||
#ifdef DEBUG
|
||||
LOG_INFO("Iteration [", it++, "]");
|
||||
Serial.print("\033[2J"); // clear screen
|
||||
Serial.print("\033[H"); // cursor home
|
||||
LOG_INFO("Pickup Flags: ", printBits(pickup_flag).c_str());
|
||||
if (!names.contains(pickup_flag))
|
||||
{
|
||||
@@ -99,9 +105,12 @@ void rtIgnitionTask(void *pvParameters)
|
||||
auto spark_timeout = ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(spark_timeout_max));
|
||||
if (ign_box_sts.coils12.spark_ok || ign_box_sts.coils34.spark_ok) // otherwise timeout if none is set in the ISR
|
||||
spark_flag = ign_box_sts.coils12.spark_ok ? SPARK_FLAG_12 : SPARK_FLAG_34;
|
||||
else
|
||||
spark_flag == SPARK_FLAG_NIL;
|
||||
|
||||
xTaskNotifyStateClear(NULL);
|
||||
ulTaskNotifyValueClear(NULL, 0xFFFFFFFF);
|
||||
|
||||
#ifdef DEBUG
|
||||
LOG_INFO("Spark Flags: ", printBits(spark_flag).c_str());
|
||||
if (!names.contains(spark_flag))
|
||||
@@ -135,12 +144,11 @@ void rtIgnitionTask(void *pvParameters)
|
||||
bool new_data = false;
|
||||
switch (pickup_flag)
|
||||
{
|
||||
// CASES for NEGATIVE cycle triggering of pickup and sparks 12 & 34
|
||||
case TRIG_FLAG_12P:
|
||||
case TRIG_FLAG_34P:
|
||||
{
|
||||
// Timeout not occourred, expected POSITIVE edge spark OCCOURRED
|
||||
if (spark_timeout == pdPASS)
|
||||
if (spark_flag != SPARK_FLAG_NIL)
|
||||
{
|
||||
coils->spark_delay = coils->spark_time - coils->trig_time;
|
||||
coils->sstart_status = softStartStatus::NORMAL; // because spark on positive edge
|
||||
@@ -151,12 +159,12 @@ void rtIgnitionTask(void *pvParameters)
|
||||
#endif
|
||||
}
|
||||
// Timeout occourred, expected POSITIVE edge spark NOT OCCOURRED
|
||||
else if (spark_timeout == pdFAIL)
|
||||
else if (spark_flag == SPARK_FLAG_NIL)
|
||||
{
|
||||
coils->spark_status = sparkStatus::SPARK_NEG_WAIT;
|
||||
coils->sstart_status = softStartStatus::NORMAL;
|
||||
}
|
||||
new_data = false;
|
||||
new_data = true;
|
||||
break; // Do nothing more on positive pulse
|
||||
}
|
||||
// CASES for NEGATIVE cycle triggering of pickup and sparks 12 & 34
|
||||
@@ -165,7 +173,7 @@ void rtIgnitionTask(void *pvParameters)
|
||||
{
|
||||
const bool expected_negative12 = coils->spark_status == sparkStatus::SPARK_NEG_WAIT;
|
||||
// Timeout not occourred, expected NEGATIVE edge spark OCCOURRED
|
||||
if (spark_timeout == pdPASS && expected_negative12)
|
||||
if (spark_flag != SPARK_FLAG_NIL && expected_negative12)
|
||||
{
|
||||
coils->spark_delay = coils->spark_time - coils->trig_time;
|
||||
coils->sstart_status = softStartStatus::SOFT_START;
|
||||
@@ -176,13 +184,13 @@ void rtIgnitionTask(void *pvParameters)
|
||||
#endif
|
||||
}
|
||||
// Timeout occourred, expected POSITIVE edge spark NOT OCCOURRED
|
||||
else if (spark_timeout == pdFAIL && expected_negative12)
|
||||
else if (spark_flag == SPARK_FLAG_NIL && expected_negative12)
|
||||
{
|
||||
coils->sstart_status = softStartStatus::NORMAL;
|
||||
coils->spark_status = sparkStatus::SPARK_NEG_FAIL;
|
||||
}
|
||||
// Timeout not occouured, unexpected negative edge spark
|
||||
else if (spark_timeout == pdPASS && !expected_negative12)
|
||||
else if (spark_flag != SPARK_FLAG_NIL && !expected_negative12)
|
||||
{
|
||||
coils->sstart_status = softStartStatus::SOFT_START;
|
||||
coils->spark_status = sparkStatus::SPARK_NEG_UNEXPECTED;
|
||||
@@ -192,7 +200,11 @@ void rtIgnitionTask(void *pvParameters)
|
||||
break;
|
||||
}
|
||||
default:
|
||||
#ifdef DEUG
|
||||
LOG_ERROR("Invalid Interrupt");
|
||||
LOG_ERROR("Pickup Flags: ", printBits(pickup_flag).c_str());
|
||||
LOG_ERROR("Spark Flags: ", printBits(spark_flag).c_str());
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,9 +7,7 @@
|
||||
// Arduino Libraries
|
||||
#include <Arduino.h>
|
||||
#include <DebugLog.h>
|
||||
#ifdef DEBUG
|
||||
#include "utils.h"
|
||||
#endif
|
||||
|
||||
// ISR
|
||||
#include "isr.h"
|
||||
@@ -23,12 +21,12 @@ const uint8_t spark_timeout_max = 2; // in milliseconds
|
||||
// Debug Variables
|
||||
#ifdef DEBUG
|
||||
static const std::map<const uint32_t, const char *> names = {
|
||||
{TRIG_FLAG_A12P, "TRIG_FLAG_A12P"},
|
||||
{TRIG_FLAG_A12N, "TRIG_FLAG_A12N"},
|
||||
{TRIG_FLAG_A34P, "TRIG_FLAG_A34P"},
|
||||
{TRIG_FLAG_A34N, "TRIG_FLAG_A34N"},
|
||||
{SPARK_FLAG_A12, "SPARK_FLAG_A12"},
|
||||
{SPARK_FLAG_A34, "SPARK_FLAG_A34"},
|
||||
{TRIG_FLAG_12P, "TRIG_FLAG_12P"},
|
||||
{TRIG_FLAG_12N, "TRIG_FLAG_12N"},
|
||||
{TRIG_FLAG_34P, "TRIG_FLAG_34P"},
|
||||
{TRIG_FLAG_34N, "TRIG_FLAG_34N"},
|
||||
{SPARK_FLAG_12, "SPARK_FLAG_12"},
|
||||
{SPARK_FLAG_34, "SPARK_FLAG_34"},
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
48
RotaxMonitor/src/ui.h
Normal file
48
RotaxMonitor/src/ui.h
Normal file
@@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
static bool firstRun = true;
|
||||
|
||||
void clearScreen(){
|
||||
Serial.print("\033[2J"); // clear screen
|
||||
Serial.print("\033[H"); // cursor home
|
||||
Serial.flush();
|
||||
}
|
||||
|
||||
void setCursor(const uint8_t x, const uint8_t y) {
|
||||
Serial.printf("\033[%d;%d", y, x+1);
|
||||
Serial.flush();
|
||||
}
|
||||
|
||||
void printField(const char name[], const uint32_t val, const uint8_t x, const uint8_t y) {
|
||||
if (firstRun) {
|
||||
setCursor(x,y);
|
||||
Serial.printf("%15s: %06d\n", name, val);
|
||||
return;
|
||||
}
|
||||
setCursor(x+16, y);
|
||||
Serial.print(val);
|
||||
}
|
||||
|
||||
void printField(const char name[], const int64_t val, const uint8_t x, const uint8_t y) {
|
||||
if (firstRun) {
|
||||
setCursor(x,y);
|
||||
Serial.printf("%15s: %06u\n", name, (uint64_t)val);
|
||||
return;
|
||||
}
|
||||
setCursor(x+16, y);
|
||||
Serial.print((uint64_t)val);
|
||||
Serial.flush();
|
||||
}
|
||||
|
||||
void printField(const char name[], const float val, const uint8_t x, const uint8_t y) {
|
||||
if (firstRun) {
|
||||
setCursor(x,y);
|
||||
Serial.printf("%15s: %4.2f\n", name, val);
|
||||
return;
|
||||
}
|
||||
setCursor(x+16, y);
|
||||
Serial.print(val);
|
||||
Serial.flush();
|
||||
}
|
||||
14
RotaxMonitor/src/utils.cpp
Normal file
14
RotaxMonitor/src/utils.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#include "utils.h"
|
||||
|
||||
std::string printBits(uint32_t value) {
|
||||
std::string result;
|
||||
for (int i = 31; i >= 0; i--) {
|
||||
// ottieni il singolo bit
|
||||
result += ((value >> i) & 1) ? '1' : '0';
|
||||
// aggiungi uno spazio ogni 8 bit, tranne dopo l'ultimo
|
||||
if (i % 8 == 0 && i != 0) {
|
||||
result += ' ';
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -3,15 +3,4 @@
|
||||
#include <Arduino.h>
|
||||
#include <string>
|
||||
|
||||
std::string printBits(uint32_t value) {
|
||||
std::string result;
|
||||
for (int i = 31; i >= 0; i--) {
|
||||
// ottieni il singolo bit
|
||||
result += ((value >> i) & 1) ? '1' : '0';
|
||||
// aggiungi uno spazio ogni 8 bit, tranne dopo l'ultimo
|
||||
if (i % 8 == 0 && i != 0) {
|
||||
result += ' ';
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
std::string printBits(uint32_t value);
|
||||
|
||||
Reference in New Issue
Block a user