10static const char *
const TAG =
"display.pvvx_mithermometer";
13 char service_buf[ble_device_base::UUID_STR_LEN];
14 char char_buf[ble_device_base::UUID_STR_LEN];
16 "PVVX MiThermometer display:\n"
18 " Service UUID : %s\n"
19 " Characteristic UUID : %s\n"
24 ESP_LOGCONFIG(TAG,
" Set time on connection: %s", YESNO(this->
time_ !=
nullptr));
27 LOG_UPDATE_INTERVAL(
this);
31 esp_ble_gattc_cb_param_t *param) {
33 case ESP_GATTC_OPEN_EVT:
34 if (param->open.status == ESP_GATT_OK) {
39 case ESP_GATTC_DISCONNECT_EVT:
45 case ESP_GATTC_SEARCH_CMPL_EVT: {
68 case ESP_GAP_BLE_AUTH_CMPL_EVT: {
72 if (param->ble_security.auth_cmpl.success) {
73 ESP_LOGD(TAG,
"[%s] Authentication successful, performing writes.", this->
parent_->
address_str());
96 ESP_LOGD(TAG,
"[%s] BLE client not enabled. Init connection.", this->
parent_->
address_str());
101 ESP_LOGW(TAG,
"[%s] Not connected to BLE client. State update can not be written.", this->
parent_->
address_str());
105 ESP_LOGW(TAG,
"[%s] No ble handle to BLE client. State update can not be written.", this->
parent_->
address_str());
108 ESP_LOGD(TAG,
"[%s] Send to display: bignum %d, smallnum: %d, cfg: 0x%02x, validity period: %u.",
109 this->
parent_->
address_str(), this->bignum_, this->smallnum_, this->cfg_, this->validity_period_);
113 blk[2] = (this->
bignum_ >> 8) & 0xff;
123 uint8_t mask = 1 << bit;
127 this->
cfg_ &= (0xFF ^ mask);
137 esp_ble_gattc_write_char(this->
parent_->
get_gattc_if(), this->parent_->get_conn_id(), this->char_handle_,
size,
138 blk, ESP_GATT_WRITE_TYPE_NO_RSP, ESP_GATT_AUTH_REQ_NONE);
163 if (this->
time_ ==
nullptr)
166 ESP_LOGW(TAG,
"[%s] Not connected to BLE client. Time can not be synced.", this->
parent_->
address_str());
170 ESP_LOGW(TAG,
"[%s] No ble handle to BLE client. Time can not be synced.", this->
parent_->
address_str());
174 if (!time.is_valid()) {
175 ESP_LOGW(TAG,
"[%s] Time is not yet valid. Time can not be synced.", this->
parent_->
address_str());
180 ESP_LOGD(TAG,
"[%s] Sync time with timestamp %" PRIu64
".", this->
parent_->
address_str(), time.timestamp);
182 blk[1] = time.timestamp & 0xff;
183 blk[2] = (time.timestamp >> 8) & 0xff;
184 blk[3] = (time.timestamp >> 16) & 0xff;
185 blk[4] = (time.timestamp >> 24) & 0xff;
bool cancel_timeout(const char *name)
Cancel a timeout function.
void set_timeout(const char *name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a const char* name.
void set_enabled(bool enabled)
const char * address_str() const
BLECharacteristic * get_characteristic(espbt::ESPBTUUID service, espbt::ESPBTUUID chr)
bool check_addr(esp_bd_addr_t &addr)
void send_to_setup_char_(uint8_t *blk, size_t size)
ble_device_base::ESPBTUUID char_uuid_
void setcfgbit_(uint8_t bit, bool value)
bool connection_established_
void dump_config() override
void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param) 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
ble_device_base::ESPBTUUID service_uuid_
uint32_t disconnect_delay_ms_
void sync_time_and_display_()
ESPTime now()
Get the time in the currently defined timezone.
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).