From 239587824837021e77f78a67b4c7e3d87ed8f1dc Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Thu, 6 Jul 2023 23:23:41 -0700 Subject: Restructure project as suggested by running ‘hall init --convert’ --- COPYING | 3 + HACKING | 47 +++++++++ README | 1 + doc/inkplate.texi | 60 +++++++++++ hall.scm | 26 +++++ inkplate.scm | 286 ++++++++++++++++++++++++++++++++++++++++++++++++++ inkplate/lowlevel.scm | 286 -------------------------------------------------- tests/inkplate.scm | 2 +- 8 files changed, 424 insertions(+), 287 deletions(-) create mode 100644 COPYING create mode 100644 HACKING create mode 120000 README create mode 100644 doc/inkplate.texi create mode 100644 hall.scm create mode 100644 inkplate.scm delete mode 100644 inkplate/lowlevel.scm diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..f658e91 --- /dev/null +++ b/COPYING @@ -0,0 +1,3 @@ +This project's license is GPL 3+. + +You can read the full license at https://www.gnu.org/licenses/gpl.html. diff --git a/HACKING b/HACKING new file mode 100644 index 0000000..31a3272 --- /dev/null +++ b/HACKING @@ -0,0 +1,47 @@ +# -*- mode: org; coding: utf-8; -*- + +#+TITLE: Hacking inkplate + +* Contributing + +By far the easiest way to hack on inkplate is to develop using Guix: + +#+BEGIN_SRC bash + # Obtain the source code + cd /path/to/source-code + guix environment -l guix.scm + # In the new shell, run: + hall dist --execute && autoreconf -vif && ./configure && make check +#+END_SRC + +You can now hack this project's files to your heart's content, whilst +testing them from your `guix environment' shell. + +To try out any scripts in the project you can now use + +#+BEGIN_SRC bash + ./pre-inst-env scripts/${script-name} +#+END_SRC + +If you'd like to tidy the project again, but retain the ability to test the +project from the commandline, simply run: + +#+BEGIN_SRC bash + ./hall clean --skip "scripts/${script-name},pre-inst-env" --execute +#+END_SRC + +** Manual Installation + +If you do not yet use Guix, you will have to install this project's +dependencies manually: + - autoconf + - automake + - pkg-config + - texinfo + - guile-hall + +Once those dependencies are installed you can run: + +#+BEGIN_SRC bash + hall dist -x && autoreconf -vif && ./configure && make check +#+END_SRC diff --git a/README b/README new file mode 120000 index 0000000..314e17d --- /dev/null +++ b/README @@ -0,0 +1 @@ +README.org \ No newline at end of file diff --git a/doc/inkplate.texi b/doc/inkplate.texi new file mode 100644 index 0000000..259ece8 --- /dev/null +++ b/doc/inkplate.texi @@ -0,0 +1,60 @@ +\input texinfo +@c -*-texinfo-*- + +@c %**start of header +@setfilename guile-inkplate.info +@documentencoding UTF-8 +@settitle Guile Inkplate Reference Manual +@c %**end of header + +@include version.texi + +@copying +Copyright @copyright{} 2023 Tom Willemse + +Permission is granted to copy, distribute and/or modify this document +under the terms of the GNU Free Documentation License, Version 1.3 or +any later version published by the Free Software Foundation; with no +Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A +copy of the license is included in the section entitled ``GNU Free +Documentation License''. +@end copying + +@dircategory The Algorithmic Language Scheme +@direntry +* Guile Inkplate: (guile-inkplate). +@end direntry + +@titlepage +@title The Guile Inkplate Manual +@author Tom Willemse + +@page +@vskip 0pt plus 1filll +Edition @value{EDITION} @* +@value{UPDATED} @* + +@insertcopying +@end titlepage + +@contents + +@c ********************************************************************* +@node Top +@top Guile Inkplate + +This document describes Guile Inkplate version @value{VERSION}. + +@menu +* Introduction:: Why Guile Inkplate? +@end menu + +@c ********************************************************************* +@node Introduction +@chapter Introduction + +INTRODUCTION HERE + +This documentation is a stub. + +@bye diff --git a/hall.scm b/hall.scm new file mode 100644 index 0000000..09b9578 --- /dev/null +++ b/hall.scm @@ -0,0 +1,26 @@ +(hall-description + (name "inkplate") + (prefix "guile") + (version "0.1") + (author "Tom Willemse") + (copyright (2023)) + (synopsis "") + (description "") + (home-page "") + (license gpl3+) + (dependencies `()) + (skip ()) + (files (libraries ((scheme-file "inkplate"))) + (tests ((directory "tests" ((scheme-file "inkplate"))))) + (programs ((directory "scripts" ()))) + (documentation + ((directory "doc" ((texi-file "inkplate"))) + (text-file "COPYING") + (text-file "HACKING") + (symlink "README" "README.org") + (org-file "README"))) + (infrastructure + ((directory "build-aux" ()) + (scheme-file "hall") + (text-file ".gitignore") + (scheme-file "guix"))))) diff --git a/inkplate.scm b/inkplate.scm new file mode 100644 index 0000000..d068455 --- /dev/null +++ b/inkplate.scm @@ -0,0 +1,286 @@ +(define-module (inkplate) + #:use-module ((ice-9 format) #:select (format)) + #:use-module ((srfi srfi-9) #:select (define-record-type)) + + #:export ( + make-inkplate + inkplate? + inkplate-input-port + inkplate-output-port + + convert-string-to-hex + + open + close + echo + draw-pixel + draw-line + draw-fast-vertical-line + draw-fast-horizontal-line + draw-rectangle + draw-circle + draw-triangle + draw-rounded-rectangle + fill-rectangle + fill-circle + fill-triangle + fill-rounded-rectangle + print + set-text-size + set-cursor + set-text-wrap + set-rotation + draw-bitmap + set-display-mode + get-display-mode + clear-screen + update + partial-update + read-temperature + read-touchpad + read-battery + panel-supply + get-panel-state + draw-image + draw-thick-line + draw-ellipse + fill-ellipse + send)) + +(define-record-type + (make-inkplate input-port output-port) + inkplate? + (input-port inkplate-input-port) + (output-port inkplate-output-port)) + +(define (convert-string-to-hex string) + "Convert STRING to a hexadecimal representation of the text." + (string-join + (map (lambda (x) (format #f "~2,'0x" (char->integer x))) + (string->list string)) + "")) + +(define (open device-path) + "Open a connection to an Inkplate on the named DEVICE-PATH." + (let ((port (open-file device-path "r+"))) + (make-inkplate port port))) + +(define (close device) + "Close a connection to an Inkplate in DEVICE." + (close-port (inkplate-output-port device)) + (close-port (inkplate-input-port device))) + +(define (echo device) + "Send a command to check if the DEVICE is receiving commands." + (display "#?*" (inkplate-output-port device))) + +(define (draw-pixel device x y color) + "Draw a pixel on DEVICE at coordinates X and Y in COLOR." + (format (inkplate-output-port device) "#0(~3,'0d,~3,'0d,~2,'0d)*" x y color)) + +(define (draw-line device x1 y1 x2 y2 color) + "Draw a line on DEVICE from coordinates X1,Y1 to X2,Y2 in COLOR." + (format (inkplate-output-port device) + "#1(~3,'0d,~3,'0d,~3,'0d,~3,'0d,~2,'0d)*" x1 y1 x2 y2 color)) + +(define (draw-fast-vertical-line device x y length color) + "Draw a vertical line on DEVICE from X,Y for LENGTH pixels in COLOR." + (format (inkplate-output-port device) + "#2(~3,'0d,~3,'0d,~3,'0d,~2,'0d)*" x y length color)) + +(define (draw-fast-horizontal-line device x y length color) + "Draw a horizontal line on DEVICE from X,Y for LENGTH pixels in COLOR." + (format (inkplate-output-port device) + "#3(~3,'0d,~3,'0d,~3,'0d,~2,'0d)*" x y length color)) + +(define (draw-rectangle device x y width height color) + "Draw a rectangle on DEVICE at X,Y WIDTH wide by HEIGHT high in COLOR. +This function draws an outline of a rectangle whereas ‘fill-rectangle’ fills the +rectangle with the specified color." + (format (inkplate-output-port device) + "#4(~3,'0d,~3,'0d,~3,'0d,~3,'0d,~2,'0d)*" x y width height color)) + +(define (draw-circle device x y radius color) + "Draw a circle on DEVICE at X,Y with RADIUS in COLOR. +This function draws an outline of a circle whereas ‘fill-circle’ fills the +circle with the specified color." + (format (inkplate-output-port device) + "#5(~3,'0d,~3,'0d,~3,'0d,~2,'0d)*" x y radius color)) + +(define (draw-triangle device x1 y1 x2 y2 x3 y3 color) + "Draw a triangle on DEVICE at points X1,Y1, X2,Y2, and X3,Y3 in COLOR. +This function draws an outline of a triangle whereas ‘fill-triangle’ fills the +triangle with the specified color." + (format (inkplate-output-port device) + "#6(~3,'0d,~3,'0d,~3,'0d,~3,'0d,~3,'0d,~3,'0d,~2,'0d)*" + x1 y1 x2 y2 x3 y3 color)) + +(define (draw-rounded-rectangle device x y width height radius color) + "Draw a rounded rectangle on DEVICE at X,Y WIDTH wide by HEIGHT high. +RADIUS is the radius of the rounded corners. Draw the rectangle in COLOR." + (format (inkplate-output-port device) + "#7(~3,'0d,~3,'0d,~3,'0d,~3,'0d,~3,'0d,~2,'0d)*" + x y width height radius color)) + +(define (fill-rectangle device x y width height color) + "Draw a rectangle on DEVICE at X,Y WIDTH wide by HEIGHT high in COLOR. +This function fills the entire rectangle with COLOR while ‘draw-rectangle’ only +draws an outline." + (format (inkplate-output-port device) + "#8(~3,'0d,~3,'0d,~3,'0d,~3,'0d,~2,'0d)*" x y width height color)) + +(define (fill-circle device x y radius color) + "Draw a circle on DEVICE at X,Y with RADIUS. +This function fills the entire circle with COLOR while ‘draw-circle’ only draws +an outline." + (format (inkplate-output-port device) + "#9(~3,'0d,~3,'0d,~3,'0d,~2,'0d)*" x y radius color)) + +(define (fill-triangle device x1 y1 x2 y2 x3 y3 color) + "Draw a triangle on DEVICE at points X1,Y1, X2,Y2, and X3,Y3 in COLOR. +This function fills the entire triangle with COLOR while ‘draw-triangle’ only +draws an outline." + (format (inkplate-output-port device) + "#A(~3,'0d,~3,'0d,~3,'0d,~3,'0d,~3,'0d,~3,'0d,~2,'0d)*" + x1 y1 x2 y2 x3 y3 color)) + +(define (fill-rounded-rectangle device x y width height radius color) + "Draw a rounded rectangle on DEVICE at X,Y WIDTH wide by HEIGHT high. +CORNER-RADIUS is the radius of the rounded corners. Fill the rectangle with +COLOR." + (format (inkplate-output-port device) + "#B(~3,'0d,~3,'0d,~3,'0d,~3,'0d,~3,'0d,~2,'0d)*" + x y width height radius color)) + +(define (print device text) + "Print the TEXT onto the screen of DEVICE. +TEXT should be a hex string as produced by ‘convert-string-to-hex’." + (format (inkplate-output-port device) "#C(~s)*" text)) + +(define (set-text-size device size) + "Set the text size for the next print command to SIZE for DEVICE." + (format (inkplate-output-port device) "#D(~2,'0d)*" size)) + +(define (set-cursor device x y) + "Move the cursor on DEVICE to the X and Y coordinates." + (format (inkplate-output-port device) "#E(~3,'0d,~3,'0d)*" x y)) + +(define (set-text-wrap device enable) + "Enable or disable text wrapping on DEVICE depending on the value of ENABLE. +If ENABLE is #t, enable text wrapping. Otherwise disable it." + (format (inkplate-output-port device) "#F(~a)*" (if enable "T" "F"))) + +(define (set-rotation device rotation) + "Set the screen rotation on DEVICE. +ROTATION can be one of: +- 0: 0 degrees rotation +- 1: 90 degrees rotation +- 2: 180 degrees rotation +- 3: 270 degrees rotation" + (format (inkplate-output-port device) "#G(~3,'0d)*" rotation)) + +(define (draw-bitmap device x y path) + "Draw a bitmap on DEVICE at coordinates X,Y. +PATH should be a path on the SD card and should be a hex string +as produced by ‘inkplate--convert-string-to-hex’. This command +puts a response in the output buffer. It should be one of: + +- #H(0)*: Image load failed +- #H(1)*: Image loaded successfully +- #H(-1)*: SD Card Init Error" + (format (inkplate-output-port device) "#H(~3,'0d,~3,'0d,~s)*" x y path)) + +(define (set-display-mode device mode) + "Set the display mode for DEVICE to MODE. +Mode can be one of: +- 1: 1-bit mode +- 3: 3-bit mode" + (format (inkplate-output-port device) "#I(~d)*" mode)) + +(define (get-display-mode device) + "Query the DEVICE for which display mode is active. + +This puts one of the following responses into the output buffer: +- #J(0): 1-bit mode +- #J(1): 3-bit mode" + (display "#J(?)*" (inkplate-output-port device))) + +(define (clear-screen device) + "Send the command to clear the screen to DEVICE." + (display "#K(1)*" (inkplate-output-port device))) + +(define (update device) + "Send the command to update the display to DEVICE." + (display "#L(1)*" (inkplate-output-port device))) + +(define (partial-update device yy1 xx2 yy2) + "Send the command to update the display to DEVICE. +Tell it to only do a partial update." + ;; I guess that xx1 is implicitly 0? It's not mentioned in the documentation. + (format (inkplate-output-port device) "#M(~3,'0d,~3,'0d,~3,'0d)*" yy1 xx2 yy2)) + +(define (read-temperature device) + "Query DEVICE for its current temperature. +This will produce a response in the output buffer in the form or #N(22)* which +means its temperature is 22 degrees Celsius." + (display "#N(?)*" (inkplate-output-port device))) + +(define (read-touchpad device touchpad) + "Query DEVICE for the state of TOUCHPAD. +TOUCHPAD can be 1, 2, or 3. This will produce a response in the +output buffer which can be read with ‘inkplate-read-output’. +Possible responses are: +- #O(1)*: The touch pad is in the high state +- #O(0)*: The touch pad is in the low state" + (format (inkplate-output-port device) "#O(~d)*" touchpad)) + +(define (read-battery device) + "Query DEVICE for the current voltage on the battery. +This produces a response in the output buffer which can be read using +‘read-output’. The response is in the form of #P(3.65)* meaning the measured +voltage on the battery is 3.65VDC." + (display "#P(?)*" (inkplate-output-port device))) + +(define (panel-supply device enable) + "Turn DEVICE on or off depending on the value of ENABLE. +If ENABLE is #t turn DEVICE on, otherwise turn it off." + (format (inkplate-output-port device) "#Q(~d)*" (if enable 1 0))) + +(define (get-panel-state device) + "Query DEVICE for the state of the panel. +This command produces a response in the output buffer which can be read using +‘read-output’. The response can be one of: + +- #R(1)*: Panel has power +- #R(0)*: Panel has no power" + (display "#R(?)*" (inkplate-output-port device))) + +(define (draw-image device x y path) + "Draw an image on DEVICE at coordinates X,Y. +PATH should be a path on the SD card and a hex string as produced by +‘convert-string-to-hex’." + (format (inkplate-output-port device) "#S(~3,'0d,~3,'0d,~s)*" x y path)) + +(define (draw-thick-line device x1 y1 x2 y2 thickness color) + "Draw a line on DEVICE from X1,Y1 to X2,Y2 in THICKNESS and COLOR." + (format (inkplate-output-port device) + "#T(~3,'0d,~3,'0d,~3,'0d,~3,'0d,~2,'0d,~2,'0d)*" + x1 y1 x2 y2 thickness color)) + +(define (draw-ellipse device x y x-radius y-radius color) + "Draw an ellipse on DEVICE at coordinates X,Y. +X-RADIUS and Y-RADIUS specify the x and y radius of the ellipse. Draw it in +COLOR." + (format (inkplate-output-port device) + "#U(~3,'0d,~3,'0d,~3,'0d,~3,'0d,~2,'0d)*" x y x-radius y-radius color)) + +(define (fill-ellipse device x y x-radius y-radius color) + "Draw and fill an ellipse on DEVICE at coordinates X,Y. +X-RADIUS and Y-RADIUS specify the x and y radius of the ellipse. Draw it in +COLOR." + (format (inkplate-output-port device) + "#V(~3,'0d,~3,'0d,~3,'0d,~3,'0d,~2,'0d)*" x y x-radius y-radius color)) + +(define (send device) + "Send the accumulated commands to DEVICE." + (force-output (inkplate-output-port device))) diff --git a/inkplate/lowlevel.scm b/inkplate/lowlevel.scm deleted file mode 100644 index c26daa7..0000000 --- a/inkplate/lowlevel.scm +++ /dev/null @@ -1,286 +0,0 @@ -(define-module (inkplate lowlevel) - #:use-module ((ice-9 format) #:select (format)) - #:use-module ((srfi srfi-9) #:select (define-record-type)) - - #:export ( - make-inkplate - inkplate? - inkplate-input-port - inkplate-output-port - - convert-string-to-hex - - open - close - echo - draw-pixel - draw-line - draw-fast-vertical-line - draw-fast-horizontal-line - draw-rectangle - draw-circle - draw-triangle - draw-rounded-rectangle - fill-rectangle - fill-circle - fill-triangle - fill-rounded-rectangle - print - set-text-size - set-cursor - set-text-wrap - set-rotation - draw-bitmap - set-display-mode - get-display-mode - clear-screen - update - partial-update - read-temperature - read-touchpad - read-battery - panel-supply - get-panel-state - draw-image - draw-thick-line - draw-ellipse - fill-ellipse - send)) - -(define-record-type - (make-inkplate input-port output-port) - inkplate? - (input-port inkplate-input-port) - (output-port inkplate-output-port)) - -(define (convert-string-to-hex string) - "Convert STRING to a hexadecimal representation of the text." - (string-join - (map (lambda (x) (format #f "~2,'0x" (char->integer x))) - (string->list string)) - "")) - -(define (open device-path) - "Open a connection to an Inkplate on the named DEVICE-PATH." - (let ((port (open-file device-path "r+"))) - (make-inkplate port port))) - -(define (close device) - "Close a connection to an Inkplate in DEVICE." - (close-port (inkplate-output-port device)) - (close-port (inkplate-input-port device))) - -(define (echo device) - "Send a command to check if the DEVICE is receiving commands." - (display "#?*" (inkplate-output-port device))) - -(define (draw-pixel device x y color) - "Draw a pixel on DEVICE at coordinates X and Y in COLOR." - (format (inkplate-output-port device) "#0(~3,'0d,~3,'0d,~2,'0d)*" x y color)) - -(define (draw-line device x1 y1 x2 y2 color) - "Draw a line on DEVICE from coordinates X1,Y1 to X2,Y2 in COLOR." - (format (inkplate-output-port device) - "#1(~3,'0d,~3,'0d,~3,'0d,~3,'0d,~2,'0d)*" x1 y1 x2 y2 color)) - -(define (draw-fast-vertical-line device x y length color) - "Draw a vertical line on DEVICE from X,Y for LENGTH pixels in COLOR." - (format (inkplate-output-port device) - "#2(~3,'0d,~3,'0d,~3,'0d,~2,'0d)*" x y length color)) - -(define (draw-fast-horizontal-line device x y length color) - "Draw a horizontal line on DEVICE from X,Y for LENGTH pixels in COLOR." - (format (inkplate-output-port device) - "#3(~3,'0d,~3,'0d,~3,'0d,~2,'0d)*" x y length color)) - -(define (draw-rectangle device x y width height color) - "Draw a rectangle on DEVICE at X,Y WIDTH wide by HEIGHT high in COLOR. -This function draws an outline of a rectangle whereas ‘fill-rectangle’ fills the -rectangle with the specified color." - (format (inkplate-output-port device) - "#4(~3,'0d,~3,'0d,~3,'0d,~3,'0d,~2,'0d)*" x y width height color)) - -(define (draw-circle device x y radius color) - "Draw a circle on DEVICE at X,Y with RADIUS in COLOR. -This function draws an outline of a circle whereas ‘fill-circle’ fills the -circle with the specified color." - (format (inkplate-output-port device) - "#5(~3,'0d,~3,'0d,~3,'0d,~2,'0d)*" x y radius color)) - -(define (draw-triangle device x1 y1 x2 y2 x3 y3 color) - "Draw a triangle on DEVICE at points X1,Y1, X2,Y2, and X3,Y3 in COLOR. -This function draws an outline of a triangle whereas ‘fill-triangle’ fills the -triangle with the specified color." - (format (inkplate-output-port device) - "#6(~3,'0d,~3,'0d,~3,'0d,~3,'0d,~3,'0d,~3,'0d,~2,'0d)*" - x1 y1 x2 y2 x3 y3 color)) - -(define (draw-rounded-rectangle device x y width height radius color) - "Draw a rounded rectangle on DEVICE at X,Y WIDTH wide by HEIGHT high. -RADIUS is the radius of the rounded corners. Draw the rectangle in COLOR." - (format (inkplate-output-port device) - "#7(~3,'0d,~3,'0d,~3,'0d,~3,'0d,~3,'0d,~2,'0d)*" - x y width height radius color)) - -(define (fill-rectangle device x y width height color) - "Draw a rectangle on DEVICE at X,Y WIDTH wide by HEIGHT high in COLOR. -This function fills the entire rectangle with COLOR while ‘draw-rectangle’ only -draws an outline." - (format (inkplate-output-port device) - "#8(~3,'0d,~3,'0d,~3,'0d,~3,'0d,~2,'0d)*" x y width height color)) - -(define (fill-circle device x y radius color) - "Draw a circle on DEVICE at X,Y with RADIUS. -This function fills the entire circle with COLOR while ‘draw-circle’ only draws -an outline." - (format (inkplate-output-port device) - "#9(~3,'0d,~3,'0d,~3,'0d,~2,'0d)*" x y radius color)) - -(define (fill-triangle device x1 y1 x2 y2 x3 y3 color) - "Draw a triangle on DEVICE at points X1,Y1, X2,Y2, and X3,Y3 in COLOR. -This function fills the entire triangle with COLOR while ‘draw-triangle’ only -draws an outline." - (format (inkplate-output-port device) - "#A(~3,'0d,~3,'0d,~3,'0d,~3,'0d,~3,'0d,~3,'0d,~2,'0d)*" - x1 y1 x2 y2 x3 y3 color)) - -(define (fill-rounded-rectangle device x y width height radius color) - "Draw a rounded rectangle on DEVICE at X,Y WIDTH wide by HEIGHT high. -CORNER-RADIUS is the radius of the rounded corners. Fill the rectangle with -COLOR." - (format (inkplate-output-port device) - "#B(~3,'0d,~3,'0d,~3,'0d,~3,'0d,~3,'0d,~2,'0d)*" - x y width height radius color)) - -(define (print device text) - "Print the TEXT onto the screen of DEVICE. -TEXT should be a hex string as produced by ‘convert-string-to-hex’." - (format (inkplate-output-port device) "#C(~s)*" text)) - -(define (set-text-size device size) - "Set the text size for the next print command to SIZE for DEVICE." - (format (inkplate-output-port device) "#D(~2,'0d)*" size)) - -(define (set-cursor device x y) - "Move the cursor on DEVICE to the X and Y coordinates." - (format (inkplate-output-port device) "#E(~3,'0d,~3,'0d)*" x y)) - -(define (set-text-wrap device enable) - "Enable or disable text wrapping on DEVICE depending on the value of ENABLE. -If ENABLE is #t, enable text wrapping. Otherwise disable it." - (format (inkplate-output-port device) "#F(~a)*" (if enable "T" "F"))) - -(define (set-rotation device rotation) - "Set the screen rotation on DEVICE. -ROTATION can be one of: -- 0: 0 degrees rotation -- 1: 90 degrees rotation -- 2: 180 degrees rotation -- 3: 270 degrees rotation" - (format (inkplate-output-port device) "#G(~3,'0d)*" rotation)) - -(define (draw-bitmap device x y path) - "Draw a bitmap on DEVICE at coordinates X,Y. -PATH should be a path on the SD card and should be a hex string -as produced by ‘inkplate--convert-string-to-hex’. This command -puts a response in the output buffer. It should be one of: - -- #H(0)*: Image load failed -- #H(1)*: Image loaded successfully -- #H(-1)*: SD Card Init Error" - (format (inkplate-output-port device) "#H(~3,'0d,~3,'0d,~s)*" x y path)) - -(define (set-display-mode device mode) - "Set the display mode for DEVICE to MODE. -Mode can be one of: -- 1: 1-bit mode -- 3: 3-bit mode" - (format (inkplate-output-port device) "#I(~d)*" mode)) - -(define (get-display-mode device) - "Query the DEVICE for which display mode is active. - -This puts one of the following responses into the output buffer: -- #J(0): 1-bit mode -- #J(1): 3-bit mode" - (display "#J(?)*" (inkplate-output-port device))) - -(define (clear-screen device) - "Send the command to clear the screen to DEVICE." - (display "#K(1)*" (inkplate-output-port device))) - -(define (update device) - "Send the command to update the display to DEVICE." - (display "#L(1)*" (inkplate-output-port device))) - -(define (partial-update device yy1 xx2 yy2) - "Send the command to update the display to DEVICE. -Tell it to only do a partial update." - ;; I guess that xx1 is implicitly 0? It's not mentioned in the documentation. - (format (inkplate-output-port device) "#M(~3,'0d,~3,'0d,~3,'0d)*" yy1 xx2 yy2)) - -(define (read-temperature device) - "Query DEVICE for its current temperature. -This will produce a response in the output buffer in the form or #N(22)* which -means its temperature is 22 degrees Celsius." - (display "#N(?)*" (inkplate-output-port device))) - -(define (read-touchpad device touchpad) - "Query DEVICE for the state of TOUCHPAD. -TOUCHPAD can be 1, 2, or 3. This will produce a response in the -output buffer which can be read with ‘inkplate-read-output’. -Possible responses are: -- #O(1)*: The touch pad is in the high state -- #O(0)*: The touch pad is in the low state" - (format (inkplate-output-port device) "#O(~d)*" touchpad)) - -(define (read-battery device) - "Query DEVICE for the current voltage on the battery. -This produces a response in the output buffer which can be read using -‘read-output’. The response is in the form of #P(3.65)* meaning the measured -voltage on the battery is 3.65VDC." - (display "#P(?)*" (inkplate-output-port device))) - -(define (panel-supply device enable) - "Turn DEVICE on or off depending on the value of ENABLE. -If ENABLE is #t turn DEVICE on, otherwise turn it off." - (format (inkplate-output-port device) "#Q(~d)*" (if enable 1 0))) - -(define (get-panel-state device) - "Query DEVICE for the state of the panel. -This command produces a response in the output buffer which can be read using -‘read-output’. The response can be one of: - -- #R(1)*: Panel has power -- #R(0)*: Panel has no power" - (display "#R(?)*" (inkplate-output-port device))) - -(define (draw-image device x y path) - "Draw an image on DEVICE at coordinates X,Y. -PATH should be a path on the SD card and a hex string as produced by -‘convert-string-to-hex’." - (format (inkplate-output-port device) "#S(~3,'0d,~3,'0d,~s)*" x y path)) - -(define (draw-thick-line device x1 y1 x2 y2 thickness color) - "Draw a line on DEVICE from X1,Y1 to X2,Y2 in THICKNESS and COLOR." - (format (inkplate-output-port device) - "#T(~3,'0d,~3,'0d,~3,'0d,~3,'0d,~2,'0d,~2,'0d)*" - x1 y1 x2 y2 thickness color)) - -(define (draw-ellipse device x y x-radius y-radius color) - "Draw an ellipse on DEVICE at coordinates X,Y. -X-RADIUS and Y-RADIUS specify the x and y radius of the ellipse. Draw it in -COLOR." - (format (inkplate-output-port device) - "#U(~3,'0d,~3,'0d,~3,'0d,~3,'0d,~2,'0d)*" x y x-radius y-radius color)) - -(define (fill-ellipse device x y x-radius y-radius color) - "Draw and fill an ellipse on DEVICE at coordinates X,Y. -X-RADIUS and Y-RADIUS specify the x and y radius of the ellipse. Draw it in -COLOR." - (format (inkplate-output-port device) - "#V(~3,'0d,~3,'0d,~3,'0d,~3,'0d,~2,'0d)*" x y x-radius y-radius color)) - -(define (send device) - "Send the accumulated commands to DEVICE." - (force-output (inkplate-output-port device))) diff --git a/tests/inkplate.scm b/tests/inkplate.scm index fb18199..989a065 100644 --- a/tests/inkplate.scm +++ b/tests/inkplate.scm @@ -1,5 +1,5 @@ (use-modules (srfi srfi-64) - (inkplate lowlevel)) + (inkplate)) (define* (call-with-test-device func #:key (input-string "")) (let ((device (make-inkplate (open-input-string input-string) (open-output-string)))) -- cgit v1.3-2-g0d8e