mirror of
https://github.com/Bodmer/TFT_eSPI.git
synced 2025-08-07 06:34:44 +02:00
Updates
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
// Latest at 03/03/17
|
||||||
|
|
||||||
// This is a Processing sketch, see https://processing.org/ to download the IDE
|
// This is a Processing sketch, see https://processing.org/ to download the IDE
|
||||||
|
|
||||||
// The sketch is a client that requests TFT screenshots from an Arduino board.
|
// The sketch is a client that requests TFT screenshots from an Arduino board.
|
||||||
@@ -39,7 +41,7 @@ String image_type = ".png"; //
|
|||||||
// #
|
// #
|
||||||
boolean save_border = true; // Save the image with a border #
|
boolean save_border = true; // Save the image with a border #
|
||||||
int border = 5; // Border pixel width #
|
int border = 5; // Border pixel width #
|
||||||
boolean fade = false; // Fade out image after saving #
|
boolean fade = true ; // Fade out image after saving #
|
||||||
// #
|
// #
|
||||||
int max_images = 10; // Maximum of numbered saved images before over-writing files #
|
int max_images = 10; // Maximum of numbered saved images before over-writing files #
|
||||||
// #
|
// #
|
||||||
@@ -71,7 +73,7 @@ int y_offset = 20; //
|
|||||||
int xpos, ypos; // Pixel position
|
int xpos, ypos; // Pixel position
|
||||||
|
|
||||||
int beginTime = 0;
|
int beginTime = 0;
|
||||||
int pixelWaitTime = 100; // Wait a maximum of 100ms gap for image pixels to arrive
|
int pixelWaitTime = 1000; // Maximum 1000ms wait for image pixels to arrive
|
||||||
int lastPixelTime = 0; // Time that "image send" command was sent
|
int lastPixelTime = 0; // Time that "image send" command was sent
|
||||||
|
|
||||||
int state = 0; // State machine current state
|
int state = 0; // State machine current state
|
||||||
@@ -128,10 +130,7 @@ void draw() {
|
|||||||
switch(state) {
|
switch(state) {
|
||||||
|
|
||||||
case 0: // Init varaibles, send start request
|
case 0: // Init varaibles, send start request
|
||||||
tint(255, 255);
|
tint(0, 0, 0, 255);
|
||||||
textAlign(CENTER);
|
|
||||||
textSize(20);
|
|
||||||
|
|
||||||
println("");
|
println("");
|
||||||
//println("Clearing pipe...");
|
//println("Clearing pipe...");
|
||||||
beginTime = millis() + 200;
|
beginTime = millis() + 200;
|
||||||
@@ -140,7 +139,7 @@ void draw() {
|
|||||||
serial.read();
|
serial.read();
|
||||||
}
|
}
|
||||||
println("Ready to receive image");
|
println("Ready to receive image");
|
||||||
serial.write("S");
|
|
||||||
xpos = 0;
|
xpos = 0;
|
||||||
ypos = 0;
|
ypos = 0;
|
||||||
serialCount = 0;
|
serialCount = 0;
|
||||||
@@ -154,6 +153,7 @@ void draw() {
|
|||||||
|
|
||||||
case 1: // Console message, give server some time
|
case 1: // Console message, give server some time
|
||||||
println("Requesting image");
|
println("Requesting image");
|
||||||
|
serial.write("S");
|
||||||
delay(10);
|
delay(10);
|
||||||
state = 2;
|
state = 2;
|
||||||
break;
|
break;
|
||||||
@@ -161,23 +161,26 @@ void draw() {
|
|||||||
case 2: // Get size and set start time for render time report
|
case 2: // Get size and set start time for render time report
|
||||||
// To do: Read image size info, currently hard coded
|
// To do: Read image size info, currently hard coded
|
||||||
beginTime = millis();
|
beginTime = millis();
|
||||||
|
noTint();
|
||||||
state = 3;
|
state = 3;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3: // Request pixels and render them
|
case 3: // Request pixels and render returned RGB values
|
||||||
|
|
||||||
if ( serial.available() > 0 ) {
|
if ( serial.available() > 0 ) {
|
||||||
|
|
||||||
// Add the latest byte from the serial port to array:
|
// Add the latest byte from the serial port to array:
|
||||||
while (serial.available()>0)
|
while (serial.available()>0)
|
||||||
{
|
{
|
||||||
rgb[serialCount] = serial.read();
|
rgb[serialCount++] = serial.read();
|
||||||
serialCount++;
|
|
||||||
|
|
||||||
// If we have 3 colour bytes:
|
// If we have 3 colour bytes:
|
||||||
if (serialCount >= 3 ) {
|
if (serialCount >= 3 ) {
|
||||||
serialCount = 0;
|
serialCount = 0;
|
||||||
pixel_count++;
|
pixel_count++;
|
||||||
stroke(rgb[indexRed], rgb[indexGreen], rgb[indexBlue]);
|
stroke(rgb[indexRed], rgb[indexGreen], rgb[indexBlue],1000);
|
||||||
|
// We seem to get some pixel transparency so draw twice
|
||||||
|
point(xpos + x_offset, ypos + y_offset);
|
||||||
point(xpos + x_offset, ypos + y_offset);
|
point(xpos + x_offset, ypos + y_offset);
|
||||||
lastPixelTime = millis();
|
lastPixelTime = millis();
|
||||||
xpos++;
|
xpos++;
|
||||||
@@ -203,19 +206,15 @@ void draw() {
|
|||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
|
|
||||||
if (millis() > (lastPixelTime + pixelWaitTime))
|
if (millis() > (lastPixelTime + pixelWaitTime))
|
||||||
{
|
{
|
||||||
println("");
|
println("");
|
||||||
System.err.println("No response, trying again...");
|
System.err.println("No response, trying again...");
|
||||||
state = 4;
|
state = 4;
|
||||||
} else
|
|
||||||
{
|
|
||||||
// Request 64 more pixels (ESP8266 buffer size)
|
|
||||||
serial.write("RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR");
|
|
||||||
serial.write("RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Request 32pixels
|
||||||
|
serial.write("RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4: // Time-out, flush serial buffer
|
case 4: // Time-out, flush serial buffer
|
||||||
@@ -226,7 +225,7 @@ void draw() {
|
|||||||
{
|
{
|
||||||
serial.read();
|
serial.read();
|
||||||
}
|
}
|
||||||
state = 0;
|
state = 6;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 5: // Save the image tot he sketch folder
|
case 5: // Save the image tot he sketch folder
|
||||||
@@ -243,19 +242,25 @@ void draw() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
n = n + 1;
|
n = n + 1;
|
||||||
if (n>9) n = 0;
|
if (n>=max_images) n = 0;
|
||||||
drawLoopCount = 0; // Reset value ready for counting in step 6
|
drawLoopCount = 0; // Reset value ready for counting in step 6
|
||||||
state = 6;
|
state = 6;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 6: // Fade the old image if enabled
|
case 6: // Fade the old image if enabled
|
||||||
|
int opacity = drawLoopCount; // So we get increasing fade
|
||||||
|
if (drawLoopCount > 50) // End fade after 50 cycles
|
||||||
|
{
|
||||||
|
opacity = 255;
|
||||||
|
state = 0;
|
||||||
|
}
|
||||||
delay(10);
|
delay(10);
|
||||||
if (fade)
|
if (fade)
|
||||||
{
|
{
|
||||||
tint(255, drawLoopCount);
|
tint(255, opacity);
|
||||||
image(tft_img, x_offset, y_offset);
|
image(tft_img, x_offset, y_offset);
|
||||||
}
|
}
|
||||||
if (drawLoopCount > 50) state = 0; // Wait for fade to end
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 99: // Draw image viewer window
|
case 99: // Draw image viewer window
|
||||||
@@ -271,7 +276,7 @@ void draw() {
|
|||||||
|
|
||||||
rect(x_offset - border, y_offset - border, tft_width - 1 + 2*border, tft_height - 1 + 2*border);
|
rect(x_offset - border, y_offset - border, tft_width - 1 + 2*border, tft_height - 1 + 2*border);
|
||||||
|
|
||||||
fill(100);
|
fill(255);
|
||||||
rect(x_offset, y_offset, tft_width-1, tft_height-1);
|
rect(x_offset, y_offset, tft_width-1, tft_height-1);
|
||||||
|
|
||||||
state = 0;
|
state = 0;
|
||||||
@@ -282,4 +287,4 @@ void draw() {
|
|||||||
System.err.println("Error state reached - check sketch!");
|
System.err.println("Error state reached - check sketch!");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
BIN
Tools/Screenshot_client/example_1.png
Normal file
BIN
Tools/Screenshot_client/example_1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
BIN
Tools/Screenshot_client/example_2.png
Normal file
BIN
Tools/Screenshot_client/example_2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.8 KiB |
Reference in New Issue
Block a user