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