From 6da42d558e7cc5013f11d9f6ac0638f1e3b62bb7 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Fri, 7 Jul 2023 23:41:19 -0700 Subject: Add custom wrapping function for displaying text Setting text wrapping to true will wrap the text to the beginning of the line again. This function just returns a list of strings that can be tweaked to provide the lists of the right length, this way I can make sure that the text continues in the right place on the next line. --- inkplate-display | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/inkplate-display b/inkplate-display index 2c7b3ab..6ad7f03 100755 --- a/inkplate-display +++ b/inkplate-display @@ -17,7 +17,21 @@ ;; this program. If not, see . (use-modules ((inkplate) #:prefix inkplate:) - (srfi srfi-19)) + (srfi srfi-19) + (srfi srfi-1)) + +(define (my-wrap text max-length) + (reverse + (map string-trim + (fold + (λ (item accumulator) + (let* ((current-line (car accumulator)) + (new-line (format #f "~a ~a" current-line item))) + (if (> (string-length new-line) max-length) + (cons item accumulator) + (cons new-line (cdr accumulator))))) + '("") + (string-split text #\ ))))) (let* ((my-dev (inkplate:open "/dev/ttyUSB0")) (date (current-date)) @@ -100,19 +114,20 @@ (inkplate:set-text-size my-dev 4) (inkplate:print my-dev (inkplate:convert-string-to-hex "S"))) - (inkplate:set-cursor my-dev 265 15) (inkplate:set-text-size my-dev 3) (inkplate:set-text-wrap my-dev #f) - (inkplate:print my-dev (inkplate:convert-string-to-hex "Choose your own tempo for an")) - (inkplate:set-cursor my-dev 265 45) - (inkplate:set-text-size my-dev 3) - (inkplate:set-text-wrap my-dev #f) - (inkplate:print my-dev (inkplate:convert-string-to-hex "email conversation")) + (let loop ((lines (my-wrap "Give yourself permission to fail; it's the path to success" 29)) + (x 265) + (y 15)) + (inkplate:set-cursor my-dev x y) + (inkplate:print my-dev (inkplate:convert-string-to-hex (car lines))) + (unless (null? (cdr lines)) + (loop (cdr lines) x (+ 30 y)))) (if (member "--reset" (command-line)) (inkplate:update my-dev) (inkplate:partial-update my-dev 15 800 600)) - (inkplate:send my-dev) + (inkplate:send my-dev) (inkplate:close my-dev)) -- cgit v1.2.3-54-g00ecf