Initial commit
This commit is contained in:
136
Ecran Lilygot-T-RGB/Code tests/Get_img/Get_img.ino
Normal file
136
Ecran Lilygot-T-RGB/Code tests/Get_img/Get_img.ino
Normal file
@@ -0,0 +1,136 @@
|
||||
#include "Wire.h"
|
||||
#include "XL9535_driver.h"
|
||||
#include "esp_lcd_panel_io.h"
|
||||
#include "esp_lcd_panel_ops.h"
|
||||
#include "esp_lcd_panel_rgb.h"
|
||||
#include "esp_lcd_panel_vendor.h"
|
||||
#include "current_img.h"
|
||||
#include "pin_config.h"
|
||||
#include <Arduino.h>
|
||||
#include <SPIFFS.h>
|
||||
#include <WiFi.h>
|
||||
#include <AsyncTCP.h>
|
||||
#include <ESPAsyncWebSrv.h>
|
||||
|
||||
const char* ssid = "Box-gut-2.4G";
|
||||
const char* password = "Rut@b@g@93";
|
||||
AsyncWebServer server(80);
|
||||
|
||||
void connectToWiFi() {
|
||||
WiFi.begin(ssid, password);
|
||||
|
||||
Serial.print("Connexion en cours au réseau Wi-Fi...");
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(1000);
|
||||
Serial.print(".");
|
||||
}
|
||||
Serial.println("\nConnecté au réseau Wi-Fi");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void traiterEntreeJson(char* entreeJson) {
|
||||
char *token = strtok(const_cast<char*>(entreeJson), ",");
|
||||
|
||||
File fichier = SPIFFS.open("/new_img.h", "a"); // Ouvre le fichier en mode ajout
|
||||
fichier.print("const uint16_t image_data[] = {");
|
||||
while (token != NULL) {
|
||||
String objet = String(token);
|
||||
|
||||
objet.replace("[", "");
|
||||
objet.replace("]", "");
|
||||
objet.replace("{", "");
|
||||
objet.replace("}", "");
|
||||
objet.replace("\"", "");
|
||||
int index = objet.indexOf(':');
|
||||
String cle = objet.substring(0, index);
|
||||
int valeur = objet.substring(index + 1).toInt();
|
||||
|
||||
for (int i = 0; i < valeur; i++) {
|
||||
fichier.print(cle);
|
||||
fichier.print(',');
|
||||
}
|
||||
|
||||
token = strtok(NULL, ",");
|
||||
}
|
||||
fichier.print("};");
|
||||
fichier.close(); // Ferme le fichier
|
||||
|
||||
File f = SPIFFS.open("/new_img.h", "r");
|
||||
if (!f) {
|
||||
Serial.println("Erreur lors de l'ouverture du fichier en lecture.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Lire le contenu du fichier
|
||||
while (f.available()) {
|
||||
char c = f.read();
|
||||
Serial.print(c);
|
||||
}
|
||||
f.close(); // Ferme le fichier
|
||||
}
|
||||
|
||||
|
||||
|
||||
void setupSPIFFS() {
|
||||
if (SPIFFS.begin()) {
|
||||
Serial.println("Système de fichiers SPIFFS monté avec succès");
|
||||
} else {
|
||||
Serial.println("Erreur lors du montage du système de fichiers SPIFFS");
|
||||
}
|
||||
if (SPIFFS.exists("/new_img.h")) {
|
||||
|
||||
|
||||
if (SPIFFS.remove("/current_img.h")) {
|
||||
Serial.println("Le fichier a été supprimé avec succès.");
|
||||
} else {
|
||||
Serial.println("Erreur lors de la suppression du fichier.");
|
||||
}
|
||||
|
||||
if (SPIFFS.rename("/new_img.h", "/current_img.h")) {
|
||||
Serial.println("Le fichier a été renommé avec succès.");
|
||||
esp_restart();
|
||||
} else {
|
||||
Serial.println("Erreur lors du renommage du fichier.");
|
||||
}
|
||||
|
||||
} else {
|
||||
Serial.println("Le fichier spécifique n'existe pas.");
|
||||
}
|
||||
|
||||
}
|
||||
void setup()
|
||||
{
|
||||
|
||||
// put your setup code here, to run once:
|
||||
Serial.begin(115200);
|
||||
setupSPIFFS();
|
||||
connectToWiFi();
|
||||
|
||||
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
|
||||
request->send(SPIFFS, "/index.html");
|
||||
});
|
||||
|
||||
server.on("/imageData", HTTP_POST, [](AsyncWebServerRequest *request){
|
||||
// Obtenir le corps de la requête JSON
|
||||
|
||||
String jsonData = request->arg("divText");
|
||||
const char* jsonDataChar = jsonData.c_str();
|
||||
Serial.println(jsonDataChar);
|
||||
|
||||
// Envoyez une réponse au client
|
||||
request->send(200, "text/plain", "Données JSON reçues avec succès !");
|
||||
});
|
||||
|
||||
|
||||
server.begin();
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
117
Ecran Lilygot-T-RGB/Code tests/Get_img/XL9535_driver.cpp
Normal file
117
Ecran Lilygot-T-RGB/Code tests/Get_img/XL9535_driver.cpp
Normal file
@@ -0,0 +1,117 @@
|
||||
#include "XL9535_driver.h"
|
||||
#include "Wire.h"
|
||||
|
||||
void XL9535::writeRegister(uint8_t reg, uint8_t *data, uint8_t len) {
|
||||
_wire->beginTransmission(_address);
|
||||
_wire->write(reg);
|
||||
for (uint8_t i = 0; i < len; i++) {
|
||||
_wire->write(data[i]);
|
||||
}
|
||||
_wire->endTransmission();
|
||||
}
|
||||
uint8_t XL9535::readRegister(uint8_t reg, uint8_t *data, uint8_t len) {
|
||||
_wire->beginTransmission(_address);
|
||||
_wire->write(reg);
|
||||
_wire->endTransmission();
|
||||
_wire->requestFrom(_address, len);
|
||||
uint8_t index = 0;
|
||||
while (index < len)
|
||||
data[index++] = _wire->read();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void XL9535::begin(bool A0, bool A1, bool A2, TwoWire *wire) {
|
||||
_address = XL9535_IIC_ADDRESS | (A2 << 3) | (A1 << 2) | (A0 << 1);
|
||||
_wire = wire;
|
||||
is_found = true;
|
||||
_wire->beginTransmission(_address);
|
||||
if (!_wire->endTransmission()) {
|
||||
Serial.println("Found xl9535");
|
||||
} else {
|
||||
Serial.println("xl9535 not found");
|
||||
is_found = false;
|
||||
}
|
||||
}
|
||||
void XL9535::pinMode(uint8_t pin, uint8_t mode) {
|
||||
if (is_found) {
|
||||
uint8_t port = 0;
|
||||
if (pin > 7) {
|
||||
readRegister(XL9535_CONFIG_PORT_1_REG, &port, 1);
|
||||
if (mode == OUTPUT) {
|
||||
port = port & (~(1 << (pin - 10)));
|
||||
} else {
|
||||
port = port | (1 << (pin - 10));
|
||||
}
|
||||
writeRegister(XL9535_CONFIG_PORT_1_REG, &port, 1);
|
||||
|
||||
} else {
|
||||
readRegister(XL9535_CONFIG_PORT_0_REG, &port, 1);
|
||||
if (mode == OUTPUT) {
|
||||
port = port & (~(1 << pin));
|
||||
} else {
|
||||
port = port | (1 << pin);
|
||||
}
|
||||
writeRegister(XL9535_CONFIG_PORT_0_REG, &port, 1);
|
||||
}
|
||||
} else {
|
||||
Serial.println("xl9535 not found");
|
||||
}
|
||||
}
|
||||
void XL9535::pinMode8(uint8_t port, uint8_t pin, uint8_t mode) {
|
||||
if (is_found) {
|
||||
uint8_t _pin = (mode != OUTPUT) ? pin : ~pin;
|
||||
if (port) {
|
||||
writeRegister(XL9535_CONFIG_PORT_1_REG, &_pin, 1);
|
||||
} else {
|
||||
writeRegister(XL9535_CONFIG_PORT_0_REG, &_pin, 1);
|
||||
}
|
||||
} else {
|
||||
Serial.println("xl9535 not found");
|
||||
}
|
||||
}
|
||||
|
||||
void XL9535::digitalWrite(uint8_t pin, uint8_t val) {
|
||||
if (is_found) {
|
||||
uint8_t port = 0;
|
||||
uint8_t reg_data = 0;
|
||||
if (pin > 7) {
|
||||
readRegister(XL9535_OUTPUT_PORT_1_REG, ®_data, 1);
|
||||
reg_data = reg_data & (~(1 << (pin - 10)));
|
||||
port = reg_data | val << (pin - 10);
|
||||
writeRegister(XL9535_OUTPUT_PORT_1_REG, &port, 1);
|
||||
} else {
|
||||
readRegister(XL9535_OUTPUT_PORT_0_REG, ®_data, 1);
|
||||
reg_data = reg_data & (~(1 << pin));
|
||||
port = reg_data | val << pin;
|
||||
writeRegister(XL9535_OUTPUT_PORT_0_REG, &port, 1);
|
||||
}
|
||||
} else {
|
||||
Serial.println("xl9535 not found");
|
||||
}
|
||||
}
|
||||
|
||||
int XL9535::digitalRead(uint8_t pin) {
|
||||
if (is_found) {
|
||||
int state = 0;
|
||||
uint8_t port = 0;
|
||||
if (pin > 7) {
|
||||
readRegister(XL9535_INPUT_PORT_1_REG, &port, 1);
|
||||
state = port & (pin - 10) ? 1 : 0;
|
||||
} else {
|
||||
readRegister(XL9535_INPUT_PORT_0_REG, &port, 1);
|
||||
state = port & pin ? 1 : 0;
|
||||
}
|
||||
return state;
|
||||
} else {
|
||||
Serial.println("xl9535 not found");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void XL9535::read_all_reg() {
|
||||
uint8_t data;
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
readRegister(i, &data, 1);
|
||||
Serial.printf("0x%02x : 0x%02X \r\n", i, data);
|
||||
}
|
||||
}
|
||||
37
Ecran Lilygot-T-RGB/Code tests/Get_img/XL9535_driver.h
Normal file
37
Ecran Lilygot-T-RGB/Code tests/Get_img/XL9535_driver.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "Wire.h"
|
||||
|
||||
#define XL9535_IIC_ADDRESS 0X20
|
||||
|
||||
#define XL9535_INPUT_PORT_0_REG 0X00
|
||||
#define XL9535_INPUT_PORT_1_REG 0X01
|
||||
#define XL9535_OUTPUT_PORT_0_REG 0X02
|
||||
#define XL9535_OUTPUT_PORT_1_REG 0X03
|
||||
#define XL9535_INVERSION_PORT_0_REG 0X04
|
||||
#define XL9535_INVERSION_PORT_1_REG 0X05
|
||||
#define XL9535_CONFIG_PORT_0_REG 0X06
|
||||
#define XL9535_CONFIG_PORT_1_REG 0X07
|
||||
|
||||
class XL9535 {
|
||||
public:
|
||||
XL9535(){};
|
||||
~XL9535(){};
|
||||
|
||||
void begin(bool A0 = 0, bool A1 = 0, bool A2 = 0, TwoWire *wire = &Wire);
|
||||
void pinMode(uint8_t pin, uint8_t mode);
|
||||
void pinMode8(uint8_t port, uint8_t pin, uint8_t mode);
|
||||
|
||||
void digitalWrite(uint8_t pin, uint8_t val);
|
||||
int digitalRead(uint8_t pin);
|
||||
void read_all_reg();
|
||||
|
||||
protected:
|
||||
void writeRegister(uint8_t reg, uint8_t *data, uint8_t len);
|
||||
uint8_t readRegister(uint8_t reg, uint8_t *data, uint8_t len);
|
||||
|
||||
uint8_t _address;
|
||||
TwoWire *_wire;
|
||||
bool is_found;
|
||||
};
|
||||
3
Ecran Lilygot-T-RGB/Code tests/Get_img/current_img.h
Normal file
3
Ecran Lilygot-T-RGB/Code tests/Get_img/current_img.h
Normal file
File diff suppressed because one or more lines are too long
154
Ecran Lilygot-T-RGB/Code tests/Get_img/data/index.html
Normal file
154
Ecran Lilygot-T-RGB/Code tests/Get_img/data/index.html
Normal file
@@ -0,0 +1,154 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Conversion d'image en C</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Conversion d'image en tableau C</h1>
|
||||
|
||||
<form id="imageForm" action="/sendImage" method="post">
|
||||
<input type="hidden" name="imageData" id="imageData">
|
||||
<input type="hidden" name="imageSize" id="imageSize">
|
||||
<input type="hidden" name="imageSizeOrign" id="imageSizeOrign">
|
||||
<button type="button" onclick="sendToESP()">Envoyer a l'ecran</button>
|
||||
</form>
|
||||
|
||||
<div>
|
||||
<input type="file" id="imageInput" accept="image/*" onchange="convertImage()">
|
||||
</div>
|
||||
|
||||
<div id="result">
|
||||
<!-- L'image convertie sera affichée ici -->
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function convertImage() {
|
||||
const inputElement = document.getElementById("imageInput");
|
||||
const file = inputElement.files[0];
|
||||
|
||||
if (file) {
|
||||
const reader = new FileReader();
|
||||
|
||||
reader.onload = function(event) {
|
||||
const image = new Image();
|
||||
image.src = event.target.result;
|
||||
|
||||
image.onload = function() {
|
||||
const canvas = document.createElement("canvas");
|
||||
canvas.width = 480;
|
||||
canvas.height = 480;
|
||||
const context = canvas.getContext("2d");
|
||||
|
||||
context.drawImage(image, 0, 0, 480, 480);
|
||||
|
||||
const imageData = context.getImageData(0, 0, 480, 480).data;
|
||||
const outputArray = [];
|
||||
|
||||
for (let i = 0; i < imageData.length; i += 4) {
|
||||
const r = imageData[i];
|
||||
const g = imageData[i + 1];
|
||||
const b = imageData[i + 2];
|
||||
const rgb565 = ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3);
|
||||
outputArray.push(`0x${rgb565.toString(16).toUpperCase()}, `);
|
||||
}
|
||||
|
||||
const resultDiv = document.getElementById("result");
|
||||
document.getElementById("imageData").value = outputArray.join("");
|
||||
resultDiv.innerHTML = `<h2>Image convertie en tableau C :</h2><pre id="completeData" >${outputArray.join("")}</pre>`;
|
||||
};
|
||||
};
|
||||
|
||||
reader.readAsDataURL(file);
|
||||
}
|
||||
}
|
||||
|
||||
function compresse(input_data) {
|
||||
let consecutiveCount = 1;
|
||||
const consecutiveCountsArray = [];
|
||||
|
||||
for (let i = 0; i < input_data.length-1; i++) {
|
||||
const currentValue = input_data[i];
|
||||
const nextValue = input_data[i + 1];
|
||||
if (currentValue === nextValue) {
|
||||
consecutiveCount++;
|
||||
} else {
|
||||
const entry = {};
|
||||
entry[`${currentValue.toString(16).toUpperCase()}`] = consecutiveCount;
|
||||
consecutiveCountsArray.push(entry);
|
||||
consecutiveCount = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return consecutiveCountsArray;
|
||||
}
|
||||
|
||||
function decompresse(consecutiveCounts) {
|
||||
const input_data = [];
|
||||
|
||||
consecutiveCounts.forEach((entry) => {
|
||||
const key = Object.keys(entry)[0];
|
||||
const count = entry[key];
|
||||
|
||||
// Supprimer les espaces et convertir en majuscules
|
||||
const cleanedKey = key.replace(/\s+/g, '').toUpperCase();
|
||||
|
||||
// Ajouter le préfixe "0x"
|
||||
const hexValue = cleanedKey.substring(2);
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
input_data.push('0x'+hexValue);
|
||||
}
|
||||
});
|
||||
|
||||
return input_data;
|
||||
}
|
||||
|
||||
function sendToESP() {
|
||||
// Obtenez la référence de la div par son identifiant
|
||||
const myDiv = document.getElementById("completeData");
|
||||
|
||||
// Obtenez le texte de la div
|
||||
const divText = myDiv.textContent;
|
||||
|
||||
// Créez un objet FormData pour envoyer les données
|
||||
const formData = new FormData();
|
||||
formData.append("divText", compresse(divText));
|
||||
|
||||
fetch("/imageData", {
|
||||
method: "POST",
|
||||
body: formData,
|
||||
})
|
||||
.then((response) => {
|
||||
if (response.ok) {
|
||||
return response.text();
|
||||
} else {
|
||||
throw new Error("Erreur lors de l'envoi des données.");
|
||||
}
|
||||
})
|
||||
.then((responseText) => {
|
||||
console.log(responseText); // La réponse du serveur
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
});
|
||||
}
|
||||
<!-- function sendToESP() { -->
|
||||
<!-- const hexData = document.getElementById("imageData").value.split(','); -->
|
||||
<!-- const compressedData = compresse(hexData); -->
|
||||
|
||||
<!-- console.log(typeof compressedData); -->
|
||||
<!-- decompresse_data = JSON.stringify(decompresse(compressedData)).replace(/"/g, '').replace(']', '};').replace('[', 'const uint16_t image_data[] = {'); -->
|
||||
<!-- console.log(decompresse_data); -->
|
||||
|
||||
<!-- compressData_complete = JSON.stringify(compressedData).replace(/\s/g, '').replace(/"/g, ''); -->
|
||||
<!-- document.getElementById("imageData").value = JSON.stringify(compressedData).replace(/\s/g, '').replace(/"/g, ''); -->
|
||||
<!-- document.getElementById("imageSize").value = compressedData.length; -->
|
||||
<!-- document.getElementById("imageSizeOrign").value = hexData.length; -->
|
||||
|
||||
<!-- const form = document.getElementById("imageForm"); -->
|
||||
<!-- form.submit(); -->
|
||||
<!-- } -->
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
57
Ecran Lilygot-T-RGB/Code tests/Get_img/pin_config.h
Normal file
57
Ecran Lilygot-T-RGB/Code tests/Get_img/pin_config.h
Normal file
@@ -0,0 +1,57 @@
|
||||
#pragma once
|
||||
|
||||
#define WIFI_SSID "xinyuandianzi"
|
||||
#define WIFI_PASSWORD "AA15994823428"
|
||||
|
||||
#define EXAMPLE_LCD_PIXEL_CLOCK_HZ (8 * 1000 * 1000)
|
||||
#define EXAMPLE_LCD_BK_LIGHT_ON_LEVEL 1
|
||||
#define EXAMPLE_LCD_BK_LIGHT_OFF_LEVEL !EXAMPLE_LCD_BK_LIGHT_ON_LEVEL
|
||||
#define EXAMPLE_PIN_NUM_BK_LIGHT 46
|
||||
#define EXAMPLE_PIN_NUM_HSYNC 47
|
||||
#define EXAMPLE_PIN_NUM_VSYNC 41
|
||||
#define EXAMPLE_PIN_NUM_DE 45
|
||||
#define EXAMPLE_PIN_NUM_PCLK 42
|
||||
// #define EXAMPLE_PIN_NUM_DATA0 44
|
||||
#define EXAMPLE_PIN_NUM_DATA1 21
|
||||
#define EXAMPLE_PIN_NUM_DATA2 18
|
||||
#define EXAMPLE_PIN_NUM_DATA3 17
|
||||
#define EXAMPLE_PIN_NUM_DATA4 16
|
||||
#define EXAMPLE_PIN_NUM_DATA5 15
|
||||
#define EXAMPLE_PIN_NUM_DATA6 14
|
||||
#define EXAMPLE_PIN_NUM_DATA7 13
|
||||
#define EXAMPLE_PIN_NUM_DATA8 12
|
||||
#define EXAMPLE_PIN_NUM_DATA9 11
|
||||
#define EXAMPLE_PIN_NUM_DATA10 10
|
||||
#define EXAMPLE_PIN_NUM_DATA11 9
|
||||
// #define EXAMPLE_PIN_NUM_DATA12 43
|
||||
#define EXAMPLE_PIN_NUM_DATA13 7
|
||||
#define EXAMPLE_PIN_NUM_DATA14 6
|
||||
#define EXAMPLE_PIN_NUM_DATA15 5
|
||||
#define EXAMPLE_PIN_NUM_DATA16 3
|
||||
#define EXAMPLE_PIN_NUM_DATA17 2
|
||||
#define EXAMPLE_PIN_NUM_DISP_EN -1
|
||||
|
||||
// The pixel number in horizontal and vertical
|
||||
#define EXAMPLE_LCD_H_RES 480
|
||||
#define EXAMPLE_LCD_V_RES 480
|
||||
|
||||
#define IIC_SCL_PIN 48
|
||||
#define IIC_SDA_PIN 8
|
||||
|
||||
#define SD_CLK_PIN 39
|
||||
#define SD_CMD_PIN 40
|
||||
#define SD_D0_PIN 38
|
||||
|
||||
#define BAT_VOLT_PIN 4
|
||||
#define TP_INT_PIN 1
|
||||
|
||||
#define BOOT_BTN_PIN 0
|
||||
|
||||
/* XL9535 --- PIN - P0*/
|
||||
#define TP_RES_PIN 1
|
||||
#define PWR_EN_PIN 2
|
||||
#define LCD_CS_PIN 3
|
||||
#define LCD_SDA_PIN 4
|
||||
#define LCD_CLK_PIN 5
|
||||
#define LCD_RST_PIN 6
|
||||
#define SD_CS_PIN 7
|
||||
Reference in New Issue
Block a user