From 6fbb6da9f57185cbcd2dbaf26c1b2e9fa6af58c7 Mon Sep 17 00:00:00 2001 From: Rupert Swarbrick Date: Fri, 8 Aug 2008 14:37:32 +0100 Subject: [PATCH] Rewrote usage.lisp for more up-to-date examples Also fixed some small package export errors. --- example/usage.lisp | 70 +++++++++++++++++++++++++++++++--------------------- package/package.lisp | 8 ++++-- 2 files changed, 48 insertions(+), 30 deletions(-) rewrite example/usage.lisp (71%) diff --git a/example/usage.lisp b/example/usage.lisp dissimilarity index 71% index d9c122d..814922f 100644 --- a/example/usage.lisp +++ b/example/usage.lisp @@ -1,28 +1,42 @@ -(defpackage :sane-example - (:use :sane :cl)) - -(in-package :sane-example) - -;; With-init runs forms with the library initialised. It can bind a -;; variable to the version - in this case, V. -(with-init v - (format t "~A~%" v) - 42) - -;; devices lists the devices sane can find. -;;(with-init nil -;; (mapcar #'device-name (devices t))) - - -;; List all the options of the device along with some info about them. -(in-package :sane) -(with-init nil - (with-device d 0 - (value (option 2 d)) - (mapcar - (lambda (o) - (format t "~A: ~A ~A~%" - (get-name o) (get-capabilities o) - (get-type (slot-value o 'value)))) - (slot-value d 'options))) - (values nil)) \ No newline at end of file +;;;;;;;;;;;; +;; This is a sort of elephants' graveyard of usage examples/snippets. Will be +;; removed/replaced when the library is fully bound and I can write some proper +;; documentation! +;;;;;;;;;;;;; + +(defpackage :sane-user + (:use :sane :cl :trivial-gray-streams :iterate)) + +(in-package :sane-user) + +;; With-init runs forms with the library initialised. It can bind a +;; variable to the version - in this case, V. +(with-init v + (format t "~A~%" v) + 42) + +;; devices lists the devices sane can find. +(with-init nil + (mapcar #'name (devices t))) + +;; List all the options of the device +(with-init nil + (with-device d "test:0" + (dump-option-list d))) + +;; Read from the device. +(with-init nil + (with-device d "test:0" + (setf (value (option "mode" d)) "Color") + (setf (value (option "test-picture" d)) "Color pattern") + + (with-open-file (f "out.raw" + :direction :output + :element-type '(unsigned-byte 8) + :if-exists :supersede :if-does-not-exist :create) + (with-open-scanner-stream s d + (let (byte) + (iterate + (setf byte (stream-read-byte s)) + (when (eq byte :eof) (terminate)) + (write-byte byte f))))))) \ No newline at end of file diff --git a/package/package.lisp b/package/package.lisp index 8f62f2b..9d4fd98 100644 --- a/package/package.lisp +++ b/package/package.lisp @@ -11,7 +11,7 @@ :with-init ;; Device :devices - :device-name :device-vendor :device-model :device-type + :name :vendor :model :device-type :with-device ;; Option getters :get-name :get-title :get-description :get-device @@ -20,4 +20,8 @@ :get-min :get-step :get-max :get-list ;; Main option functions :option-value-readable-p - :option :value)) \ No newline at end of file + :option :value + ;; And option debugging + :dump-option-list + ;; Reading + :with-open-scanner-stream :parameters :device)) \ No newline at end of file -- 2.11.4.GIT