Skip to content

Commit

Permalink
Fix debug output line breaks
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisxhe committed Jul 22, 2024
1 parent aa37baa commit f4ea935
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 46 deletions.
40 changes: 20 additions & 20 deletions src/SensorBHI260AP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,13 @@ class SensorBHI260AP
__error_code = (bhy2_get_feature_status(&feat_status, bhy2));
BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_get_feature_status failed!", false);

stream.printf("Product ID : %02x", product_id);
stream.printf("Kernel version : %04u", kernel_version);
stream.printf("User version : %04u", user_version);
stream.printf("ROM version : %04u", rom_version);
stream.printf("Power state : %s", (host_status & BHY2_HST_POWER_STATE) ? "sleeping" : "active");
stream.printf("Host interface : %s", (host_status & BHY2_HST_HOST_PROTOCOL) ? "SPI" : "I2C");
stream.printf("Feature status : 0x%02x", feat_status);
stream.printf("Product ID : %02x\n", product_id);
stream.printf("Kernel version : %04u\n", kernel_version);
stream.printf("User version : %04u\n", user_version);
stream.printf("ROM version : %04u\n", rom_version);
stream.printf("Power state : %s\n", (host_status & BHY2_HST_POWER_STATE) ? "sleeping" : "active");
stream.printf("Host interface : %s\n", (host_status & BHY2_HST_HOST_PROTOCOL) ? "SPI" : "I2C");
stream.printf("Feature status : 0x%02x\n", feat_status);

/* Read boot status */
__error_code = (bhy2_get_boot_status(&boot_status, bhy2));
Expand Down Expand Up @@ -295,17 +295,17 @@ class SensorBHI260AP
/* Get present virtual sensor */
bhy2_get_virt_sensor_list(bhy2);

stream.printf("Virtual sensor list.");
stream.printf("Sensor ID | Sensor Name | ID | Ver | Min rate | Max rate |");
stream.printf("----------+--------------------------------------+-----+-----+-----------+-----------|");
stream.printf("Virtual sensor list.\r\n");
stream.printf("Sensor ID | Sensor Name | ID | Ver | Min rate | Max rate |\r\n");
stream.printf("----------+--------------------------------------+-----+-----+-----------+-----------|\r\n");
for (uint8_t i = 0; i < BHY2_SENSOR_ID_MAX; i++) {
if (bhy2_is_sensor_available(i, bhy2)) {
if (i < BHY2_SENSOR_ID_CUSTOM_START) {
stream.printf(" %8u | %36s ", i, get_sensor_name(i));
}
__error_code = (bhy2_get_sensor_info(i, &info, bhy2));
BHY2_RLST_CHECK(__error_code != BHY2_OK, "bhy2_get_sensor_info failed!", false);
stream.printf("| %3u | %3u | %9.4f | %9.4f |",
stream.printf("| %3u | %3u | %9.4f | %9.4f |\r\n",
info.driver_id,
info.driver_version,
info.min_rate.f_val,
Expand Down Expand Up @@ -341,15 +341,15 @@ class SensorBHI260AP
if (__error_code != BHY2_OK) {
return ;
}
stream.printf("Host interrupt control");
stream.printf("-- Wake up FIFO %s.", (data & BHY2_ICTL_DISABLE_FIFO_W) ? "disabled" : "enabled");
stream.printf("-- Non wake up FIFO %s.", (data & BHY2_ICTL_DISABLE_FIFO_NW) ? "disabled" : "enabled");
stream.printf("-- Status FIFO %s.", (data & BHY2_ICTL_DISABLE_STATUS_FIFO) ? "disabled" : "enabled");
stream.printf("-- Debugging %s.", (data & BHY2_ICTL_DISABLE_DEBUG) ? "disabled" : "enabled");
stream.printf("-- Fault %s.", (data & BHY2_ICTL_DISABLE_FAULT) ? "disabled" : "enabled");
stream.printf("-- Interrupt is %s.", (data & BHY2_ICTL_ACTIVE_LOW) ? "active low" : "active high");
stream.printf("-- Interrupt is %s triggered.", (data & BHY2_ICTL_EDGE) ? "pulse" : "level");
stream.printf("-- Interrupt pin drive is %s.", (data & BHY2_ICTL_OPEN_DRAIN) ? "open drain" : "push-pull");
stream.printf("Host interrupt control\r\n");
stream.printf("-- Wake up FIFO %s.\r\n", (data & BHY2_ICTL_DISABLE_FIFO_W) ? "disabled" : "enabled");
stream.printf("-- Non wake up FIFO %s.\r\n", (data & BHY2_ICTL_DISABLE_FIFO_NW) ? "disabled" : "enabled");
stream.printf("-- Status FIFO %s.\r\n", (data & BHY2_ICTL_DISABLE_STATUS_FIFO) ? "disabled" : "enabled");
stream.printf("-- Debugging %s.\r\n", (data & BHY2_ICTL_DISABLE_DEBUG) ? "disabled" : "enabled");
stream.printf("-- Fault %s.\r\n", (data & BHY2_ICTL_DISABLE_FAULT) ? "disabled" : "enabled");
stream.printf("-- Interrupt is %s.\r\n", (data & BHY2_ICTL_ACTIVE_LOW) ? "active low" : "active high");
stream.printf("-- Interrupt is %s triggered.\r\n", (data & BHY2_ICTL_EDGE) ? "pulse" : "level");
stream.printf("-- Interrupt pin drive is %s.\r\n", (data & BHY2_ICTL_OPEN_DRAIN) ? "open drain" : "push-pull");
}

bool isReady()
Expand Down
33 changes: 20 additions & 13 deletions src/SensorCommon.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,27 @@ public:

bool begin(PLATFORM_WIRE_TYPE &w, uint8_t addr, int sda, int scl)
{
log_i("Using Arduino Wire interface.\n");
log_i("Using Arduino Wire interface.");
if (__has_init)return thisChip().initImpl();
__wire = &w;
__sda = sda;
__scl = scl;
#if defined(NRF52840_XXAA) || defined(NRF52832_XXAA)
if (__sda != 0xFF && __scl != 0xFF) {
__wire->setPins(__sda, __scl);
}
__wire->begin();
#elif defined(ARDUINO_ARCH_RP2040)
__wire->end();
__wire->setSDA(__sda);
__wire->setSCL(__scl);
#elif defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_STM32)
if (__sda != 0xFF && __scl != 0xFF) {
__wire->end();
__wire->setSDA(__sda);
__wire->setSCL(__scl);
}
__wire->begin();
#else
#elif defined(ARDUINO_ARCH_ESP32)
__wire->begin(__sda, __scl);
#else
__wire->begin();
#endif
__addr = addr;
__spi = NULL;
Expand All @@ -97,7 +104,7 @@ public:
PLATFORM_SPI_TYPE &spi = SPI
)
{
log_i("Using Arduino SPI interface.\n");
log_i("Using Arduino SPI interface.");
if (__has_init)return thisChip().initImpl();
__cs = cs;
__spi = &spi;
Expand Down Expand Up @@ -135,7 +142,7 @@ public:

bool begin(i2c_master_bus_handle_t i2c_dev_bus_handle, uint8_t addr)
{
log_i("Using ESP-IDF Driver interface.\n");
log_i("Using ESP-IDF Driver interface.");
if (i2c_dev_bus_handle == NULL) return false;
if (__has_init)return thisChip().initImpl();

Expand Down Expand Up @@ -169,15 +176,15 @@ public:
if (ESP_OK != i2c_master_bus_add_device(bus_handle,
&__i2c_dev_conf,
&__i2c_device)) {
log_i("i2c_master_bus_add_device failed !\n");
log_i("i2c_master_bus_add_device failed !");
return false;
}
log_i("Added Device Address : 0x%X New Dev Address: %p Speed :%lu \n", __addr, __i2c_device, __i2c_dev_conf.scl_speed_hz);
log_i("Added Device Address : 0x%X New Dev Address: %p Speed :%lu ", __addr, __i2c_device, __i2c_dev_conf.scl_speed_hz);
__has_init = thisChip().initImpl();

if (!__has_init) {
// Initialization failed, delete device
log_i("i2c_master_bus_rm_device !\n");
log_i("i2c_master_bus_rm_device !");
i2c_master_bus_rm_device(__i2c_device);
}

Expand All @@ -189,7 +196,7 @@ public:
bool begin(i2c_port_t port_num, uint8_t addr, int sda, int scl)
{
__i2c_num = port_num;
log_i("Using ESP-IDF Driver interface.\n");
log_i("Using ESP-IDF Driver interface.");
if (__has_init)return thisChip().initImpl();
__sda = sda;
__scl = scl;
Expand Down Expand Up @@ -226,7 +233,7 @@ public:

bool begin(uint8_t addr, iic_fptr_t readRegCallback, iic_fptr_t writeRegCallback)
{
log_i("Using Custom interface.\n");
log_i("Using Custom interface.");
if (__has_init)return thisChip().initImpl();
__i2c_master_read = readRegCallback;
__i2c_master_write = writeRegCallback;
Expand Down
7 changes: 4 additions & 3 deletions src/SensorLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,15 @@ typedef struct __SensorLibPins {

#ifdef ARDUINO
#if !defined(ESP32) || !defined(ARDUINO_ARCH_ESP32)
#define LOG_FILE_LINE_INFO __FILE__, __LINE__
#ifndef log_e
#define log_e(...) Serial.printf(__VA_ARGS__)
#define log_e(fmt, ...) Serial.printf("[E][%s:%d] " fmt "\n", LOG_FILE_LINE_INFO, ##__VA_ARGS__)
#endif
#ifndef log_i
#define log_i(...) Serial.printf(__VA_ARGS__)
#define log_i(fmt, ...) Serial.printf("[I][%s:%d] " fmt "\n", LOG_FILE_LINE_INFO, ##__VA_ARGS__)
#endif
#ifndef log_d
#define log_d(...) Serial.printf(__VA_ARGS__)
#define log_d(fmt, ...) Serial.printf("[D][%s:%d] " fmt "\n", LOG_FILE_LINE_INFO, ##__VA_ARGS__)
#endif
#endif
#elif defined(ESP_PLATFORM)
Expand Down
20 changes: 10 additions & 10 deletions src/TouchDrvFT6X36.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ class TouchDrvFT6X36 :


if (vendId != FT6X36_VEND_ID) {
log_e("Vendor id is 0x%X not match!\n", vendId);
log_e("Vendor id is 0x%X not match!", vendId);
return false;
}

Expand All @@ -390,24 +390,24 @@ class TouchDrvFT6X36 :
(__chipID != FT6236U_CHIP_ID) &&
(__chipID != FT3267_CHIP_ID)
) {
log_e("Vendor id is not match!\n");
log_e("ChipID:0x%lx should be 0x06 or 0x36 or 0x64\n", __chipID);
log_e("Vendor id is not match!");
log_e("ChipID:0x%lx should be 0x06 or 0x36 or 0x64", __chipID);
return false;
}

log_i("Vend ID: 0x%X\n", vendId);
log_i("Chip ID: 0x%lx\n", __chipID);
log_i("Firm Version: 0x%X\n", readRegister(FT6X36_REG_FIRM_VERS));
log_i("Point Rate Hz: %u\n", readRegister(FT6X36_REG_PERIOD_ACTIVE));
log_i("Thresh : %u\n", readRegister(FT6X36_REG_THRESHOLD));
log_i("Vend ID: 0x%X", vendId);
log_i("Chip ID: 0x%lx", __chipID);
log_i("Firm Version: 0x%X", readRegister(FT6X36_REG_FIRM_VERS));
log_i("Point Rate Hz: %u", readRegister(FT6X36_REG_PERIOD_ACTIVE));
log_i("Thresh : %u", readRegister(FT6X36_REG_THRESHOLD));

// change threshold to be higher/lower
writeRegister(FT6X36_REG_THRESHOLD, 60);

log_i("Chip library version : 0x%x\n", getLibraryVersion());
log_i("Chip library version : 0x%x", getLibraryVersion());

// This register describes period of monitor status, it should not less than 30.
log_i("Chip period of monitor status : 0x%x\n", readRegister(FT6X36_REG_PERIOD_MONITOR));
log_i("Chip period of monitor status : 0x%x", readRegister(FT6X36_REG_PERIOD_MONITOR));

// This register describes the period of active status, it should not less than 12

Expand Down

0 comments on commit f4ea935

Please sign in to comment.