Skip to content

Commit 3a747bf

Browse files
committed
ajout de hardware
1 parent 6593865 commit 3a747bf

File tree

6 files changed

+55
-12
lines changed

6 files changed

+55
-12
lines changed

lib/graphics/src/graphics.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ void graphics::SDLInit(void (*appMain)())
123123
// You should only use this function with a "Canvas" (Surface that is the size of the screen)
124124
void graphics::showSurface(const Surface* surface, int x, int y)
125125
{
126-
if (x != 0 || y != 0)
126+
/*if (x != 0 || y != 0)
127127
{
128128
std::cerr << "---------------------------------------------------------------------------------------------------------------------" << std::endl;
129129
std::cerr << " Warning ! " << std::endl;
@@ -133,7 +133,7 @@ void graphics::showSurface(const Surface* surface, int x, int y)
133133
std::cerr << ">>> Please push to a 'graphics::Surface' before pushing to the screen. <<<" << std::endl;
134134
std::cerr << ">>> By using a 'graphics::Surface' before pusing to the screen, you are also enabling double buffering rendering. <<<" << std::endl;
135135
std::cerr << "---------------------------------------------------------------------------------------------------------------------" << std::endl;
136-
}
136+
}*/
137137

138138
lgfx::LGFX_Sprite sprite = surface->m_sprite; // we are friends !
139139

@@ -151,9 +151,9 @@ void graphics::getTouchPos(int16_t* x, int16_t* y)
151151
int16_t ty;
152152

153153
lcd->getTouch(&tx, &ty);
154-
ty = ty * 480 / 700;
155-
156-
std::cout << tx << " " << ty << std::endl;
154+
#ifdef ESP_PLATFORM // with capacitive touch?
155+
ty = ty * 480 / 700;
156+
#endif
157157

158158
if (tx <= 0 || ty <= 0 || tx > graphics::getScreenWidth() || ty > graphics::getScreenHeight())
159159
{

lib/gui/src/ElementBase.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ bool gui::ElementBase::update()
133133
// check if the finger is currently on the widget
134134
if (touchX != -1 && touchY != -1)
135135
{
136-
if (getAbsoluteX() < touchX && touchX < getAbsoluteX() + getWidth() && // l'objet est touché
137-
getAbsoluteY() < touchY && touchY < getAbsoluteY() + getHeight())
136+
if (getAbsoluteX()-10 < touchX && touchX < getAbsoluteX() + getWidth() +10 && // l'objet est touché
137+
getAbsoluteY()-10 < touchY && touchY < getAbsoluteY() + getHeight() +10)
138138
{
139139
if (m_widgetPressed == nullptr && m_pressedState == PressedState::NOT_PRESSED) // l'objet est touché pour la première fois
140140
{
@@ -165,6 +165,12 @@ bool gui::ElementBase::update()
165165
return true;
166166
}
167167
}
168+
else
169+
{
170+
originTouchX = -1;
171+
originTouchY = -1;
172+
}
173+
168174
if (touchX == -1 && touchY == -1 && m_widgetPressed == this && m_pressedState != PressedState::RELEASED)
169175
{
170176
if (m_pressedState == PressedState::PRESSED)

lib/hardware/gpio.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#define PIN_SD_CS 4
22
#define PIN_HOME_BUTTON -1
3+
#define PIN_SCREEN_POWER 14
34
/* ... */

lib/hardware/hardware.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include "hardware.hpp"
2+
#include "gpio.hpp"
3+
4+
#ifdef ESP_PLATFORM
5+
#include <Arduino.h>
6+
#endif
7+
8+
void hardware::init()
9+
{
10+
#ifdef ESP_PLATFORM
11+
12+
psramInit();
13+
pinMode(PIN_SCREEN_POWER, OUTPUT);
14+
15+
#endif
16+
}
17+
18+
void hardware::setScreenPower(bool power)
19+
{
20+
#ifdef ESP_PLATFORM
21+
22+
digitalWrite(PIN_SCREEN_POWER, power);
23+
24+
#endif
25+
}

lib/hardware/hardware.hpp

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#ifndef HARDWARE_HPP
2+
#define HARDWARE_HPP
3+
4+
namespace hardware
5+
{
6+
void init();
7+
8+
void setScreenPower(bool power);
9+
};
10+
11+
#endif

src/main.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#endif
99

1010
#include "graphics.hpp"
11+
#include "hardware.hpp"
1112
#include "gui.hpp"
1213
#include "path.hpp"
1314
#include "filestream.hpp"
@@ -19,10 +20,9 @@ void loop(){}
1920

2021
void setup()
2122
{
22-
psramInit();
23-
pinMode(14, OUTPUT);
24-
digitalWrite(14, 1);
25-
23+
hardware::init();
24+
hardware::setScreenPower(true);
25+
2626
graphics::init();
2727

2828
Window win;
@@ -85,7 +85,7 @@ void setup()
8585
// Native main
8686
int main(int argc, char **argv)
8787
{
88-
graphics::SDLInit(app_main);
88+
graphics::SDLInit(setup);
8989
}
9090

9191
#endif

0 commit comments

Comments
 (0)