Convert images for the Samsung EM32DX

Tags:

previously

Photo of the frame displaying an image

Now that I have a shell script to send images to my Eink display, I'm looking at improving the experience. Mostly by porting the tools to Perl to better integrate them with my other tools. But also, by making it more convenient to find and select new images to display on the screen.

Shell script

I want to build a good collection of images to display on the Eink display. As I often lose track of the filename of a very good looking image ( I'm already looking at it on the display and I like it, why should I bother with the filename? ), I've added logging to my interim shell script so that I have a log of files to go through and re-evaluate.

I'm using JSONL as the log format, not because it is especially easy to create from the shell, but it is highly convenient for later processing with other tools.

#!/usr/bin/perl
use 5.020;
use JSON::Tiny 'encode_json';
use Getopt::Long (qw(:config pass_through permute)); # stop at the first unknown option or first argument
use POSIX 'strftime';

my $result = {};

my $name;

GetOptions(
    '<>' => sub( $v ) { if( ! $name ) { $name = $v =~ s/^--//r; } else { $result->{$name} = $v; undef $name }; },
);

$result->{ timestamp } //= strftime '%Y-%m-%dT%H:%M:%SZ', gmtime();

say encode_json( $result );

I've also added bas64-encoded thumbnail images to the log lines so that I can easily display the logfile as an HTML page to better pick out good images or images to discard.

Screenshot of thumbnails from the logfile

Shell integration

After adding the appropriate file in ~/.local/share/applications/eink.desktop I can send any image to the frame by using a right-click. This is highly convenient and encourages me to quickly try out new images.

The Perl port of the sender script will likely use

  • Imager
    • error distribution errdiff quantization option
  • Mojolicious for communication
    • request/response mechanism, easily adapted into Future / Future::Mojo

I need to port the mdc Javascript module and create a test suite to properly encode the blobs.

MDC documentation PDF

While looking at the Javascript code, I found the official MDC documentation version 15.0 PDF from 2020-11-06 . This describes the actual protocol (serial, or over IP) in detail.

The command blocks are simple, consisting only of 8-bit bytes. This is a problem for payloads (like URLs) that are longer than 230 bytes. But for my use-case, that is no problem.

Request

| Header | Command | Display ID | Payload length | Payload | 8-bit checksum | | --- | --- | --- | --- | --- | --- | | 0xAA | . | . | . | . | 8-bit sum of payload |

Response

| Response | Header | Command | Display ID | Payload length | ACK / NACK | Payload | 8-bit checksum | | --- | --- | --- | --- | --- | --- | --- | --- | | 0xFF | 0xAA | . | . | . | "A" / "N" | . | (not verified) |

The inconvenient thing is that the length does not immediately precede the payload, so that unpack does not work. Instead I've used a regular expression to extract the parts.

The blobs are sent and received via port 1515. I have not found a way to change this port, but I'm not sure why I would want that.

Program structure

The program to change the image would then

  • Spin up a webserver ( Mojo::Server::Daemon
  • send the URL with code 0x53 / 0x80
  • wait for playlist and image(s) to be fetched
  • done