M5Unit-WEIGHT 0.1.1 git rev:97a7989
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
46 virtual void update(const bool force = false) override;
47
50
52 {
53 return _cfg_mini;
54 }
56 inline void config(const config_t& cfg)
57 {
58 _cfg_mini = cfg;
59 UnitWeightI2C::config(static_cast<UnitWeightI2C::config_t>(_cfg_mini));
60 }
62
65
70 bool readLEDColor(uint32_t& rgb32);
78 bool readLEDColor(uint8_t& r, uint8_t& g, uint8_t& b);
84 inline bool writeLEDColor(const uint32_t rgb32)
85 {
86 return writeLEDColor((rgb32 >> 16) & 0xFF, (rgb32 >> 8) & 0xFF, rgb32 & 0xFF);
87 }
93 bool writeLEDColor(const uint16_t rgb16);
101 bool writeLEDColor(const uint8_t r, const uint8_t g, const uint8_t b);
103
106
111 bool readButtonStatus(bool& press);
117 inline bool isPressed() const
118 {
119 return _button;
120 }
126 inline bool wasPressed() const
127 {
128 return _button && (_button != _prev_button);
129 }
135 inline bool wasReleased() const
136 {
137 return !_button && (_button != _prev_button);
138 }
140
141private:
142 bool _button{}, _prev_button{};
143 config_t _cfg_mini{};
144};
145
146namespace miniscales {
147namespace command {
149// clang-format off
150constexpr uint8_t BUTTON_REG {0x20};
151constexpr uint8_t RGB_LED_REG {0x30};
152// clang-format on
154
155} // namespace command
156} // namespace miniscales
157
158} // namespace unit
159} // namespace m5
160
161#endif
MiniScales unit.
bool readButtonStatus(bool &press)
Read the button status.
Definition unit_MiniScales.cpp:78
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:117
void config(const config_t &cfg)
Set the configuration.
Definition unit_MiniScales.hpp:56
config_t config()
Gets the configuration.
Definition unit_MiniScales.hpp:51
virtual void update(const bool force=false) override
Update the cached measurement and button state.
Definition unit_MiniScales.cpp:25
bool wasPressed() const
Was button pressed?
Definition unit_MiniScales.hpp:126
bool writeLEDColor(const uint32_t rgb32)
Write the LED color as RGB32 (00RRGGBB HEX)
Definition unit_MiniScales.hpp:84
bool wasReleased() const
Is button released?
Definition unit_MiniScales.hpp:135
WeightI2C unit.
Definition unit_WeightI2C.hpp:72
config_t config()
Gets the configuration.
Definition unit_WeightI2C.hpp:120
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:80
WeightI2C Unit for M5UnitUnified.