Skip to content

Commit

Permalink
Merge pull request #101 from paxo-phone/gabriel_dev
Browse files Browse the repository at this point in the history
Ajout des MMS
  • Loading branch information
paxo-rch authored Sep 4, 2024
2 parents 1fc30a8 + 1720e6c commit 39a158f
Show file tree
Hide file tree
Showing 23 changed files with 1,783 additions and 119 deletions.
4 changes: 2 additions & 2 deletions lib/graphics/src/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ uint64_t getFileSize(storage::Path& path)
// TODO : Use "Path"
std::shared_ptr<uint8_t[]> getFileData(storage::Path& path)
{
auto data = std::shared_ptr<uint8_t[]>(new uint8_t[30]); // just for headers
auto data = std::shared_ptr<uint8_t[]>(new uint8_t[2000]); // just for headers

storage::FileStream stream(path.str(), storage::Mode::READ);

Expand All @@ -34,7 +34,7 @@ std::shared_ptr<uint8_t[]> getFileData(storage::Path& path)
}

size_t i = 0;
while (i < 30)
while (i < 2000)
{
data.get()[i++] = stream.readchar();
}
Expand Down
109 changes: 106 additions & 3 deletions lib/graphics/src/Surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,22 @@

#include <path.hpp>
#include <filestream.hpp>
//#include <JPEGENC.h>
#include <iostream>

#ifdef ESP_PLATFORM
#include <Arduino.h>
#include <SD.h>
#endif

#ifndef JPEG_PIXEL_RGB565
#define JPEG_PIXEL_RGB565 4
#endif

#ifndef JPEG_SUBSAMPLE_444
#define JPEG_SUBSAMPLE_444 0
#endif

#include "color.hpp"
#include "fonts/Arial-12.h"
#include "fonts/Arial-16.h"
Expand Down Expand Up @@ -65,13 +74,14 @@

namespace graphics
{
Surface::Surface(const uint16_t width, const uint16_t height) : m_color(0xFFFF),
Surface::Surface(const uint16_t width, const uint16_t height, const uint8_t color_depth) : m_color(0xFFFF),
m_transparent(false),
m_transparent_color(0xFFFF),
m_font(ARIAL),
m_fontSize(PT_12)
m_fontSize(PT_12),
m_color_depth(color_depth)
{
m_sprite.setColorDepth(16);
m_sprite.setColorDepth(m_color_depth);
m_sprite.setPsram(true);

m_sprite.createSprite(width, height);
Expand Down Expand Up @@ -286,6 +296,98 @@ namespace graphics
#endif
}

bool Surface::saveAsJpg(const storage::Path filename)
{
/*JPEG jpg;
int quality = 90;
LGFX_Sprite sprite = &m_sprite;
if (sprite.getBuffer() == nullptr || !filename.str().size()) {
Serial.println("Invalid sprite or filename");
return false;
}
int width = sprite.width();
int height = sprite.height();
// Open the file for writing
std::ofstream outFile(filename.str(), std::ios::binary);
if (!outFile.is_open()) {
Serial.println("Failed to open file for writing");
return false;
}
// JPEG encoder object
JPEGENCODE jpe;
// Start the JPEG encoding process
int rc = jpg.encodeBegin(&jpe, width, height, JPEG_PIXEL_RGB565, JPEG_SUBSAMPLE_444, quality);
if (rc != 0) {
Serial.println("Failed to start JPEG encoding");
outFile.close();
return false;
}
// Calculate MCU dimensions
int mcu_w = (width + jpe.cx - 1) / jpe.cx;
int mcu_h = (height + jpe.cy - 1) / jpe.cy;
// Buffer for one MCU
uint8_t ucMCU[64 * 3]; // 8x8 pixels, 3 channels (RGB)
// Process each MCU
for (int y = 0; y < mcu_h; y++) {
for (int x = 0; x < mcu_w; x++) {
// Extract MCU data from sprite
for (int j = 0; j < 8; j++) {
for (int i = 0; i < 8; i++) {
int px = x * 8 + i;
int py = y * 8 + j;
if (px < width && py < height) {
uint16_t pixel = sprite.readPixel(px, py);
// Convert RGB565 to RGB888
uint8_t r = ((pixel >> 11) & 0x1F) << 3;
uint8_t g = ((pixel >> 5) & 0x3F) << 2;
uint8_t b = (pixel & 0x1F) << 3;
ucMCU[(j * 8 + i) * 3] = r;
ucMCU[(j * 8 + i) * 3 + 1] = g;
ucMCU[(j * 8 + i) * 3 + 2] = b;
} else {
// Fill with black if outside sprite bounds
ucMCU[(j * 8 + i) * 3] = 0;
ucMCU[(j * 8 + i) * 3 + 1] = 0;
ucMCU[(j * 8 + i) * 3 + 2] = 0;
}
}
}
// Add MCU to JPEG
rc = jpg.addMCU(&jpe, ucMCU, 8);
if (rc != 0) {
Serial.println("Failed to add MCU");
outFile.close();
return false;
}
}
}
// Finish encoding and get the compressed data
int jpegSize = jpg.close();
// Write JPEG data to file
outFile.write(reinterpret_cast<const char*>(jpe.pOutput), jpegSize);
outFile.close();
Serial.print("JPEG file created: ");
Serial.println(filename);
Serial.print("File size: ");
Serial.print(jpegSize);
Serial.println(" bytes");*/

return true;
}

void Surface::setFont(const EFont font)
{
m_font = font;
Expand Down Expand Up @@ -463,6 +565,7 @@ namespace graphics
{
// Copy
auto copy = lgfx::LGFX_Sprite();
copy.setColorDepth(m_color_depth);
copy.createSprite(getWidth(), getHeight());

// Apply blur effect
Expand Down
4 changes: 3 additions & 1 deletion lib/graphics/src/Surface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ namespace graphics
EFont m_font;
float m_fontSize;
color_t m_text_color;
uint8_t m_color_depth;

public:
Surface(uint16_t width, uint16_t height);
Surface(uint16_t width, uint16_t height, const uint8_t color_depth = 16);
~Surface();

[[nodiscard]] uint16_t getWidth() const;
Expand Down Expand Up @@ -67,6 +68,7 @@ namespace graphics

void drawLine(int16_t x1, int16_t y1, int16_t x2, int16_t y2, color_t color);

bool saveAsJpg(const storage::Path filename);
void drawImage(const SImage &image, int16_t x, int16_t y, uint16_t w = 0, uint16_t h = 0);

void setFont(EFont font);
Expand Down
15 changes: 14 additions & 1 deletion lib/graphics/src/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//

#include "graphics.hpp"
#include "standby.hpp"

#include <iostream>
#include <libsystem.hpp>
Expand All @@ -25,7 +26,6 @@ namespace
{
bool running;


std::shared_ptr<LGFX> lcd;

graphics::EScreenOrientation screenOrientation;
Expand Down Expand Up @@ -72,6 +72,11 @@ void graphics::setBrightness(uint16_t value)
#endif
}

LGFX* graphics::getLcd()
{
return lcd.get();
}

graphics::GraphicsInitCode graphics::init()
{
#ifdef ESP_PLATFORM
Expand Down Expand Up @@ -270,6 +275,8 @@ int getTouch(uint16_t *pPoints)

void graphics::touchUpdate()
{
if(StandbyMode::state() == true)
return;
bool touchState = true;
int16_t liveTouchX = 0, liveTouchY = 0;

Expand Down Expand Up @@ -327,6 +334,12 @@ void graphics::touchUpdate()
newTouchY = -1;
isTouchRead = false;
}

if(liveTouchX != touchX || liveTouchY != touchY)
{
if(StandbyMode::state() == false)
StandbyMode::trigger();
}
}

bool graphics::isTouched()
Expand Down
15 changes: 7 additions & 8 deletions lib/graphics/src/graphics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
#ifndef GRAPHICS_HPP
#define GRAPHICS_HPP

// #define LGFX_USE_V1
// #include <LovyanGFX.hpp>
#define LGFX_USE_V1

#include <cstdint>

#ifdef ESP_PLATFORM

Expand All @@ -18,13 +19,8 @@
#include "lgfx/v1/platforms/sdl/Panel_sdl.hpp"
#include "LGFX_AUTODETECT.hpp"

#include "LovyanGFX.hpp"

#endif

#include <cstdint>


class FT6236G;

namespace graphics
Expand All @@ -37,7 +33,10 @@ namespace graphics

class Surface;

enum GraphicsInitCode {
LGFX* getLcd();
void reInit();

enum GraphicsInitCode {
SUCCESS,
ERROR_NO_TOUCHSCREEN,
ERROR_FAULTY_TOUCHSCREEN
Expand Down
1 change: 1 addition & 0 deletions lib/gsm/src/conversation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <path.hpp>

#define MESSAGES_LOCATION "apps/messages/data"
#define MESSAGES_IMAGES_LOCATION "apps/messages/images"
#define MESSAGES_NOTIF_LOCATION "apps/messages/unread.txt"
#define MAX_MESSAGES 40

Expand Down
Loading

0 comments on commit 39a158f

Please sign in to comment.