Skip to content

Commit

Permalink
Add time between log
Browse files Browse the repository at this point in the history
  • Loading branch information
AzonInc committed Jan 26, 2025
1 parent 5f6371a commit 4c36f7d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
20 changes: 15 additions & 5 deletions components/tc_bus/tc_bus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ namespace esphome

auto &s = this->store_;

if(s.s_time_between_debug != 0 && s.s_time_between_debug < 9000)
{
ESP_LOGD(TAG, "Time between: %i", s.s_time_between_debug);
}

if(s.s_cmdReady) {
if(reading_memory_) {
ESP_LOGD(TAG, "Received 4 memory addresses %i to %i", (reading_memory_count_ * 4), (reading_memory_count_ * 4) + 4);
Expand Down Expand Up @@ -316,6 +321,7 @@ namespace esphome
}
#endif

volatile uint32_t TCBusComponentStore::s_time_between_debug = 0;
volatile uint32_t TCBusComponentStore::s_last_bit_change = 0;
volatile uint32_t TCBusComponentStore::s_cmd = 0;
volatile bool TCBusComponentStore::s_cmd_is_long = false;
Expand All @@ -326,10 +332,12 @@ namespace esphome
// Made by https://github.com/atc1441/TCSintercomArduino

// Timing thresholds (in microseconds)
const uint32_t BIT_0_MIN = 1000, BIT_0_MAX = 2999;
const uint32_t BIT_1_MIN = 3000, BIT_1_MAX = 4999;
const uint32_t BIT_2_MIN = 5000, BIT_2_MAX = 6999;
const uint32_t RESET_MIN = 7000, RESET_MAX = 24000;
const uint32_t START_MIN = 5000, START_MAX = 6999; // 6ms

const uint32_t BIT_0_MIN = 1000, BIT_0_MAX = 2999; // 2ms
const uint32_t BIT_1_MIN = 3000, BIT_1_MAX = 4999; // 4ms

const uint32_t RESET_MIN = 7000, RESET_MAX = 24000; // > 7ms

static uint32_t curCMD = 0; // Current command being constructed
static uint32_t usLast = 0; // Last timestamp in microseconds
Expand All @@ -344,13 +352,15 @@ namespace esphome
uint32_t timeInUS = usNow - usLast;
usLast = usNow;

arg->s_time_between_debug = timeInUS;

// Determine current bit based on time interval
uint8_t curBit = 4; // Default to undefined bit
if (timeInUS >= BIT_0_MIN && timeInUS <= BIT_0_MAX) {
curBit = 0;
} else if (timeInUS >= BIT_1_MIN && timeInUS <= BIT_1_MAX) {
curBit = 1;
} else if (timeInUS >= BIT_2_MIN && timeInUS <= BIT_2_MAX) {
} else if (timeInUS >= START_MIN && timeInUS <= START_MAX) {
curBit = 2;
} else if (timeInUS >= RESET_MIN && timeInUS <= RESET_MAX) {
curBit = 3; // Reset condition
Expand Down
1 change: 1 addition & 0 deletions components/tc_bus/tc_bus.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ namespace esphome
{
static void gpio_intr(TCBusComponentStore *arg);

static volatile uint32_t s_time_between_debug;
static volatile uint32_t s_last_bit_change;
static volatile uint32_t s_cmd;
static volatile bool s_cmd_is_long;
Expand Down

0 comments on commit 4c36f7d

Please sign in to comment.