-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
153 wcli screenshot
- Loading branch information
Showing
6 changed files
with
175 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,6 @@ | |
.vscode/launch.json | ||
.vscode/ipch | ||
.vscode/settings.json | ||
|
||
assets | ||
tools/*.raw | ||
tools/*.png |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#ifndef DISABLE_CLI | ||
#include "cli.hpp" | ||
#include "storage.hpp" | ||
#include "tft.hpp" | ||
|
||
#define SCREENSHOT_TEMP_FILE "/screenshot.raw" | ||
|
||
// Capture the screenshot and save it to the SD card | ||
void captureScreenshot(const char* filename, Stream *response) { | ||
File file = SD.open(filename, FILE_WRITE); | ||
if (!file) { | ||
response->println("Failed to open file for writing"); | ||
return; | ||
} | ||
|
||
// Allocate memory to store the screen data (1 byte per segment) | ||
uint8_t* buffer = (uint8_t*)malloc(tft.width() * tft.height() * 2); // 2 bytes per pixel | ||
if (!buffer) { | ||
response->println("Failed to allocate memory for buffer"); | ||
file.close(); | ||
return; | ||
} | ||
|
||
// Read the screen data into the buffer using readRect | ||
tft.readRect(0, 0, tft.width(), tft.height(), (uint16_t*)buffer); | ||
|
||
// Write the buffer data to the file | ||
for (int y = 0; y < tft.height(); y++) { | ||
for (int x = 0; x < tft.width(); x++) { | ||
// Combine the two 8-bit segments into a 16-bit value | ||
uint8_t highByte = buffer[(y * tft.width() + x) * 2]; | ||
uint8_t lowByte = buffer[(y * tft.width() + x) * 2 + 1]; | ||
uint16_t color = (highByte << 8) | lowByte; | ||
file.write((const uint8_t*)&color, sizeof(color)); | ||
} | ||
} | ||
|
||
// Clean up | ||
free(buffer); | ||
file.close(); | ||
response->println("Screenshot saved"); | ||
} | ||
|
||
// WiFi client | ||
WiFiClient client; | ||
|
||
void captureScreenshot(const char* filename, const char* pc_ip, uint16_t pc_port) { | ||
if (!client.connect(pc_ip, pc_port)) { | ||
Serial.println("Connection to server failed"); | ||
return; | ||
} | ||
|
||
Serial.println("Connected to server"); | ||
|
||
File file = SD.open(filename, FILE_READ); | ||
if (!file) { | ||
Serial.println("Failed to open file for reading"); | ||
client.stop(); | ||
return; | ||
} | ||
|
||
// Send the file data to the PC | ||
while (file.available()) { | ||
size_t size = 0; | ||
uint8_t buffer[512]; | ||
size = file.read(buffer, sizeof(buffer)); | ||
if (size > 0) { | ||
client.write(buffer, size); | ||
} | ||
} | ||
|
||
file.close(); | ||
client.stop(); | ||
Serial.println("Screenshot sent over WiFi"); | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from PIL import Image | ||
import numpy as np | ||
|
||
# Define image dimensions | ||
width = 320 | ||
height = 480 | ||
|
||
# Read the raw RGB565 file | ||
with open("screenshot.raw", "rb") as f: | ||
raw_data = f.read() | ||
|
||
# Convert the raw data to an array of 16-bit values (RGB565) | ||
pixels = np.frombuffer(raw_data, dtype=np.uint16) | ||
|
||
# Convert RGB565 to RGB888 | ||
def rgb565_to_rgb888(pixel): | ||
r = (pixel & 0xF800) >> 8 | ||
g = (pixel & 0x07E0) >> 3 | ||
b = (pixel & 0x001F) << 3 | ||
return (r, g, b) | ||
|
||
# Apply the conversion to all pixels | ||
rgb_data = np.array([rgb565_to_rgb888(pixel) for pixel in pixels], dtype=np.uint8) | ||
|
||
# Reshape to the correct dimensions | ||
rgb_data = rgb_data.reshape((height, width, 3)) | ||
|
||
# Create an image from the RGB data | ||
image = Image.fromarray(rgb_data) | ||
image.save("screenshot.png") |