[Fluxus] Gamepads

Dave Griffiths dave at pawfal.org
Mon Dec 3 15:01:38 PST 2007


On Mon, 2007-12-03 at 21:05 +0100, Martin Ahnelöv wrote:
> Hey!
> I've tried to get my joystick to work with fluxus. I've looked at the
> script on <http://www.pawfal.org/index.php?page=FluxusGamePadInput>, but
> it doesn't like (make-list) at all. Is the script outdated, or is it me?
> I've tried both version 0.13 and 0.14. I've compiled them with mzs 3.71.

Bad script, I've posted the one I'm currently using at the bottom - I've
been planning to put this in the release (along with the ring menu and
probably some other stuff) so if you can give it a test that would be
great.

> Also, why have you hidden the old tutorial for 0.12 ? Is it that heavily
> outdated? I think you should link to it wit a disclaimer, or, which is
> better, update it. A list of new functions doesn't really help new
> schemers.

Good questions. I stopped using it because it was getting increasingly
out of date and I didn't have the ability to keep it current. The way it
works now is much easier to keep up to date, but yes, it's very lacking
in the high level stuff, it's true. 

I'm hoping that a better set of examples is the way to go - showing some
more representative examples of how fluxus is used (and some more
complex things too). Do you think this would fill the gap enough? The
other nice thing about examples is that you can check they still work
between each release.


;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; joypad
; a joypad input listener, for use with oscjoy 
; (http://www.lcscanada.com/oscjoy/index.html)
;
; usage:
; (osc-source oscjoy-portnumber)
; (define my-joypad (make-object joypad%))
; ... every frame loop ...
; (send my-joypad update)
; (display (send my-joypad get-button 0))(newline)
; (display (send my-joypad get-axis 0))(newline) ; returns a two element vector

(define joypad%
  (class object%
    (public
      update ;; update the joylistener
      get-button ;; get the current values for a button
      get-axis ;; get the current value for an axis
      )
    
    (define buttons '())
    (define axes '())
    (define button-state '())
    
    (define (joypad-new)
      (super-new)
      (set! buttons (make-buttons 16 '()))
      (set! axes (make-axes 16 '()))
      (set! button-state (make-buttons 16 '())))
    
    (define (make-axes n l)
      (if (zero? n)
          l
          (make-axes (- n 1) (cons (make-vector 2 0) l))))
    
    (define (make-buttons n l)
      (if (zero? n)
          l
          (make-buttons (- n 1) (cons 0 l))))
    
    (define (get-button n)
      (list-ref buttons n))
    
    (define (button-changed n)
      (list-ref button-state n))
    
    (define (get-axis n)
      (list-ref axes n))
    
    (define (set-button! n s)
      (list-set! buttons n s))
    
    (define (update)
      (define (drain path value)       ; drains all osc events for a message and 
        (if (osc-msg path)             ; only reports the last one which is ok for
            (drain path (osc 0))       ; this sort of control
            value))
      
      (define (do-axes n)
        (let ((value (drain (string-append "/oscjoy.0.axis." (number->string n)) #f)))
          (cond
            ((number? value)
             ; do some mangling of values here,
             ; firstly, make 0=x 1=y and secondly,
             ; change the range from 0 to 1 to -1 to 1
             (vector-set! (get-axis (inexact->exact (truncate (/ n 2))))
                          (- 1 (modulo n 2)) (* 2 (- value 0.5))))))
        (if (zero? n)
            0
            (do-axes (- n 1))))
      
      (define (do-buttons n)
        (let ((value (drain (string-append "/oscjoy.0.button." (number->string n)) #f)))
          (cond 
            ((number? value)
             ; have we changed?
             (if (not (eq? (get-button n) value))
                 (list-set! button-state n #t)
                 (list-set! button-state n #f))
             (set-button! n value))))
        (if (zero? n)
            0
            (do-buttons (- n 1))))
      
      ;(display (osc-peek)) (newline)
      
      (do-axes 16)
      (do-buttons 16))
    
    (joypad-new)))





More information about the Fluxus mailing list