aboutsummaryrefslogtreecommitdiff
path: root/guile/starlet/base.scm
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2021-03-21 11:03:45 +0100
committerThomas White <taw@physics.org>2021-03-28 10:20:28 +0200
commitf6accbde30843bf60595f93a83b3bf2c86109859 (patch)
tree4325dab086492d549831cb2d68d71bfc54b104da /guile/starlet/base.scm
parente765bccaa048ed22a429cde6088449216b0dc6e1 (diff)
Add some error checking
Diffstat (limited to 'guile/starlet/base.scm')
-rw-r--r--guile/starlet/base.scm35
1 files changed, 27 insertions, 8 deletions
diff --git a/guile/starlet/base.scm b/guile/starlet/base.scm
index d378457..a7a1af0 100644
--- a/guile/starlet/base.scm
+++ b/guile/starlet/base.scm
@@ -5,6 +5,7 @@
#:use-module (ice-9 atomic)
#:use-module (ice-9 receive)
#:use-module (ice-9 pretty-print)
+ #:use-module (ice-9 exceptions)
#:use-module (web client)
#:use-module (web http)
#:use-module (web uri)
@@ -396,13 +397,19 @@ pre-existing contents."
;; Helper function for scanout functions to set individual DMX values
(define (set-dmx universe addr value)
+ (unless (number? value)
+ (raise-exception (make-exception
+ (make-exception-with-message
+ "Attempt to set non-number DMX value")
+ (make-exception-with-irritants
+ (list universe addr value)))))
+
;; Create DMX array for universe if it doesn't exist already
(unless (assq universe universes)
(set! universes (acons universe
(make-u8vector 512 0)
universes)))
- ;; Set the value in the DMX array
(u8vector-set! (assq-ref universes universe)
(- addr 1) ; u8vector-set indexing starts from zero
(round-dmx value)))
@@ -431,16 +438,28 @@ pre-existing contents."
;; Helper function to set 8-bit DMX value
(define (set-chan relative-channel-number value)
- (when value
- (set-dmx univ
- (+ addr relative-channel-number -1)
- value)))
+
+ (unless (number? value)
+ (raise-exception (make-exception
+ (make-exception-with-message
+ "set-chan: value is not a number")
+ (make-exception-with-irritants
+ (list relative-channel-number value)))))
+ (set-dmx univ
+ (+ addr relative-channel-number -1)
+ value))
;; Helper function to set 16-bit DMX value
(define (set-chan-16bit relative-channel-number value)
- (when value
- (set-chan relative-channel-number (msb value))
- (set-chan (+ relative-channel-number 1) (lsb value))))
+ (unless (number? value)
+ (raise-exception (make-exception
+ (make-exception-with-message
+ "set-chan16: value is not a number")
+ (make-exception-with-irritants
+ (list relative-channel-number
+ value)))))
+ (set-chan relative-channel-number (msb value))
+ (set-chan (+ relative-channel-number 1) (lsb value)))
(scanout-fixture fix get-attr set-chan set-chan-16bit)))