try: fb = open('/dev/fb0', 'rb') fcntl.ioctl(fb, FBIO_REFRESH, struct.pack('I', 0)) fb.close() except Exception as e: print(f"Refresh failed: e", file=sys.stderr) sys.exit(1) <?php // api.php - REST API for e-paper display header('Content-Type: application/json'); $display = new EPaperDisplay(800, 480);
$method = $_SERVER['REQUEST_METHOD']; $path = $_GET['path'] ?? '';
// Supported color modes const COLOR_BW = 1; // Black/White const COLOR_BWR = 2; // Black/White/Red const COLOR_BWY = 3; // Black/White/Yellow
/** * Load image from file */ public function loadImage($path) $extension = strtolower(pathinfo($path, PATHINFO_EXTENSION)); switch($extension) case 'jpg': case 'jpeg': return imagecreatefromjpeg($path); case 'png': return imagecreatefrompng($path); case 'bmp': return imagecreatefrombmp($path); default: throw new Exception("Unsupported image format: $extension"); epaper php script
/** * Generate frame buffer data */ public function generateFramebuffer($image) $buffer = ''; for ($y = 0; $y < $this->height; $y++) for ($x = 0; $x < $this->width; $x++) $b5; $buffer .= pack('v', $pixel); return $buffer;
<?php /** * E-Paper Display Management Script * Supports Waveshare, Pervasive Displays, and compatible e-paper screens */ class EPaperDisplay private $devicePath; private $width; private $height; private $rotation; private $colorMode;
private function handleTextDisplay() $text = $_POST['text']; $fontSize = $_POST['font_size'] ?? 24; try $this->display->displayText($text, $fontSize); $_SESSION['message'] = "Text displayed successfully!"; catch (Exception $e) $_SESSION['message'] = "Error: " . $e->getMessage(); try: fb = open('/dev/fb0', 'rb') fcntl
case 'display/text': if ($method === 'POST') $data = json_decode(file_get_contents('php://input'), true); $display->displayText($data['text'], $data['font_size'] ?? 24); echo json_encode(['success' => true]); break; case 'info': echo json_encode($display->getInfo()); break;
// Start session for messages session_start();
/** * Convert image to e-paper compatible format */ public function convertForEPaper($image) // Resize image to fit display $resized = imagecreatetruecolor($this->width, $this->height); imagecopyresampled($resized, $image, 0, 0, 0, 0, $this->width, $this->height, imagesx($image), imagesy($image)); // Apply dithering for better e-paper rendering if ($this->colorMode == self::COLOR_BW) imagefilter($resized, IMG_FILTER_GRAYSCALE); // Threshold for black/white for ($x = 0; $x < $this->width; $x++) for ($y = 0; $y < $this->height; $y++) $rgb = imagecolorat($resized, $x, $y); $gray = ($rgb >> 16) & 0xFF; $color = ($gray > 127) ? 255 : 0; imagesetpixel($resized, $x, $y, imagecolorallocate($resized, $color, $color, $color)); return $resized; $data['font_size'] ?? 24)
function handleImageAPI($display) // API image handling logic return ['success' => true];
// Slideshow $images = ['img1.jpg', 'img2.jpg', 'img3.jpg']; $display->displaySlideshow($images, 10);
public function __construct($width = 800, $height = 480, $colorMode = self::COLOR_BW) $this->width = $width; $this->height = $height; $this->colorMode = $colorMode; $this->rotation = 0; $this->devicePath = '/dev/fb0'; // Framebuffer device