Can't believe I fucked the for loop like that
Well I can believe it
This commit is contained in:
@@ -34,7 +34,13 @@ void dht22_handle_error(dht22_error e) {
|
||||
uint32_t wait_for_signal_to_change_from(int signal_level) {
|
||||
uint64_t start_time = esp_timer_get_time();
|
||||
uint64_t next_time = start_time;
|
||||
/*
|
||||
A vague attempt at "waiting" until the pin comes some kind of level
|
||||
if (gpio_get_level(CONFIG_DHT22_DATA_GPIO) != signal_level) {
|
||||
ets_delay_us(15);
|
||||
|
||||
}
|
||||
*/
|
||||
while (gpio_get_level(CONFIG_DHT22_DATA_GPIO) == signal_level) {
|
||||
next_time = esp_timer_get_time();
|
||||
if ((next_time - start_time) >= 1000 * 10) {
|
||||
@@ -95,9 +101,9 @@ dht22_error dht22_read() {
|
||||
* - if 26-28us -> 0 bit
|
||||
* - if 70us -> 1 bit
|
||||
*/
|
||||
portENABLE_INTERRUPTS();
|
||||
for (int byte_i = 4; byte_i >= 0; byte_i--) {
|
||||
for (int bit_i = 0; bit_i <= 8; bit_i++) {
|
||||
//portENABLE_INTERRUPTS();
|
||||
for (int byte_i = 0; byte_i <= 4; byte_i++) {
|
||||
for (int bit_i = 7; bit_i >= 0; bit_i--) {
|
||||
|
||||
elapsed_time = wait_for_signal_to_change_from(0);
|
||||
if (elapsed_time == DHT22_TIMEOUT_ERROR) {
|
||||
@@ -111,7 +117,7 @@ dht22_error dht22_read() {
|
||||
if (elapsed_time < 60 || elapsed_time > 80) {
|
||||
data[byte_i] |= (1 << bit_i);
|
||||
}
|
||||
ESP_LOGE(TAG, "elapsed_time: %lu", elapsed_time);
|
||||
//ESP_LOGE(TAG, "bit: %i, byte: %i, elapsed_time: %lu", bit_i, byte_i, elapsed_time);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -63,6 +63,9 @@ my_dht22_data ten_minute_rolling_average;
|
||||
uint32_t num_samples_last_ten_mins = 0;
|
||||
|
||||
void read_from_dht22() {
|
||||
// From datasheet:
|
||||
// Don't start within 1 second of powering on
|
||||
// vTaskDelay(pdMS_TO_TICKS(2000)); FIXME - still doesn't actually fix the problem though
|
||||
while (run_dht) {
|
||||
// Data reading is based on time, so need to block interrups etc
|
||||
// I _think_ these are freeRTOS task interrupts - I wonder if
|
||||
@@ -143,7 +146,7 @@ void app_main(void) {
|
||||
|
||||
#ifdef CONFIG_DHT22_ENABLED
|
||||
xTaskCreate(read_from_dht22, "DHT22",
|
||||
4 * 1024, // honestly I have _no_ idea
|
||||
8 * 1024, // honestly I have _no_ idea
|
||||
NULL,
|
||||
5, // no idea either
|
||||
&dht22_handle);
|
||||
|
||||
Reference in New Issue
Block a user