M5Unit-WEIGHT 0.1.0 git rev:dab2ce0
Loading...
Searching...
No Matches
unit_MiniScales.hpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
3 *
4 * SPDX-License-Identifier: MIT
5 */
10#ifndef M5_UNIT_WEIGHT_I2C_UNIT_MINISCALES_HPP
11#define M5_UNIT_WEIGHT_I2C_UNIT_MINISCALES_HPP
12
13#include "unit_WeightI2C.hpp"
14
15namespace m5 {
16namespace unit {
17
22class UnitMiniScales : public UnitWeightI2C {
23 M5_UNIT_COMPONENT_HPP_BUILDER(UnitMiniScales, 0x26);
24
25public:
33 };
34
35 explicit UnitMiniScales(const uint8_t addr = DEFAULT_ADDRESS) : UnitWeightI2C(addr)
36 {
37 }
38 virtual ~UnitMiniScales()
39 {
40 }
41
42 virtual void update(const bool force = false) override;
43
46
48 {
49 return this->_cfg;
50 }
52 inline void config(const config_t& cfg)
53 {
54 _cfg = cfg;
56 }
58
61
66 bool readLEDColor(uint32_t& rgb32);
74 bool readLEDColor(uint8_t& r, uint8_t& g, uint8_t& b);
80 inline bool writeLEDColor(const uint32_t rgb32)
81 {
82 return writeLEDColor((rgb32 >> 16) & 0xFF, (rgb32 >> 8) & 0xFF, rgb32 & 0xFF);
83 }
89 bool writeLEDColor(const uint16_t rgb16);
97 bool writeLEDColor(const uint8_t r, const uint8_t g, const uint8_t b);
99
102
107 bool readButtonStatus(bool& press);
113 inline bool isPressed() const
114 {
115 return _button;
116 }
122 inline bool wasPressed() const
123 {
124 return _button && (_button != _prev_button);
125 }
131 inline bool wasReleased()
132 {
133 return !_button && (_button != _prev_button);
134 }
136
137private:
138 bool _button{}, _prev_button{};
139 config_t _cfg{};
140};
141
142namespace miniscales {
143namespace command {
145// clang-format off
146constexpr uint8_t BUTTON_REG {0x20};
147constexpr uint8_t RGB_LED_REG {0x30};
148// clang-format on
150
151} // namespace command
152} // namespace miniscales
153
154} // namespace unit
155} // namespace m5
156
157#endif
MiniScales unit.
bool readButtonStatus(bool &press)
Read the button status.
Definition unit_MiniScales.cpp:85
bool readLEDColor(uint32_t &rgb32)
Read the LED color as RGB32 (00RRGGBB HEX)
Definition unit_MiniScales.cpp:34
bool isPressed() const
Is button pressed?
Definition unit_MiniScales.hpp:113
void config(const config_t &cfg)
Set the configration.
Definition unit_MiniScales.hpp:52
config_t config()
Gets the configration.
Definition unit_MiniScales.hpp:47
bool wasPressed() const
Was button pressed?
Definition unit_MiniScales.hpp:122
bool writeLEDColor(const uint32_t rgb32)
Write the LED color as RGB32 (00RRGGBB HEX)
Definition unit_MiniScales.hpp:80
bool wasReleased()
Is button released?
Definition unit_MiniScales.hpp:131
WeightI2C unit.
Definition unit_WeightI2C.hpp:56
config_t config()
Gets the configration.
Definition unit_WeightI2C.hpp:96
Top level namespace of M5stack.
Unit-related namespace.
Settings for begin.
Definition unit_MiniScales.hpp:30
bool manage_button_status
Manage button status with update?
Definition unit_MiniScales.hpp:32
Settings for begin.
Definition unit_WeightI2C.hpp:64
WeightI2C Unit for M5UnitUnified.