Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - Stefan

#1
I actually bought a "used" AR.Drone. It was in a pretty good shape and I could test it before I bought it.
#2
I wrote a few functions that allow to control the Parrot AR.Drone 2.0 with newLisp.

You can find the code here: https://bitbucket.org/StefanLiebig/dragondrone">https://bitbucket.org/StefanLiebig/dragondrone



Any kind of feedback is welcome!



Tschüß,

Stefan
#3
Thanks! It works with ncurses:

;;;
;;; simplified newlisp ncurses example to get key codes
;;;

;;; import functions from ncurses lib
(set 'ncfuncs '( "initscr" "endwin" "getch" "cbreak" "keypad"))
(define (import-ncurses) (dolist (x ncfuncs ) (import "/usr/lib/libncurses.dylib" x)))

;;; Newlisp-Ncurses
(import-ncurses)
(set 'stdscr (initscr))
(println (format "%ld" stdscr))
(cbreak)
(keypad stdscr 1)
(set 'key (getch))
(endwin)
(println (string "key: " key))


This should be sufficient for my purpose.
#4
For a simple "game" (console based) I need to get the keyboard "key events" from my Mac.

(read-key) seems to be a good choice, but unfortunately some keys (or modified keys: shift, ..) do require following (read-key)s.

Worse on Mac is that "cursor up" results in three (read-key)s returning: 27 91 65 and ESC in 27! So I can not distinguish between ESC and cursor keys.



Is there a better solution?



Stefan



ps From the newLISP docu: (while (!= (set 'c (read-key)) 1) (println c))
#5
Yep, that's the reason.



Thanks,

Stefan
#6
I am currently playing with UDP (no experience with it yet). For getting things started I tried the example udp client and server from http://www.newlisp.org/CodePatterns.html#toc-13">//http://www.newlisp.org/CodePatterns.html#toc-13 .

Server started, but the client reports an error:

newLISP v.10.6.0 64-bit on OSX IPv4/6 UTF-8 libffi, options: newlisp -h
> (load "udp-client.lsp")
(10 "Cannot bind socket")
nil


Something I forgot?



Stefan
#7
Right! The (add 256) in
Quote
bit 9 will be set for 64-bit (changeable at runtime) versions (add 256)

(http://www.newlisp.org/downloads/newlisp_manual.html#sys-info">http://www.newlisp.org/downloads/newlis ... l#sys-info">http://www.newlisp.org/downloads/newlisp_manual.html#sys-info)

could have told me this. I really did not know how to interpret it.



ps: Currently I am glad that it is a signed integer. :-)



Thanks,

Stefan
#8
After browsing the good documentation I found ".init.lsp" for automating this:

;; set local to the "C" locale on UTF8
(if utf8
(set-locale "C"))

;; test for 32-bit-ness
(define (bit32?)
(= (& (sys-info -1) (<< 1 9))))

;; define flt32 depending on the bit-ness
(if (bit32?)
(constant 'flt32 flt)
(define (flt32 f)
(first (unpack "ld" (pack "f" f)))))

While the locale stuff works nicely detecting the bitness does not work. It returns true on Win32 and OS X.

On OS X (sys-info -1) returns 1411 and on Win32 it returns 1030.

In both cases bit 9 is 0, i.e. 32 bit.

Is there another way for detecting this?



Stefan
#9
Thanks for the explanation and the code snippet for the integer representation. Although, I am not really sure what is happening there. "first" of the result of "unpack" - what is unpack in this case returning?



However, the locale dependency scares me a little bit. Should the parsing of literals not be locale independent?  Formatting and scanning of cause should be locale dependent.



Is there a possibility to automate the (set-locale "C")?



Stefan
#10
newLISP and the O.S. / (flt -0.8) on OS X and Win
May 20, 2014, 09:22:48 AM
I need the integer representation of single-precision IEEE-754 floating-point value. My home machine is a Mac:

newLISP v.10.6.0 64-bit on OSX IPv4/6 UTF-8 libffi, options: newlisp -h

> (flt -0.8)
0

On my machine at work I get:

newLISP v.10.6.0 32-bit on Win32 IPv4/6 libffi, options: newlisp -h

> (flt -0.8)
-1085485875

which is precisely what I need (on my Mac).



Btw, in Java:

Float.floatToIntBits(-0.8f)

does exactly the same. it returns -1085485875



Is this different behavior "intended"? (I know Mac is 64-bit and Win is 32-bit)



However, how could I get the same result on my Mac? I tried several things but I had no success.



While experimenting I found also this:

newLISP v.10.6.0 32-bit on Win32 IPv4/6 libffi, options: newlisp -h

> (format "%f" -0.8)
"-0.800000"

and

newLISP v.10.6.0 64-bit on OSX IPv4/6 UTF-8 libffi, options: newlisp -h

> (format "%f" -0.8)

ERR: mismatch in number of arguments in function format : .8
>

Hmm!?



Stefan