70 case ESP_SLEEP_WAKEUP_UNDEFINED: |
70 case ESP_SLEEP_WAKEUP_UNDEFINED: |
71 default: |
71 default: |
72 ESP_LOGI(TAG, "Starting from hard reset"); |
72 ESP_LOGI(TAG, "Starting from hard reset"); |
73 } |
73 } |
74 |
74 |
75 const int wakeup_time_sec = 20; |
75 const int wakeup_time_sec = 55; |
76 ESP_LOGI(TAG, "Enabling timer wakeup, %ds", wakeup_time_sec); |
76 ESP_LOGI(TAG, "Enabling timer wakeup, %ds", wakeup_time_sec); |
77 esp_sleep_enable_timer_wakeup(wakeup_time_sec * 1000000); |
77 esp_sleep_enable_timer_wakeup(wakeup_time_sec * 1000000); |
78 |
78 |
79 // const int ext_wakeup_pin_1 = ROT_ENC_SW_GPIO; // 25 in example, redefine to rotary name. |
79 // const int ext_wakeup_pin_1 = ROT_ENC_SW_GPIO; // 25 in example, redefine to rotary name. |
80 // const uint64_t ext_wakeup_pin_1_mask = 1ULL << ext_wakeup_pin_1; |
80 // const uint64_t ext_wakeup_pin_1_mask = 1ULL << ext_wakeup_pin_1; |
107 u8g2_esp32_hal.sda = PIN_SDA; |
107 u8g2_esp32_hal.sda = PIN_SDA; |
108 u8g2_esp32_hal.scl = PIN_SCL; |
108 u8g2_esp32_hal.scl = PIN_SCL; |
109 u8g2_esp32_hal_init(u8g2_esp32_hal); |
109 u8g2_esp32_hal_init(u8g2_esp32_hal); |
110 |
110 |
111 u8g2_t u8g2; // a structure which will contain all the data for one display |
111 u8g2_t u8g2; // a structure which will contain all the data for one display |
112 u8g2_Setup_sh1106_i2c_128x64_noname_f( |
112 u8g2_Setup_sh1106_i2c_128x64_noname_f(&u8g2, U8G2_R0, u8g2_esp32_i2c_byte_cb, u8g2_esp32_gpio_and_delay_cb); // init u8g2 structure |
113 &u8g2, |
|
114 U8G2_R0, |
|
115 u8g2_esp32_i2c_byte_cb, |
|
116 u8g2_esp32_gpio_and_delay_cb); // init u8g2 structure |
|
117 u8x8_SetI2CAddress(&u8g2.u8x8, 0x78); |
113 u8x8_SetI2CAddress(&u8g2.u8x8, 0x78); |
118 ESP_LOGI(TAG, "u8g2_InitDisplay"); |
114 ESP_LOGI(TAG, "u8g2_InitDisplay"); |
119 u8g2_InitDisplay(&u8g2); // send init sequence to the display, display is in sleep mode after this, |
115 u8g2_InitDisplay(&u8g2); // send init sequence to the display, display is in sleep mode after this, |
120 |
116 |
121 /* |
117 /* |
201 xTaskCreate(&task_ds18b20, "task_ds18b20", 2560, NULL, 8, &xTaskDS18B20); |
197 xTaskCreate(&task_ds18b20, "task_ds18b20", 2560, NULL, 8, &xTaskDS18B20); |
202 xTaskCreate(&task_adc, "task_adc", 2560, NULL, 8, &xTaskADC); |
198 xTaskCreate(&task_adc, "task_adc", 2560, NULL, 8, &xTaskADC); |
203 esp_log_level_set("wifi", ESP_LOG_ERROR); |
199 esp_log_level_set("wifi", ESP_LOG_ERROR); |
204 xTaskCreate(&task_wifi, "task_wifi", 4096, NULL, 3, &xTaskWifi); |
200 xTaskCreate(&task_wifi, "task_wifi", 4096, NULL, 3, &xTaskWifi); |
205 vTaskDelay(10 / portTICK_PERIOD_MS); |
201 vTaskDelay(10 / portTICK_PERIOD_MS); |
|
202 esp_log_level_set("MQTT_CLIENT", ESP_LOG_ERROR); |
206 xTaskCreate(&task_mqtt, "task_mqtt", 4096, NULL, 5, &xTaskMQTT); |
203 xTaskCreate(&task_mqtt, "task_mqtt", 4096, NULL, 5, &xTaskMQTT); |
207 |
204 |
208 // esp32-rotary-encoder requires that the GPIO ISR service is installed before calling rotary_encoder_register() |
205 /* |
209 // ESP_ERROR_CHECK(gpio_install_isr_service(0)); |
206 * Setup the Rotary Encoder. |
210 |
207 * esp32-rotary-encoder requires that the GPIO ISR service is |
211 // Initialise the rotary encoder device with the GPIOs for A and B signals |
208 * installed before calling rotary_encoder_register() |
212 // rotary_encoder_info_t info = { 0 }; |
209 */ |
213 // ESP_ERROR_CHECK(rotary_encoder_init(&info, ROT_ENC_A_GPIO, ROT_ENC_B_GPIO)); |
210 ESP_ERROR_CHECK(gpio_install_isr_service(0)); |
214 // ESP_ERROR_CHECK(rotary_encoder_enable_half_steps(&info, ENABLE_HALF_STEPS)); |
211 rotary_encoder_info_t rinfo = { 0 }; |
|
212 ESP_ERROR_CHECK(rotary_encoder_init(&rinfo, ROT_ENC_A_GPIO, ROT_ENC_B_GPIO)); |
|
213 // ESP_ERROR_CHECK(rotary_encoder_enable_half_steps(&rinfo, ENABLE_HALF_STEPS)); |
215 #ifdef FLIP_DIRECTION |
214 #ifdef FLIP_DIRECTION |
216 // ESP_ERROR_CHECK(rotary_encoder_flip_direction(&info)); |
215 // ESP_ERROR_CHECK(rotary_encoder_flip_direction(&rinfo)); |
217 #endif |
216 #endif |
218 |
217 |
219 // Create a queue for events from the rotary encoder driver. |
218 // Create a queue for events from the rotary encoder driver. |
220 // Tasks can read from this queue to receive up to date position information. |
219 // Tasks can read from this queue to receive up to date position information. |
221 // QueueHandle_t event_queue = rotary_encoder_create_queue(); |
220 // QueueHandle_t event_queue = rotary_encoder_create_queue(); |
222 // ESP_ERROR_CHECK(rotary_encoder_set_queue(&info, event_queue)); |
221 // ESP_ERROR_CHECK(rotary_encoder_set_queue(&rinfo, event_queue)); |
223 |
222 |
224 |
223 |
225 /* |
224 /* |
226 * Main application loop. |
225 * Main application loop. |
227 */ |
226 */ |