Skip to content

Commit 6c4c0dd

Browse files
authored
Merge pull request #19 from paxo-phone/gabriel_dev
Gabriel dev
2 parents 138e133 + 3a747bf commit 6c4c0dd

19 files changed

+4550
-782
lines changed

lib/graphics/src/Image.cpp

+11-2
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,22 @@ uint64_t getFileSize(const char *filename)
1515
{
1616
auto inputStream = std::ifstream(filename, std::ios::ate | std::ios::binary);
1717

18+
if(!inputStream)
19+
return 0;
1820
return inputStream.tellg();
1921
}
20-
22+
#include <iostream>
2123
// TODO: Replace this with "storage"
2224
// TODO : Use "Path"
2325
std::shared_ptr<uint8_t[]> getFileData(const char *filename)
2426
{
2527
const size_t filesize = getFileSize(filename);
2628

29+
std::cout << "File size: " << filesize << std::endl;
30+
31+
if(filesize == 0)
32+
return std::shared_ptr<uint8_t[]>();
33+
2734
auto data = std::shared_ptr<uint8_t[]>(new uint8_t[filesize]);
2835

2936
auto inputStream = std::ifstream(filename, std::ios::binary);
@@ -44,7 +51,9 @@ namespace graphics {
4451
const size_t fileSize = getFileSize(filename.c_str());
4552

4653
m_size = fileSize;
47-
m_data = getFileData(filename.c_str());;
54+
if(fileSize == 0)
55+
return;
56+
m_data = getFileData(filename.c_str());
4857

4958
const imgdec::IMGData imageData = imgdec::decodeHeader(m_data.get());
5059

lib/graphics/src/Surface.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
#include "fonts/Arial-24.h"
1515
#include "fonts/Arial-8.h"
1616

17+
#include "fonts/ArialBold-12.h"
18+
#include "fonts/ArialBold-16.h"
19+
#include "fonts/ArialBold-24.h"
20+
#include "fonts/ArialBold-8.h"
21+
1722
#include "Encoder/decodeutf8.hpp"
1823

1924
namespace graphics
@@ -28,6 +33,8 @@ namespace graphics
2833
m_sprite.setPsram(true);
2934

3035
m_sprite.createSprite(width, height);
36+
if(m_sprite.getBuffer() == nullptr)
37+
std::cout << "ERROR" << std::endl;
3138
}
3239

3340
Surface::~Surface()
@@ -202,9 +209,9 @@ namespace graphics
202209
if (font == ARIAL)
203210
{
204211
if (fontSize == PT_8)
205-
return &Arial8ptFR;
212+
return &ArialBold8ptFR;
206213
if (fontSize == PT_12)
207-
return &Arial12ptFR;
214+
return &ArialBold12ptFR;
208215
if (fontSize == PT_16)
209216
return &Arial16ptFR;
210217
if (fontSize == PT_24)

lib/graphics/src/fonts/ArialBold-12.h

+427
Large diffs are not rendered by default.

lib/graphics/src/fonts/ArialBold-16.h

+605
Large diffs are not rendered by default.

lib/graphics/src/fonts/ArialBold-24.h

+1,241
Large diffs are not rendered by default.

lib/graphics/src/fonts/ArialBold-8.h

+277
Large diffs are not rendered by default.

lib/graphics/src/graphics.cpp

+10-9
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,17 @@ void graphics::init()
4343
#endif
4444

4545
lcd->init();
46-
lcd->setBrightness(0xFF);
46+
lcd->setBrightness(0xFF/3);
4747
lcd->setColorDepth(16);
4848
lcd->setTextColor(TFT_WHITE);
49-
lcd->fillScreen(TFT_BLACK);
50-
51-
lcd->startWrite(); // Keep the SPI Bus busy ?
49+
lcd->fillScreen(TFT_RED);
5250

5351
#ifdef ESP_PLATFORM
5452
// uint16_t calibrationData[8];
5553
// lcd->calibrateTouch(calibrationData, TFT_MAGENTA, TFT_BLACK);
5654

5755
// Please do a real calibration thing... (see above)
58-
uint16_t calibrationData[] = {
56+
/*uint16_t calibrationData[] = {
5957
390,
6058
170,
6159
350,
@@ -66,7 +64,7 @@ void graphics::init()
6664
3950
6765
};
6866
69-
lcd->setTouchCalibrate(calibrationData);
67+
lcd->setTouchCalibrate(calibrationData);*/
7068
#endif
7169
}
7270

@@ -125,7 +123,7 @@ void graphics::SDLInit(void (*appMain)())
125123
// You should only use this function with a "Canvas" (Surface that is the size of the screen)
126124
void graphics::showSurface(const Surface* surface, int x, int y)
127125
{
128-
if (x != 0 || y != 0)
126+
/*if (x != 0 || y != 0)
129127
{
130128
std::cerr << "---------------------------------------------------------------------------------------------------------------------" << std::endl;
131129
std::cerr << " Warning ! " << std::endl;
@@ -135,7 +133,7 @@ void graphics::showSurface(const Surface* surface, int x, int y)
135133
std::cerr << ">>> Please push to a 'graphics::Surface' before pushing to the screen. <<<" << std::endl;
136134
std::cerr << ">>> By using a 'graphics::Surface' before pusing to the screen, you are also enabling double buffering rendering. <<<" << std::endl;
137135
std::cerr << "---------------------------------------------------------------------------------------------------------------------" << std::endl;
138-
}
136+
}*/
139137

140138
lgfx::LGFX_Sprite sprite = surface->m_sprite; // we are friends !
141139

@@ -153,8 +151,11 @@ void graphics::getTouchPos(int16_t* x, int16_t* y)
153151
int16_t ty;
154152

155153
lcd->getTouch(&tx, &ty);
154+
#ifdef ESP_PLATFORM // with capacitive touch?
155+
ty = ty * 480 / 700;
156+
#endif
156157

157-
if (tx < 0 || ty < 0 || tx > graphics::getScreenWidth() || ty > graphics::getScreenHeight())
158+
if (tx <= 0 || ty <= 0 || tx > graphics::getScreenWidth() || ty > graphics::getScreenHeight())
158159
{
159160
// Be sure to be offscreen
160161
*x = -1;

lib/graphics/src/platforms/LGFX_ESP32_PAXO5.hpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#include <LovyanGFX.hpp>
66

7-
#define USE_TOUCH_RESISTIVE
7+
#define USE_TOUCH_CAPACITIVE
88

99
class LGFX : public lgfx::LGFX_Device
1010
{
@@ -30,8 +30,6 @@ class LGFX : public lgfx::LGFX_Device
3030
cfg.freq_read = 16000000;
3131
cfg.spi_3wire = true; // changed
3232
cfg.use_lock = true;
33-
cfg.dma_channel = 1;
34-
3533
cfg.pin_sclk = 18;
3634
cfg.pin_mosi = 23;
3735
cfg.pin_dc = 2;
@@ -55,7 +53,7 @@ class LGFX : public lgfx::LGFX_Device
5553
cfg.offset_rotation = 0;
5654
cfg.dummy_read_pixel = 8;
5755
cfg.dummy_read_bits = 0;//1
58-
cfg.readable = false;
56+
cfg.readable = true;
5957
cfg.invert = false;
6058
cfg.rgb_order = false;
6159
cfg.dlen_16bit = false;

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/gui/src/elements/Button.cpp

+23-8
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ namespace gui::elements
1818
this->m_backgroundColor = COLOR_WHITE;
1919
this->m_borderRadius = 17;
2020

21-
m_theme = BUTTON_BLACK;
21+
m_theme = BUTTON_WHITE;
22+
23+
this->m_label = nullptr;
24+
this->m_image = nullptr;
2225
}
2326

2427
Button::~Button() = default;
@@ -44,11 +47,13 @@ namespace gui::elements
4447

4548
if(m_image != nullptr)
4649
m_image->setX(getWidth()/2 - w/2);
50+
4751
if(m_label != nullptr)
4852
{
49-
m_label->setX(getWidth()/2 - w/2 + space + ((m_image != nullptr) ? (m_image->getX() + m_image->getWidth()) : 0));
53+
m_label->setX(space + ((m_image != nullptr) ? (m_image->getX() + m_image->getWidth()) : getWidth()/2 - w/2));
5054
m_label->setY(10);
5155
m_label->setWidth(m_label->getTextWidth());
56+
m_label->setHeight(18);
5257
m_label->setFontSize(LABEL_SMALL);
5358

5459
if(m_theme)
@@ -76,16 +81,26 @@ namespace gui::elements
7681
}
7782
}
7883

79-
void Button::setLabel(Label* label)
84+
void Button::setText(std::string text)
8085
{
81-
this->m_label = label;
82-
addChild(m_label);
86+
if(m_label == nullptr)
87+
{
88+
m_label = new Label(0, 0, 0, 0);
89+
addChild(m_label);
90+
}
91+
this->m_label->setText(text);
92+
format();
8393
}
8494

85-
void Button::setImage(Image* image)
95+
void Button::setIcon(storage::Path path)
8696
{
87-
this->m_image = image;
88-
addChild(m_image);
97+
if(m_image == nullptr)
98+
{
99+
m_image = new Image(path, 0, 10, 20, 20);
100+
m_image->load();
101+
addChild(m_image);
102+
format();
103+
}
89104
}
90105

91106
void Button::setTheme(bool value)

lib/gui/src/elements/Button.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define BUTTON_HPP
33

44
#include "../ElementBase.hpp"
5+
#include <filestream.hpp>
56

67
#include "Label.hpp"
78
#include "Image.hpp"
@@ -20,8 +21,8 @@ namespace gui::elements
2021
void format(); // recalculer les coordonées et tailles des sous widgets
2122
void render() override;
2223

23-
void setLabel(Label* label);
24-
void setImage(Image* image);
24+
void setText(std::string text);
25+
void setIcon(storage::Path path);
2526

2627
void setTheme(bool value);
2728

lib/gui/src/elements/Label.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace gui::elements {
4040
for (size_t i = 0; i < lines.size(); i++)
4141
{
4242
int x;
43-
switch (m_textHorizontalAlignment)
43+
switch (int(m_textHorizontalAlignment))
4444
{
4545
case Alignement::LEFT:
4646
x = getRadius()/2 + getBorderSize();
@@ -54,7 +54,7 @@ namespace gui::elements {
5454
};
5555

5656
int y;
57-
switch (m_textVerticalAlignment)
57+
switch (int(m_textVerticalAlignment))
5858
{
5959
case Alignement::UP:
6060
y = getRadius()/2 + getBorderSize() + (m_surface->getTextHeight() + LINE_SPACING) * i;

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

platformio.ini

+10-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ test_framework = googletest
1414
[env:esp32dev]
1515
platform = espressif32
1616
board = esp32dev
17-
framework = espidf
17+
framework = arduino, espidf
1818
monitor_speed = 115200
1919
lib_deps =
2020
lovyan03/LovyanGFX@^1.1.9
@@ -26,15 +26,22 @@ build_flags =
2626

2727
[env:paxo-v5]
2828
platform = espressif32
29-
board = esp32dev
30-
framework = espidf
29+
board = esp-wrover-kit
30+
framework = arduino
3131
monitor_speed = 115200
3232
lib_deps =
3333
lovyan03/LovyanGFX@^1.1.9
3434
build_flags =
3535
-DPLATFORM_PAXO_V5
3636
-DCONFIG_FATFS_MAX_LFN=255
3737
-I include
38+
-fexceptions
39+
-Wno-error=maybe-uninitialized
40+
-Wno-reorder
41+
-DBOARD_HAS_PSRAM
42+
-mfix-esp32-psram-cache-issue
43+
-DCONFIG_SPIRAM_CACHE_WORKAROUND
44+
-DCORE_DEBUG_LEVEL=5
3845

3946
; You need to have mingw32/mingw64 installed
4047
[env:windows]

0 commit comments

Comments
 (0)