aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tom Willemse2023-07-07 23:41:19 -0700
committerGravatar Tom Willemse2023-07-07 23:41:19 -0700
commit6da42d558e7cc5013f11d9f6ac0638f1e3b62bb7 (patch)
tree1881d8c927bbcd3bc2a805a8725fa95a570854ca
parent48ce1ba15723ddb3807ee681729d330d3972a155 (diff)
downloadinkplate-display-6da42d558e7cc5013f11d9f6ac0638f1e3b62bb7.tar.gz
inkplate-display-6da42d558e7cc5013f11d9f6ac0638f1e3b62bb7.zip
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.
-rwxr-xr-xinkplate-display31
1 files 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 <https://www.gnu.org/licenses/>.
(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))