Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
AzonInc committed Jan 26, 2025
1 parent fa16b5d commit 999ce8a
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions components/tc_bus/tc_bus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,14 @@ namespace esphome
}
#endif

ESP_LOGD(TAG, "Set debug interval");
this->set_interval("debuglogs", 2000, [this] {
this->rx_pin_->detach_interrupt();
uint8_t index = s.debug_buffer_index;
s.debug_buffer_index = 0;
this->rx_pin_->attach_interrupt(TCBusComponentStore::gpio_intr, &this->store_, gpio::INTERRUPT_ANY_EDGE);

ESP_LOGD(TAG, "Time diff interval ended:");
for (uint8_t i = 0; i < index; i++) {
ESP_LOGD(TAG, "Time diff: %i", s.debug_buffer[i]);
}
Expand Down Expand Up @@ -339,12 +341,10 @@ namespace esphome
// Made by https://github.com/atc1441/TCSintercomArduino

// Timing thresholds (in microseconds)
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
const uint32_t BIT_0_MIN = 1700, BIT_0_MAX = 2300; // 2ms
const uint32_t BIT_1_MIN = 3700, BIT_1_MAX = 4300; // 4ms
const uint32_t START_MIN = 5700, START_MAX = 6300; // 6ms
const uint32_t RESET_MIN = 7000; // > 7ms

static uint32_t curCMD = 0; // Current command being constructed
static uint32_t usLast = 0; // Last timestamp in microseconds
Expand All @@ -364,26 +364,23 @@ namespace esphome
}

// Determine current bit based on time interval
uint8_t curBit = 4; // Default to undefined bit
uint8_t curBit;
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 >= START_MIN && timeInUS <= START_MAX) {
curBit = 2;
} else if (timeInUS >= RESET_MIN && timeInUS <= RESET_MAX) {
curBit = 3; // Reset condition
} else if (timeInUS >= RESET_MIN) {
// Reset if a reset signal is detected
curPos = 0;
return;
} else {
// Invalid timing, reset the position
curPos = 0;
return;
}

// Reset if a reset signal is detected
if (curBit == 3) {
curPos = 0;
return;
}

if (curPos == 0) {
// First bit after reset: expect start signal (bit 2)
Expand Down

0 comments on commit 999ce8a

Please sign in to comment.