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: {
64 case ESP_GAP_BLE_AUTH_CMPL_EVT: {
68 if (param->ble_security.auth_cmpl.success) {
69 ESP_LOGD(TAG,
"[%s] Authentication successful, performing writes.", this->
parent_->
address_str().c_str());
92 ESP_LOGD(TAG,
"[%s] BLE client not enabled. Init connection.", this->
parent_->
address_str().c_str());
97 ESP_LOGW(TAG,
"[%s] Not connected to BLE client. State update can not be written.",
102 ESP_LOGW(TAG,
"[%s] No ble handle to BLE client. State update can not be written.",
106 ESP_LOGD(TAG,
"[%s] Send to display: bignum %d, smallnum: %d, cfg: 0x%02x, validity period: %u.",
107 this->
parent_->
address_str().c_str(), this->bignum_, this->smallnum_, this->cfg_, this->validity_period_);
111 blk[2] = (this->
bignum_ >> 8) & 0xff;
121 uint8_t mask = 1 << bit;
125 this->
cfg_ &= (0xFF ^ mask);
131 ESP_LOGW(TAG,
"[%s] Not connected to BLE client.", this->
parent_->
address_str().c_str());
135 esp_ble_gattc_write_char(this->
parent_->
get_gattc_if(), this->parent_->get_conn_id(), this->char_handle_, size,
136 blk, ESP_GATT_WRITE_TYPE_NO_RSP, ESP_GATT_AUTH_REQ_NONE);
161 if (this->
time_ ==
nullptr)
164 ESP_LOGW(TAG,
"[%s] Not connected to BLE client. Time can not be synced.", this->
parent_->
address_str().c_str());
168 ESP_LOGW(TAG,
"[%s] No ble handle to BLE client. Time can not be synced.", this->
parent_->
address_str().c_str());
172 if (!time.is_valid()) {
173 ESP_LOGW(TAG,
"[%s] Time is not yet valid. Time can not be synced.", this->
parent_->
address_str().c_str());
178 ESP_LOGD(TAG,
"[%s] Sync time with timestamp %" PRIu64
".", this->
parent_->
address_str().c_str(), time.timestamp);
180 blk[1] = time.timestamp & 0xff;
181 blk[2] = (time.timestamp >> 8) & 0xff;
182 blk[3] = (time.timestamp >> 16) & 0xff;
183 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)
const std::string & 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)
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
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
uint32_t disconnect_delay_ms_
void sync_time_and_display_()
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).