Skip to content

Commit 3219e2b

Browse files
Add Wireless Paper example
1 parent ef1557d commit 3219e2b

File tree

13 files changed

+524
-0
lines changed

13 files changed

+524
-0
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/* Heltec Automation Wireless_Paper_V1.0 Sensors test example
2+
*
3+
* Function:
4+
* - Build a web page and refresh e-paper through Wi-Fi.
5+
* - With DHCP function.
6+
*
7+
* HelTec AutoMation, Chengdu, China
8+
* www.heltec.org
9+
*
10+
* Operation instance: Only work with Heltec Wireless Paper V1.0 hardware
11+
*
12+
* this project also realess in GitHub:
13+
* https://github.com/HelTecAutomation/Heltec_ESP32
14+
*/
15+
16+
#include <WebServer.h>
17+
#include <ESPmDNS.h>
18+
#include "HT_QYEG0213RWS800_BWR.h"
19+
#include "images.h"
20+
#include "html.h"
21+
QYEG0213RWS800_BWR display(6, 5, 4, 7, 3, 2, -1, 6000000); // rst,dc,cs,busy,sck,mosi,miso,frequency
22+
23+
uint8_t width, height;
24+
String HTTP_Payload;
25+
26+
WebServer server(80); // Create WebServer object with port number 80
27+
// By using port number 80, you can directly enter the IP address for access, while using other ports requires entering the IP: port number for access
28+
29+
const char *ssid = "your_ssid";
30+
const char *password = "your_password";
31+
32+
// Distribute processing callback function
33+
34+
void Config_Callback()
35+
{
36+
37+
String Payload;
38+
const char *buff;
39+
40+
Payload = server.arg("value"); // Obtain the data delivered
41+
buff = Payload.c_str();
42+
43+
delay(100);
44+
int i = 0;
45+
char *token;
46+
token = strtok((char *)buff, ",");
47+
48+
while (token != NULL)
49+
{
50+
int num = atoi(token);
51+
WiFi_Logo_bits[i] = num;
52+
token = strtok(NULL, ",");
53+
Serial.print(WiFi_Logo_bits[i]);
54+
i++;
55+
}
56+
drawImageDemo();
57+
Serial.println("dd");
58+
}
59+
60+
void setup()
61+
{
62+
63+
Serial.begin(115200);
64+
Serial.println();
65+
66+
VextON();
67+
delay(100);
68+
display.init();
69+
70+
WiFi.mode(WIFI_STA);
71+
WiFi.setSleep(false);
72+
WiFi.begin(ssid, password);
73+
while (WiFi.status() != WL_CONNECTED)
74+
{
75+
delay(500);
76+
Serial.print(".");
77+
}
78+
Serial.println("Connected");
79+
Serial.print("IP Address:");
80+
Serial.println(WiFi.localIP());
81+
server.on("/", []()
82+
{ server.send(200, "text/html", index_html); });
83+
84+
server.on("/set", HTTP_GET, Config_Callback); // Bind the handler that is configured to deliver the function
85+
server.begin();
86+
}
87+
void drawImageDemo()
88+
{
89+
// see http://blog.squix.org/2015/05/esp8266-nodemcu-how-to-create-xbm.html
90+
// on how to create xbm files
91+
display.clear();
92+
display.update(BLACK_BUFFER);
93+
94+
display.clear();
95+
int x = width / 2 - WiFi_Logo_width / 2;
96+
int y = height / 2 - WiFi_Logo_height / 2;
97+
display.drawXbm(0, 0, WiFi_Logo_width, WiFi_Logo_height, WiFi_Logo_bits);
98+
display.update(BLACK_BUFFER);
99+
display.display();
100+
}
101+
void VextON(void)
102+
{
103+
pinMode(45, OUTPUT);
104+
digitalWrite(45, LOW);
105+
}
106+
107+
void VextOFF(void) // Vext default OFF
108+
{
109+
pinMode(45, OUTPUT);
110+
digitalWrite(45, HIGH);
111+
}
112+
void loop()
113+
{
114+
server.handleClient(); // Handle requests from clients
115+
}
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
//An array for storing web pages
2+
const char index_html[] PROGMEM = R"rawliteral(
3+
<!DOCTYPE HTML>
4+
<html>
5+
<head>
6+
<meta charset="utf-8">
7+
</head>
8+
<body>
9+
<h2>wireless_paper</h2>
10+
<!-- Create an ID bit dht box to display the obtained data -->
11+
<div id="dht">
12+
</div>
13+
<canvas id="canvasElem" width="1" height="1"></canvas>
14+
<input type="file" id="avatar" name="avatar" style="display:none" accept="image/bmp,image/jpg,image/png" onchange="changeAgentContent(this)" />
15+
<input type="button" value="Browse..." onclick="document.getElementById('avatar').click()" />
16+
<input type="text" value="" disabled id="inputFileAgent" />
17+
18+
<br>
19+
<!-- <input type="button" onclick="bmpToXbm(255)" value="Get image data">-->
20+
21+
<input type="button" value="refresh" onclick="set()">
22+
</body>
23+
<script>
24+
// Pressing the button will run this JS function
25+
var xbmCode;
26+
function changeAgentContent(file){
27+
// document.getElementById("inputFileAgent").value = document.getElementById("avatar").value;
28+
var filePath = file.value;
29+
if (filePath) {
30+
var filePic = file.files[0]; //Selected file content - images
31+
var fileType = filePath.slice(filePath.indexOf(".")); //Choose the format of the file
32+
var fileSize = file.files[0].size; //选Choose the size of the file
33+
var reader = new FileReader();
34+
reader.readAsDataURL(filePic);
35+
reader.onload = function (e) {
36+
var data = e.target.result;
37+
//Load image to obtain the true width and height of the image
38+
var image = new Image();
39+
image.onload = function () {
40+
var width = image.width;
41+
var height = image.height;
42+
if (width == 255 || height == 122) { //Determine file pixels
43+
//upload pictures
44+
document.getElementById("inputFileAgent").value = document.getElementById("avatar").value;
45+
bmpToXbm(255);
46+
} else {
47+
alert("The image size should be: 255*122");
48+
return;
49+
}
50+
};
51+
image.src = data;
52+
};
53+
}
54+
}
55+
56+
function bmpToXbm(brightnessLevels) {
57+
var fileInput = document.getElementById("avatar");
58+
var file = fileInput.files[0];
59+
60+
var reader = new FileReader();
61+
reader.onload = function() {
62+
var img = new Image();
63+
img.onload = function() {
64+
65+
var canvas = document.getElementById("canvasElem");
66+
// var canvas = document.createElement("canvas");
67+
var context = canvas.getContext("2d");
68+
69+
canvas.width = img.width;
70+
canvas.height = img.height;
71+
context.drawImage(img, 0, 0);
72+
73+
var imageData = context.getImageData(0, 0, canvas.width, canvas.height);
74+
var data = imageData.data;
75+
var width = canvas.width;
76+
var height = canvas.height;
77+
78+
79+
80+
var xbmData;
81+
var xbmBytes = Math.ceil(width / 8);
82+
var bitIndex = 0;
83+
var byteValue = 0;
84+
85+
for (var i = 0; i < data.length; i += 4) {
86+
var offset = i / 4;
87+
var x = offset % width;
88+
var y = Math.floor(offset / width);
89+
var r = data[i];
90+
var g = data[i + 1];
91+
var b = data[i + 2];
92+
var brightness = Math.round((r + g + b) / 3);
93+
94+
var isOn = brightness < 254;
95+
96+
if (isOn) {
97+
byteValue |= (1<< bitIndex);
98+
}
99+
100+
if (bitIndex === 7 || x === width - 1) {
101+
xbmData += "0x" + byteValue.toString(16) + ", ";
102+
byteValue = 0;
103+
bitIndex = 0;
104+
105+
if (x === width - 1) {
106+
xbmData += "\n";
107+
}
108+
} else {
109+
bitIndex++;
110+
}
111+
}
112+
xbmCode = xbmData;
113+
console.log(xbmCode);
114+
};
115+
116+
img.src = reader.result;
117+
};
118+
119+
reader.readAsDataURL(file);
120+
}
121+
122+
function set() {
123+
var payload = xbmCode; // What needs to be sent
124+
125+
126+
127+
var a=payload.split(",").map(v=> parseInt(v, 16)).reduce((pre, cur) => pre + "," + cur, "").slice(1)
128+
// Give via get request /set
129+
// .replaceAll("+", "-").replaceAll("/", "_").replaceAll("0x", "").map(v=> parseInt(v, 16))
130+
var xhr = new XMLHttpRequest();
131+
// XMLHttpRequest
132+
xhr.open("GET", "/set?value=" + a, true);
133+
xhr.send();
134+
}
135+
136+
</script>)rawliteral";
137+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#define WiFi_Logo_width 250
2+
#define WiFi_Logo_height 122
3+
uint8_t WiFi_Logo_bits[10000] PROGMEM = {
4+
};
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/* Heltec Automation Wireless_Paper_V1.0 Sensors test example
2+
*
3+
* Function:
4+
* - Build a web page and refresh e-paper through Wi-Fi.
5+
* - With DHCP function.
6+
*
7+
* HelTec AutoMation, Chengdu, China
8+
* www.heltec.org
9+
*
10+
* Operation instance: Only work with Heltec Wireless Paper V1.1 hardware
11+
*
12+
* this project also realess in GitHub:
13+
* https://github.com/HelTecAutomation/Heltec_ESP32
14+
*/
15+
16+
#include <WebServer.h>
17+
#include <ESPmDNS.h>
18+
#include "HT_lCMEN2R13EFC1.h"
19+
#include "images.h"
20+
#include "html.h"
21+
HT_ICMEN2R13EFC1 display(6, 5, 4, 7, 3, 2, -1, 6000000); // rst,dc,cs,busy,sck,mosi,miso,frequency
22+
23+
int width, height;
24+
String HTTP_Payload;
25+
WebServer server(80); // Create WebServer object with port number 80
26+
// By using port number 80, you can directly enter the IP address for access, while using other ports requires entering the IP: port number for access
27+
28+
const char *ssid = "your-ssid";
29+
const char *password = "your-password";
30+
31+
// Distribute processing callback function
32+
void Config_Callback()
33+
{
34+
35+
String Payload;
36+
const char *buff;
37+
38+
Payload = server.arg("value"); // Obtain the data delivered
39+
buff = Payload.c_str();
40+
41+
delay(100);
42+
int i = 0;
43+
char *token;
44+
token = strtok((char *)buff, ",");
45+
46+
while (token != NULL)
47+
{
48+
int num = atoi(token);
49+
WiFi_Logo_bits[i] = num;
50+
token = strtok(NULL, ",");
51+
Serial.print(WiFi_Logo_bits[i]);
52+
i++;
53+
}
54+
drawImageDemo();
55+
Serial.println("dd");
56+
}
57+
58+
void setup()
59+
{
60+
61+
Serial.begin(115200);
62+
Serial.println();
63+
64+
VextON();
65+
delay(100);
66+
display.init();
67+
68+
WiFi.mode(WIFI_STA);
69+
WiFi.setSleep(false);
70+
WiFi.begin(ssid, password);
71+
while (WiFi.status() != WL_CONNECTED)
72+
{
73+
delay(500);
74+
Serial.print(".");
75+
}
76+
Serial.println("Connected");
77+
Serial.print("IP Address:");
78+
Serial.println(WiFi.localIP());
79+
server.on("/", []()
80+
{ server.send(200, "text/html", index_html); });
81+
82+
server.on("/set", HTTP_GET, Config_Callback); // Bind the handler that is configured to deliver the function
83+
server.begin();
84+
}
85+
void drawImageDemo()
86+
{
87+
// see http://blog.squix.org/2015/05/esp8266-nodemcu-how-to-create-xbm.html
88+
// on how to create xbm files
89+
display.clear();
90+
display.update(BLACK_BUFFER);
91+
92+
display.clear();
93+
int x = width / 2 - WiFi_Logo_width / 2;
94+
int y = height / 2 - WiFi_Logo_height / 2;
95+
display.drawXbm(0, 0, WiFi_Logo_width, WiFi_Logo_height, WiFi_Logo_bits);
96+
display.update(BLACK_BUFFER);
97+
display.display();
98+
99+
}
100+
void VextON(void)
101+
{
102+
pinMode(45, OUTPUT);
103+
digitalWrite(45, LOW);
104+
}
105+
106+
void VextOFF(void) // Vext default OFF
107+
{
108+
pinMode(45, OUTPUT);
109+
digitalWrite(45, HIGH);
110+
}
111+
void loop()
112+
{
113+
server.handleClient(); // Handle requests from clients
114+
115+
}

0 commit comments

Comments
 (0)