ESPHome  2024.11.0
pvvx_display.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "esphome/core/defines.h"
6 
7 #include <cinttypes>
8 
9 #ifdef USE_ESP32
10 #include <esp_gattc_api.h>
11 #ifdef USE_TIME
13 #endif
14 
15 namespace esphome {
16 namespace pvvx_mithermometer {
17 
18 class PVVXDisplay;
19 
21 enum UNIT {
22  UNIT_NONE = 0,
30 };
31 
32 using pvvx_writer_t = std::function<void(PVVXDisplay &)>;
33 
35  public:
36  void set_writer(pvvx_writer_t &&writer) { this->writer_ = writer; }
37  void set_auto_clear(bool auto_clear_enabled) { this->auto_clear_enabled_ = auto_clear_enabled; }
38  void set_disconnect_delay(uint32_t ms) { this->disconnect_delay_ms_ = ms; }
39 
40  void dump_config() override;
41 
42  float get_setup_priority() const override { return setup_priority::DATA; }
43 
44  void update() override;
45 
46  void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if,
47  esp_ble_gattc_cb_param_t *param) override;
48 
50  void set_validity_period(uint16_t validity_period) { this->validity_period_ = validity_period; }
52  void clear() {
53  this->bignum_ = 0;
54  this->smallnum_ = 0;
55  this->cfg_ = 0;
56  }
63  void print_bignum(float bignum) { this->bignum_ = bignum * 10; }
69  void print_smallnum(float smallnum) { this->smallnum_ = smallnum; }
88  void print_happy(bool happy = true) { this->setcfgbit_(0, happy); }
90  void print_sad(bool sad = true) { this->setcfgbit_(1, sad); }
92  void print_bracket(bool bracket = true) { this->setcfgbit_(2, bracket); }
94  void print_percent(bool percent = true) { this->setcfgbit_(3, percent); }
96  void print_battery(bool battery = true) { this->setcfgbit_(4, battery); }
98  void print_unit(UNIT unit) { this->cfg_ = (this->cfg_ & 0x1F) | ((unit & 0x7) << 5); }
99 
100  void display();
101 
102 #ifdef USE_TIME
103  void set_time(time::RealTimeClock *time) { this->time_ = time; };
104 #endif
105 
106  protected:
108  uint32_t disconnect_delay_ms_ = 5000;
109  uint16_t validity_period_ = 300;
110  uint16_t bignum_ = 0;
111  uint16_t smallnum_ = 0;
112  uint8_t cfg_ = 0;
113 
114  void setcfgbit_(uint8_t bit, bool value);
115  void send_to_setup_char_(uint8_t *blk, size_t size);
116  void delayed_disconnect_();
117 #ifdef USE_TIME
118  void sync_time_();
120 #endif
121  uint16_t char_handle_ = 0;
123 
125  esp32_ble_tracker::ESPBTUUID::from_raw("00001f10-0000-1000-8000-00805f9b34fb");
127  esp32_ble_tracker::ESPBTUUID::from_raw("00001f1f-0000-1000-8000-00805f9b34fb");
128 
130 };
131 
132 } // namespace pvvx_mithermometer
133 } // namespace esphome
134 
135 #endif
const float DATA
For components that import data from directly connected sensors like DHT.
Definition: component.cpp:19
void set_writer(pvvx_writer_t &&writer)
Definition: pvvx_display.h:36
float get_setup_priority() const override
Definition: pvvx_display.h:42
optional< pvvx_writer_t > writer_
Definition: pvvx_display.h:129
The RealTimeClock class exposes common timekeeping functions via the device&#39;s local real-time clock...
void print_battery(bool battery=true)
Print battery sign.
Definition: pvvx_display.h:96
void set_auto_clear(bool auto_clear_enabled)
Definition: pvvx_display.h:37
void setcfgbit_(uint8_t bit, bool value)
void print_bignum(float bignum)
Print the big number.
Definition: pvvx_display.h:63
This class simplifies creating components that periodically check a state.
Definition: component.h:283
void print_smallnum(float smallnum)
Print the small number.
Definition: pvvx_display.h:69
void print_unit(UNIT unit)
Print unit of big number.
Definition: pvvx_display.h:98
void set_validity_period(uint16_t validity_period)
Set validity period of the display information in seconds (1..65535)
Definition: pvvx_display.h:50
void print_sad(bool sad=true)
Print a sad face.
Definition: pvvx_display.h:90
void send_to_setup_char_(uint8_t *blk, size_t size)
esp32_ble_tracker::ESPBTUUID char_uuid_
Definition: pvvx_display.h:126
void print_percent(bool percent=true)
Print percent sign at small number.
Definition: pvvx_display.h:94
esp32_ble_tracker::ESPBTUUID service_uuid_
Definition: pvvx_display.h:124
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void print_happy(bool happy=true)
Print a happy face.
Definition: pvvx_display.h:88
void set_time(time::RealTimeClock *time)
Definition: pvvx_display.h:103
static ESPBTUUID from_raw(const uint8_t *data)
Definition: ble_uuid.cpp:28
void print_bracket(bool bracket=true)
Print round brackets around the face.
Definition: pvvx_display.h:92
std::function< void(PVVXDisplay &)> pvvx_writer_t
Definition: pvvx_display.h:32
void gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param) override
UNIT
Possible units for the big number.
Definition: pvvx_display.h:21