(if (or (< lat -90) (< 90 lat))
(error "Invalid latitude:" lat))
(if (or (< long -180) (< 180 long))
- (error "INvalid longitude:" long))
+ (error "Invalid longitude:" long))
(queue! 'turn-to lat long)))
((eq? keyword 'TIME-TO)
- (let ((time (car args)))
- (if (not (eq? time 'current))
- (guarantee-integer time 'time-to))
- (queue! 'time-to time)))
+ (queue! 'time-to (->time (car args))))
((eq? keyword 'HOUR-TO)
(let ((hour (car args)))
(guarantee-integer hour 'hour-to)
(queue! queue 'go))
(else (error "unknown command:" keyword args))))))
+(define (->time object)
+ (cond ((eq? object 'current)
+ 'current)
+ ((decoded-time? object)
+ (decoded-time->universal-time object))
+ ((integer? object)
+ object)
+ (else
+ (error "Not a time (universal, decoded or 'CURRENT):" object))))
+
(define (run-tellurion queue)
(let ((device (make-suitable-graphics-device))
;; Latitude and longitude per GPS -- positive degrees long. to the east.
(lat/lng (make-latitude/longitude 23.271 0.))
- (time (get-universal-time))
+ (time 'current)
(stopped? #f))
- (define-integrable (draw)
- (draw-tellurion device time lat/lng))
+ (define (draw)
+ (draw-tellurion device
+ (if (eq? time 'current)
+ (get-universal-time)
+ time)
+ lat/lng))
(draw)
(let loop ()
(let ((command (if stopped?
(thread-queue/dequeue! queue)
(thread-queue/dequeue-no-hang!
queue
- (let* ((time (get-universal-time))
- (next (* 15 60
- (1+ (quotient time (* 15 60)))))
- (sec (- next time)))
- (* sec 1000))))))
+ (if (eq? time 'current)
+ (let* ((time (get-universal-time))
+ (next (* 15 60
+ (1+ (quotient time (* 15 60)))))
+ (sec (- next time)))
+ (* sec 1000))
+ (* 15 60 1000))))))
(cond ((eq? command #f) ;timeout
- (set! time (get-universal-time))
+ (if (not (eq? time 'current))
+ (set! time (+ time (* 15 60))))
(draw))
((eq? (car command) 'TURN-TO)
(set-latitude! lat/lng (cadr command))
(set-longitude! lat/lng (caddr command))
(draw))
((eq? (car command) 'TIME-TO)
- (if (eq? (cadr command) 'current)
- (set! time (get-universal-time))
- (set! time (cadr command)))
- (draw))
- ((eq? (car command) 'HOUR-TO)
- (set! time (decoded-time->universal-time
- (let ((decoded
- (universal-time->global-decoded-time time)))
- (make-decoded-time
- 0 0 (cadr command)
- (decoded-time/day decoded)
- (decoded-time/month decoded)
- (decoded-time/year decoded)))))
+ (set! time (cadr command))
(draw))
((eq? (car command) 'STOP)
- (display ";stopped\n")
(set! stopped? #t))
((eq? (car command) 'GO)
(set! stopped? #f)
- (display ";going\n")
- (set! time (get-universal-time))
- (draw))))
+ (if (eq? time 'current)
+ (draw)))))
(loop))))
(define draw-tellurion