6namespace pvvx_mithermometer {
8static const char *
const TAG =
"display.pvvx_mithermometer";
12 "PVVX MiThermometer display:\n"
14 " Service UUID : %s\n"
15 " Characteristic UUID : %s\n"
20 ESP_LOGCONFIG(TAG,
" Set time on connection: %s", YESNO(this->
time_ !=
nullptr));
23 LOG_UPDATE_INTERVAL(
this);
27 esp_ble_gattc_cb_param_t *param) {
29 case ESP_GATTC_OPEN_EVT:
30 if (param->open.status == ESP_GATT_OK) {
35 case ESP_GATTC_DISCONNECT_EVT:
41 case ESP_GATTC_SEARCH_CMPL_EVT: {
70 ESP_LOGD(TAG,
"[%s] BLE client not enabled. Init connection.", this->
parent_->
address_str().c_str());
75 ESP_LOGW(TAG,
"[%s] Not connected to BLE client. State update can not be written.",
80 ESP_LOGW(TAG,
"[%s] No ble handle to BLE client. State update can not be written.",
84 ESP_LOGD(TAG,
"[%s] Send to display: bignum %d, smallnum: %d, cfg: 0x%02x, validity period: %u.",
85 this->
parent_->
address_str().c_str(), this->bignum_, this->smallnum_, this->cfg_, this->validity_period_);
89 blk[2] = (this->
bignum_ >> 8) & 0xff;
99 uint8_t mask = 1 << bit;
103 this->
cfg_ &= (0xFF ^ mask);
109 ESP_LOGW(TAG,
"[%s] Not connected to BLE client.", this->
parent_->
address_str().c_str());
113 esp_ble_gattc_write_char(this->
parent_->
get_gattc_if(), this->parent_->get_conn_id(), this->char_handle_, size,
114 blk, ESP_GATT_WRITE_TYPE_NO_RSP, ESP_GATT_AUTH_REQ_NONE);
132 if (this->
time_ ==
nullptr)
135 ESP_LOGW(TAG,
"[%s] Not connected to BLE client. Time can not be synced.", this->
parent_->
address_str().c_str());
139 ESP_LOGW(TAG,
"[%s] No ble handle to BLE client. Time can not be synced.", this->
parent_->
address_str().c_str());
143 if (!time.is_valid()) {
144 ESP_LOGW(TAG,
"[%s] Time is not yet valid. Time can not be synced.", this->
parent_->
address_str().c_str());
149#if ESP_IDF_VERSION_MAJOR >= 5
150 ESP_LOGD(TAG,
"[%s] Sync time with timestamp %" PRIu64
".", this->
parent_->
address_str().c_str(), time.timestamp);
152 ESP_LOGD(TAG,
"[%s] Sync time with timestamp %lu.", this->
parent_->
address_str().c_str(), time.timestamp);
155 blk[1] = time.timestamp & 0xff;
156 blk[2] = (time.timestamp >> 8) & 0xff;
157 blk[3] = (time.timestamp >> 16) & 0xff;
158 blk[4] = (time.timestamp >> 24) & 0xff;
bool cancel_timeout(const std::string &name)
Cancel a timeout function.
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
void set_enabled(bool enabled)
std::string address_str() const
BLECharacteristic * get_characteristic(espbt::ESPBTUUID service, espbt::ESPBTUUID chr)
void send_to_setup_char_(uint8_t *blk, size_t size)
void setcfgbit_(uint8_t bit, bool value)
optional< pvvx_writer_t > writer_
esp32_ble_tracker::ESPBTUUID service_uuid_
bool connection_established_
esp32_ble_tracker::ESPBTUUID char_uuid_
void dump_config() override
time::RealTimeClock * time_
void delayed_disconnect_()
void clear()
Clear the screen.
uint16_t validity_period_
void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param) override
uint32_t disconnect_delay_ms_
ESPTime now()
Get the time in the currently defined timezone.
Providing packet encoding functions for exchanging data with a remote host.
void recalc_timestamp_utc(bool use_day_of_year=true)
Recalculate the timestamp field from the other fields of this ESPTime instance (must be UTC).