Skip to content

Commit f09d67b

Browse files
committed
Merge branch 'develop'
2 parents cab9f4e + 1b04cb7 commit f09d67b

File tree

9 files changed

+123
-29
lines changed

9 files changed

+123
-29
lines changed

doc/doxy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
## Get git rev of HEAD
77
LIB_VERSION="$(pcregrep -o1 "^\s*version\s*=\s*(\*|\d+(\.\d+){0,3}(\.\*)?)" library.properties)"
88
#echo ${DOXYGEN_PROJECT_NUMBER}
9-
DOXYGEN_PROJECT_NUMBER="${LIB_VERSION} git rev:$(git rev-parse HEAD)" doxygen doc/Doxyfile
9+
DOXYGEN_PROJECT_NUMBER="${LIB_VERSION} git rev:$(git rev-parse --short HEAD)" doxygen doc/Doxyfile
1010

1111

examples/rotation/rotation.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#include <gob_unifiedButton.hpp>
2+
// setup/main in rotation_main.cpp
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
gob_unifiedButton example
3+
rotation for CoreS3
4+
*/
5+
#include <M5Unified.h>
6+
#include <gob_unifiedButton.hpp>
7+
8+
goblib::UnifiedButton unifiedButton; // gob_unifiedButton instance
9+
auto& display = M5.Display;
10+
11+
void setup()
12+
{
13+
M5.begin();
14+
unifiedButton.begin(&display);
15+
display.clear(TFT_DARKGREEN);
16+
unifiedButton.getButtonA()->setLabelText("ROTATE");
17+
}
18+
19+
void loop()
20+
{
21+
bool force{};
22+
static uint_fast8_t rot{display.getRotation()};
23+
24+
M5.update();
25+
unifiedButton.update();
26+
27+
// Change rotation
28+
if(M5.BtnA.wasClicked())
29+
{
30+
rot = (rot + 1) & 0x07;
31+
M5_LOGI("setRotation:%u", rot);
32+
33+
display.clear(TFT_DARKGREEN);
34+
35+
display.setRotation(rot);
36+
unifiedButton.setRotation(display.getRotation()); // Do not use a value different from the target!
37+
// If you have already customized the buttons, you will need to do it again.
38+
unifiedButton.getButtonA()->setLabelText("ROTATE");
39+
40+
force = true;
41+
}
42+
43+
display.setCursor(16, 32);
44+
display.printf("R:%u W:%d H:%d\n", display.getRotation(), display.width(), display.height());
45+
display.printf("Click A to rotate random");
46+
unifiedButton.draw(force);
47+
}

library.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
"type": "git",
1212
"url": "https://github.com/GOB52/gob_unifiedButton.git"
1313
},
14-
"version": "0.1.2",
14+
"version": "0.1.3",
1515
"headers": "gob_unifiedButton.hpp",
1616
"license": "MIT",
1717
"platforms": "espressif32",
1818
"frameworks": "arduino",
1919
"dependencies": {
2020
"m5stack/M5Unified": "^0.1.13"
2121
}
22-
}
22+
}

library.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name=gob_unifiedButton
2-
version=0.1.2
2+
version=0.1.3
33
author=GOB
44
maintainer=GOB
55
sentence=Add touch buttons for CoreS3 and commonality with conventional buttons (M5.BtnX)
6-
paragraph=
6+
paragraph=M5Stack CoreS3
77
category=Other
88
url=https://github.com/GOB52/gob_unifiedButton.git
99
architectures=esp32,esp32s3

platformio.ini

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,11 @@ board_build.arduino.memory_type = qio_qspi
6464
build_type=release
6565
build_flags=${env.build_flags} ${option_release.build_flags}
6666
build_src_filter = +<*> -<.git/> -<.svn/> +<../examples/customButton/>
67+
68+
; rotate screen example (only CoreS3)
69+
[env:rotation_CoreS3]
70+
board = esp32s3box
71+
board_build.arduino.memory_type = qio_qspi
72+
build_type=release
73+
build_flags=${env.build_flags} ${option_release.build_flags}
74+
build_src_filter = +<*> -<.git/> -<.svn/> +<../examples/rotation/>

src/gob_unifiedButton.cpp

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,30 @@
66
#include <M5Unified.h>
77
#include "gob_unifiedButton.hpp"
88

9+
namespace
10+
{
11+
constexpr char labelA[] = "BtnA";
12+
constexpr char labelB[] = "BtnB";
13+
constexpr char labelC[] = "BtnC";
14+
constexpr const char* label_table[] = { labelA, labelB, labelC };
15+
constexpr int32_t olClr = lgfx::color565(64,64,64);
16+
}
917
namespace goblib
1018
{
1119
// class UnifiedButton
1220
void UnifiedButton::begin(LovyanGFX* gfx, const appearance_t app)
1321
{
14-
_board = M5.getBoard();
1522
assert(gfx);
1623
_gfx = gfx;
1724
_appearance = app;
1825
_dirty = true;
1926
_font = gfx->getFont();
20-
createButtons(_appearance);
27+
_enable = M5.getBoard() == m5::board_t::board_M5StackCoreS3 && M5.Touch.isEnabled();
28+
_rotation = _gfx->getRotation();
29+
if(_enable) { create_buttons(_appearance); }
2130
}
2231

23-
void UnifiedButton::createButtons(const appearance_t app)
32+
void UnifiedButton::create_buttons(const appearance_t app)
2433
{
2534
int32_t w{_gfx->width() / 3};
2635
int32_t h{32};
@@ -41,19 +50,21 @@ void UnifiedButton::createButtons(const appearance_t app)
4150
top = h/2;
4251
break;
4352
}
53+
for(uint_fast8_t i = 0; i < 3; ++i)
54+
{
55+
_btns[i].initButton(_gfx, left + w * i + w / 2, top, w, h, olClr, TFT_DARKGRAY, TFT_BLACK,label_table[i]);
56+
}
57+
}
4458

45-
constexpr int32_t olClr = lgfx::color565(64,64,64);
46-
47-
_btns[0].initButton(_gfx, left + w * 0 + w / 2, top, w, h, olClr, TFT_DARKGRAY, TFT_BLACK, "BtnA");
48-
_btns[1].initButton(_gfx, left + w * 1 + w / 2, top, w, h, olClr, TFT_DARKGRAY, TFT_BLACK, "BtnB");
49-
_btns[2].initButton(_gfx, left + w * 2 + w / 2, top, w, h, olClr, TFT_DARKGRAY, TFT_BLACK, "BtnC");
50-
51-
//M5_LOGI("[gob] change appearance_t:%02xH", app);
59+
void UnifiedButton::setRotation(const uint_fast8_t rot)
60+
{
61+
_rotation = rot & 0x07; // Valid values are [0...7]
62+
create_buttons(_appearance);
5263
}
5364

5465
void UnifiedButton::update()
5566
{
56-
if(_board != m5::board_t::board_M5StackCoreS3) { return; }
67+
if(!_enable) { return; }
5768

5869
// Processes buttons in the same way as they are processed in Core2
5970
auto ms = m5gfx::millis();
@@ -72,15 +83,31 @@ void UnifiedButton::update()
7283
if (M5.BtnC.isPressed()) { btn_bits |= 1 << 2; }
7384
if (btn_bits || !(det.state & m5::touch_state_t::mask_moving))
7485
{
86+
// Correct coordinates to match rotation.
87+
auto x = raw.x;
88+
auto y = raw.y;
89+
const uint32_t rot = _gfx->getRotation();
90+
const auto wid = _gfx->width();
91+
const auto hgt = _gfx->height();
92+
93+
if(!(rot & 1)) { std::swap(x, y); }
94+
const auto rot4 = rot ^ ((((rot >> 2) ^ 1) - 1) & 0x07); // 0-3 => 0-3, 4-7 => 3-0
95+
switch(rot4)
96+
{
97+
case 0: x = wid - x - 1; break;
98+
case 2: y = hgt - y - 1; break;
99+
case 3: x = wid - x - 1; y = hgt - y - 1; break;
100+
default: break;
101+
}
102+
75103
for(int i=0; i<3; ++i)
76104
{
77-
btn_bits |= (_btns[i].contains(raw.x, raw.y) << i);
105+
btn_bits |= (_btns[i].contains(x, y) << i);
78106
}
79107
_press_bits = btn_bits;
80108
}
81109
}
82110
}
83-
84111
// Set status to M5.BtnX
85112
M5.BtnA.setRawState(ms, btn_bits & 1);
86113
M5.BtnB.setRawState(ms, btn_bits & 2);
@@ -91,15 +118,13 @@ void UnifiedButton::update()
91118

92119
void UnifiedButton::draw(const bool force)
93120
{
94-
if(_board != m5::board_t::board_M5StackCoreS3) { return; }
95-
96-
if(!(_appearance & appearance_t::transparent_bottom) && _show && (_dirty || force))
121+
if(_enable && !(_appearance & appearance_t::transparent_bottom) && _show && (_dirty || force))
97122
{
98123
auto gfont = _gfx->getFont();
99124
_gfx->setFont(_font);
100125

101126
_dirty = false;
102-
for(int i=0; i<3; ++i)
127+
for(int i=0; i < 3; ++i)
103128
{
104129
_btns[i].drawButton(_press_bits & (1<<i));
105130
}

src/gob_unifiedButton.hpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
@mainpage gob_unifiedButton
66
Add touch buttons for CoreS3 and commonality with conventional buttons (M5.BtnX)
77
8-
@author GOB / GitHub:<a href="https://github.com/GOB52/">GOB52</a> / Twitter:<a href="https://twitter.com/gob_52_gob">@GOB_52_GOB</a>
8+
@author GOB / GitHub:<a href="https://github.com/GOB52/">GOB52</a> / X:<a href="https://twitter.com/gob_52_gob">@GOB_52_GOB</a>
99
1010
@copyright 2023 GOB
1111
@copyright Licensed under the MIT license. See LICENSE file in the project root for full license information.
@@ -45,8 +45,13 @@ class UnifiedButton
4545

4646
UnifiedButton() {}
4747

48+
///@cond
49+
UnifiedButton(const UnifiedButton&) = delete;
50+
UnifiedButton& operator=(const UnifiedButton&) = delete;
51+
///@endcond
52+
4853
/*!
49-
@brief Initialize
54+
@brief Begin the unified button
5055
@param gfx Target for drawing
5156
@param app Button appearance
5257
*/
@@ -90,10 +95,17 @@ class UnifiedButton
9095
{
9196
_dirty = true;
9297
_appearance = app;
93-
createButtons(_appearance);
98+
create_buttons(_appearance);
9499
}
95100
}
96101

102+
/*!
103+
@brief Change rotation
104+
@param rot Rotation code same as M5GFX [0...7]
105+
@warning If you have already customized the buttons, you will need to do it again.
106+
*/
107+
void setRotation(const uint_fast8_t rot);
108+
97109
///@name Gets the LGFX_Button
98110
///@{
99111
LGFX_Button* getButtonA() { return &_btns[0]; } //!< @brief Gets the button A
@@ -111,15 +123,15 @@ class UnifiedButton
111123
/// @endcond
112124

113125
private:
114-
void createButtons(const appearance_t app);
126+
void create_buttons(const appearance_t app);
115127

116128
LGFX_Button _btns[3]; // 0:A, 1:B, 2:C
117129
LovyanGFX* _gfx{};
118130
uint_fast8_t _press_bits{};
119-
bool _dirty{}, _show{true};;
131+
bool _enable{}, _dirty{}, _show{true};
120132
appearance_t _appearance{appearance_t::bottom};
121-
m5::board_t _board{m5::board_t::board_unknown};
122133
const lgfx::IFont* _font{};
134+
uint_fast8_t _rotation{(uint_fast8_t)-1}; // Same as M5GFX
123135
};
124136
//
125137
}

src/gob_unifiedButton_version.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#define GOBLIB_UNIFIED_BUTTON_VERSION_MAJOR 0
55
#define GOBLIB_UNIFIED_BUTTON_VERSION_MINOR 1
6-
#define GOBLIB_UNIFIED_BUTTON_VERSION_PATCH 2
6+
#define GOBLIB_UNIFIED_BUTTON_VERSION_PATCH 3
77

88
#define GOBLIB_UNIFIED_BUTTON_VERSION_STRINGIFY_AGAIN(x) #x
99
#define GOBLIB_UNIFIED_BUTTON_VERSION_STRINGIFY(x) GOBLIB_UNIFIED_BUTTON_VERSION_STRINGIFY_AGAIN(x)

0 commit comments

Comments
 (0)