From 3bdc84a07ab33fd6bccabbf5304a8d98703aa5fb Mon Sep 17 00:00:00 2001 From: Erik Charlebois Date: Sun, 14 Feb 2010 23:41:44 -0800 Subject: [PATCH 1/8] Fix D3D9 constants that I punted on calculating initially. --- .../directx/d3d9types/d3d9types.factor | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/basis/windows/directx/d3d9types/d3d9types.factor b/basis/windows/directx/d3d9types/d3d9types.factor index 9f4358f658..dc02849553 100644 --- a/basis/windows/directx/d3d9types/d3d9types.factor +++ b/basis/windows/directx/d3d9types/d3d9types.factor @@ -900,12 +900,6 @@ CONSTANT: D3DMULTISAMPLE_14_SAMPLES 14 CONSTANT: D3DMULTISAMPLE_15_SAMPLES 15 CONSTANT: D3DMULTISAMPLE_16_SAMPLES 16 CONSTANT: D3DMULTISAMPLE_FORCE_DWORD HEX: 7fffffff - -:: MAKEFOURCC ( ch0 ch1 ch2 ch3 -- n ) - ch3 HEX: ff bitand 24 shift - ch2 HEX: ff bitand 16 shift - ch1 HEX: ff bitand 8 shift - ch0 HEX: ff bitand bitor bitor bitor ; inline TYPEDEF: int D3DFORMAT CONSTANT: D3DFMT_UNKNOWN 0 @@ -937,15 +931,15 @@ CONSTANT: D3DFMT_X8L8V8U8 62 CONSTANT: D3DFMT_Q8W8V8U8 63 CONSTANT: D3DFMT_V16U16 64 CONSTANT: D3DFMT_A2W10V10U10 67 -#! : D3DFMT_UYVY ( -- n ) 'U' 'Y' 'V' 'Y' MAKEFOURCC -#! D3DFMT_R8G8_B8G8 = MAKEFOURCC('R', 'G', 'B', 'G'), -#! D3DFMT_YUY2 = MAKEFOURCC('Y', 'U', 'Y', '2'), -#! D3DFMT_G8R8_G8B8 = MAKEFOURCC('G', 'R', 'G', 'B'), -#! D3DFMT_DXT1 = MAKEFOURCC('D', 'X', 'T', '1'), -#! D3DFMT_DXT2 = MAKEFOURCC('D', 'X', 'T', '2'), -#! D3DFMT_DXT3 = MAKEFOURCC('D', 'X', 'T', '3'), -#! D3DFMT_DXT4 = MAKEFOURCC('D', 'X', 'T', '4'), -#! D3DFMT_DXT5 = MAKEFOURCC('D', 'X', 'T', '5'), +CONSTANT: D3DFMT_UYVY HEX: 55595659 +CONSTANT: D3DFMT_R8G8_B8G8 HEX: 52474247 +CONSTANT: D3DFMT_YUY2 HEX: 59555932 +CONSTANT: D3DFMT_G8R8_G8B8 HEX: 47524742 +CONSTANT: D3DFMT_DXT1 HEX: 44585431 +CONSTANT: D3DFMT_DXT2 HEX: 44585432 +CONSTANT: D3DFMT_DXT3 HEX: 44585433 +CONSTANT: D3DFMT_DXT4 HEX: 44585434 +CONSTANT: D3DFMT_DXT5 HEX: 44585435 CONSTANT: D3DFMT_D16_LOCKABLE 70 CONSTANT: D3DFMT_D32 71 CONSTANT: D3DFMT_D15S1 73 @@ -962,7 +956,7 @@ CONSTANT: D3DFMT_VERTEXDATA 100 CONSTANT: D3DFMT_INDEX16 101 CONSTANT: D3DFMT_INDEX32 102 CONSTANT: D3DFMT_Q16W16V16U16 110 -#! D3DFMT_MULTI2_ARGB8 = MAKEFOURCC('M', 'E', 'T', '1'), +CONSTANT: D3DFMT_MULTI2_ARGB8 HEX: 4d455431 CONSTANT: D3DFMT_R16F 111 CONSTANT: D3DFMT_G16R16F 112 CONSTANT: D3DFMT_A16B16G16R16F 113 From d8c452270596bad65be18dc58295a1635379ca05 Mon Sep 17 00:00:00 2001 From: Erik Charlebois Date: Tue, 16 Feb 2010 03:14:30 -0800 Subject: [PATCH 2/8] Fix docs typo --- basis/command-line/command-line-docs.factor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basis/command-line/command-line-docs.factor b/basis/command-line/command-line-docs.factor index 11ee46c227..9a69614766 100644 --- a/basis/command-line/command-line-docs.factor +++ b/basis/command-line/command-line-docs.factor @@ -91,7 +91,7 @@ ARTICLE: "standard-cli-args" "Command line switches for general usage" } ; ARTICLE: "factor-boot-rc" "Bootstrap initialization file" -"The botstrap initialization file is named " { $snippet "factor-boot-rc" } " on Windows and " { $snippet ".factor-boot-rc" } " on Unix. This file can contain " { $link require } " calls for vocabularies you use frequently, and other such long-running tasks that you do not want to perform every time Factor starts." +"The bootstrap initialization file is named " { $snippet "factor-boot-rc" } " on Windows and " { $snippet ".factor-boot-rc" } " on Unix. This file can contain " { $link require } " calls for vocabularies you use frequently, and other such long-running tasks that you do not want to perform every time Factor starts." $nl "A word to run this file from an existing Factor session:" { $subsections run-bootstrap-init } From c8192adf7113c996adb546c4e8a3fe8619b0ba08 Mon Sep 17 00:00:00 2001 From: Erik Charlebois Date: Tue, 16 Feb 2010 03:25:03 -0800 Subject: [PATCH 3/8] Fix some doc typos, metadata --- basis/db/tuples/tuples-docs.factor | 2 +- core/classes/tuple/tuple-docs.factor | 2 +- extra/chipmunk/summary.txt | 2 +- extra/chipmunk/tags.txt | 1 + 4 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 extra/chipmunk/tags.txt diff --git a/basis/db/tuples/tuples-docs.factor b/basis/db/tuples/tuples-docs.factor index 01d65484f3..ebf86371a7 100644 --- a/basis/db/tuples/tuples-docs.factor +++ b/basis/db/tuples/tuples-docs.factor @@ -267,7 +267,7 @@ T{ book { $list "Make a new tuple to represent your data" { "Map the Factor types to the database types with " { $link define-persistent } } - { "Make a custom database combinator (see" { $link "db-custom-database-combinators" } ") to open your database and run a " { $link quotation } } + { "Make a custom database combinator (see " { $link "db-custom-database-combinators" } ") to open your database and run a " { $link quotation } } { "Create a table with " { $link create-table } ", " { $link ensure-table } ", or " { $link recreate-table } } { "Start making and storing objects with " { $link insert-tuple } ", " { $link update-tuple } ", " { $link delete-tuples } ", and " { $link select-tuples } } } ; diff --git a/core/classes/tuple/tuple-docs.factor b/core/classes/tuple/tuple-docs.factor index 2b3e80da1d..0fd7907492 100644 --- a/core/classes/tuple/tuple-docs.factor +++ b/core/classes/tuple/tuple-docs.factor @@ -440,4 +440,4 @@ HELP: boa { $values { "..." "slot values" } { "class" tuple-class } { "tuple" tuple } } { $description "Creates a new instance of " { $snippet "class" } " and fill in the slots from the stack, with the top-most stack element being stored in the right-most slot." } { $notes "The name " { $snippet "boa" } " is shorthand for “by order of arguments”, and “BOA constructor” is a pun on “boa constrictor”." } -{ $errors "Throws an error if the slot values do not match class declarations on slots (see" { $link "tuple-declarations" } ")." } ; +{ $errors "Throws an error if the slot values do not match class declarations on slots (see " { $link "tuple-declarations" } ")." } ; diff --git a/extra/chipmunk/summary.txt b/extra/chipmunk/summary.txt index ebc56a79ed..2859b353f2 100644 --- a/extra/chipmunk/summary.txt +++ b/extra/chipmunk/summary.txt @@ -1 +1 @@ -FFI bindings to the Chipmunk 2D physics library. +Chipmunk 2D physics library binding diff --git a/extra/chipmunk/tags.txt b/extra/chipmunk/tags.txt new file mode 100644 index 0000000000..bb863cf9a0 --- /dev/null +++ b/extra/chipmunk/tags.txt @@ -0,0 +1 @@ +bindings From 941c09d73a1f5d571a6a39255e03e0b896302c83 Mon Sep 17 00:00:00 2001 From: Erik Charlebois Date: Tue, 16 Feb 2010 03:26:36 -0800 Subject: [PATCH 4/8] Splines: catmull-rom, bezier curve, cubic hermite, kochanek-bartels --- extra/math/splines/authors.txt | 1 + extra/math/splines/splines-docs.factor | 44 ++++++++++++ extra/math/splines/splines.factor | 84 +++++++++++++++++++++++ extra/math/splines/summary.txt | 1 + extra/math/splines/testing/authors.txt | 1 + extra/math/splines/testing/testing.factor | 49 +++++++++++++ extra/math/splines/viewer/authors.txt | 1 + extra/math/splines/viewer/viewer.factor | 49 +++++++++++++ 8 files changed, 230 insertions(+) create mode 100644 extra/math/splines/authors.txt create mode 100644 extra/math/splines/splines-docs.factor create mode 100644 extra/math/splines/splines.factor create mode 100644 extra/math/splines/summary.txt create mode 100644 extra/math/splines/testing/authors.txt create mode 100644 extra/math/splines/testing/testing.factor create mode 100644 extra/math/splines/viewer/authors.txt create mode 100644 extra/math/splines/viewer/viewer.factor diff --git a/extra/math/splines/authors.txt b/extra/math/splines/authors.txt new file mode 100644 index 0000000000..6f03a12101 --- /dev/null +++ b/extra/math/splines/authors.txt @@ -0,0 +1 @@ +Erik Charlebois diff --git a/extra/math/splines/splines-docs.factor b/extra/math/splines/splines-docs.factor new file mode 100644 index 0000000000..62ff1418cd --- /dev/null +++ b/extra/math/splines/splines-docs.factor @@ -0,0 +1,44 @@ +! Copyright (C) 2010 Erik Charlebois. +! See http://factorcode.org/license.txt for BSD license. +USING: help.markup help.syntax math ; +IN: math.splines + +HELP: +{ $values + { "control-points" "sequence of control points same dimension" } + { "polynomials" "sequence of polynomials for each dimension" } +} +{ $description "Creates bezier curve polynomials for the given control points." } ; + +HELP: +{ $values + { "points" "points on the spline" } { "m0" "initial tangent vector" } { "mn" "final tangent vector" } + { "polynomials-sequence" "sequence of sequences of polynomials" } +} +{ $description "Creates a sequence of cubic hermite curves (each a sequence of polynomials) passing through the given points and generating tangents for C1 continuity." } ; + +HELP: +{ $values + { "p0" "start point" } { "m0" "start tangent" } { "p1" "end point" } { "m1" "end tangent" } + { "polynomials" "sequence of polynomials" } +} +{ $description "Creates a sequence of polynomials (one per dimension) for the curve passing through " { $emphasis "p0" } " and " { $emphasis "p1" } "." } ; + +HELP: +{ $values + { "point-tangent-pairs" "sequence of point and tangent pairs" } + { "polynomials-sequence" "sequence of sequences of polynomials" } +} +{ $description "Creates a sequence of cubic hermite curves (each a sequence of polynomials) passing through the given points with the given tangents." } ; + +HELP: +{ $values + { "points" "points on the spline" } { "m0" "start tangent" } { "mn" "end tangent" } { "tension" number } { "bias" number } { "continuity" number } + { "polynomials-sequence" "sequence of sequence of polynomials" } +} +{ $description "Creates a sequence of cubic hermite curves (each a sequence of polynomials) passing through the given points, generating tangents with the given tuning parameters." } ; + +ARTICLE: "math.splines" "Common parametric curves." +"The curve creating functions create sequences of polynomials, one for each degree of the input points. The spline creating functions create sequences of these curve polynomial sequences. The " { $vocab-link "math.splines.viewer" } " vocabulary provides a gadget to evaluate the generated polynomials and view the results."; + +ABOUT: "math.splines" diff --git a/extra/math/splines/splines.factor b/extra/math/splines/splines.factor new file mode 100644 index 0000000000..dc22224416 --- /dev/null +++ b/extra/math/splines/splines.factor @@ -0,0 +1,84 @@ +! Copyright (C) 2010 Erik Charlebois +! See http://factorcode.org/license.txt for BSD license. +USING: accessors combinators kernel locals math math.combinatorics +math.polynomials opengl.gl sequences ui.gadgets ui.gadgets.panes +ui.render arrays grouping math.vectors assocs +ui.gestures ; +IN: math.splines + + ( pi-1 pi pi+1 ) + pi pi-1 v- c1 v*n + pi+1 pi v- c2 v*n v+ + ] map + m0 prefix + mn suffix ; +PRIVATE> + +:: ( control-points -- polynomials ) + control-points + [ length 1 - ] + [ first length [ { 0 } ] replicate ] + bi :> ( n acc ) + + control-points [| pt i | + n i bernstein-polynomial-ith :> poly + pt [| v j | + j acc [ v poly n*p p+ ] change-nth + ] each-index + ] each-index + acc ; + +:: ( p0 m0 p1 m1 -- polynomials ) + p0 length iota [ + { + [ p0 nth ] [ m0 nth ] + [ p1 nth ] [ m1 nth ] + } cleave + hermite-polynomial + ] map ; + + + ] map ; +PRIVATE> + +: ( point-tangent-pairs -- polynomials-sequence ) + 2 clump [ first2 [ first2 ] bi@ ] map ; + +:: ( points m0 mn tension bias continuity -- polynomials-sequence ) + tension bias continuity kochanek-bartels-coefficients :> ( s1 d1 s2 d2 ) + points m0 mn + [ s1 s2 kochanek-bartels-tangents ] + [ d1 d2 kochanek-bartels-tangents ] 3bi :> ( in out ) + points in out [ 3array ] 3map (cubic-hermite-spline) ; + +: ( points m0 mn -- polynomials-sequence ) + 0 0 0 ; diff --git a/extra/math/splines/summary.txt b/extra/math/splines/summary.txt new file mode 100644 index 0000000000..229b05edc9 --- /dev/null +++ b/extra/math/splines/summary.txt @@ -0,0 +1 @@ +Common parametric curves diff --git a/extra/math/splines/testing/authors.txt b/extra/math/splines/testing/authors.txt new file mode 100644 index 0000000000..67cf648cf5 --- /dev/null +++ b/extra/math/splines/testing/authors.txt @@ -0,0 +1 @@ +Erik Charlebois \ No newline at end of file diff --git a/extra/math/splines/testing/testing.factor b/extra/math/splines/testing/testing.factor new file mode 100644 index 0000000000..bbb5cd6a6a --- /dev/null +++ b/extra/math/splines/testing/testing.factor @@ -0,0 +1,49 @@ +! Copyright (C) 2010 Erik Charlebois. +! See http://factorcode.org/license.txt for BSD license. +USING: locals math.splines math.splines.viewer arrays ; +IN: math.splines.testing + +: test1 ( -- ) + { + { { 0 0 } { 0 200 } } + { { 100 50 } { 0 -200 } } + { { 300 300 } { 500 200 } } + { { 400 400 } { 300 0 } } + } { 50 100 } 4 spline. ; + +: test2 ( -- ) + { + { 50 50 } + { 100 100 } + { 300 200 } + { 350 0 } + { 400 400 } + } { 0 100 } { 100 0 } { 100 50 } 50 spline. ; + +:: test3 ( x y z -- ) + { + { 100 50 } + { 200 350 } + { 300 50 } + } { 0 100 } { 0 -100 } x y z { 50 50 } 1000 spline. ; + +: test4 ( -- ) + { + { 0 5 } + { 0.5 3 } + { 10 10 } + { 12 4 } + { 15 5 } + } 1array { 100 100 } 100 spline. ; + +: test-splines ( -- ) + test1 test2 + 1 0 0 test3 + -1 0 0 test3 + 0 1 0 test3 + 0 -1 0 test3 + 0 0 1 test3 + 0 0 -1 test3 + test4 ; + + diff --git a/extra/math/splines/viewer/authors.txt b/extra/math/splines/viewer/authors.txt new file mode 100644 index 0000000000..67cf648cf5 --- /dev/null +++ b/extra/math/splines/viewer/authors.txt @@ -0,0 +1 @@ +Erik Charlebois \ No newline at end of file diff --git a/extra/math/splines/viewer/viewer.factor b/extra/math/splines/viewer/viewer.factor new file mode 100644 index 0000000000..f1ec1a2445 --- /dev/null +++ b/extra/math/splines/viewer/viewer.factor @@ -0,0 +1,49 @@ +! Copyright (C) 2010 Erik Charlebois. +! See http://factorcode.org/license.txt for BSD license. +USING: accessors kernel locals math math.order math.polynomials +math.splines opengl.gl sequences ui.gadgets ui.gadgets.panes ui.render +arrays ; +IN: math.splines.viewer + + + +TUPLE: spline-gadget < gadget polynomials steps spline-dim ; + +M: spline-gadget pref-dim* spline-dim>> ; + +M:: spline-gadget draw-gadget* ( gadget -- ) + 0 0 0 glColor3f + + gadget [ polynomials>> ] [ steps>> ] bi eval-polynomials :> pts + + pts [ first ] [ max ] map-reduce :> x-max + pts [ first ] [ min ] map-reduce :> x-min + pts [ second ] [ max ] map-reduce :> y-max + pts [ second ] [ min ] map-reduce :> y-min + + pts [ + [ first x-min - x-max x-min - / gadget spline-dim>> first * ] + [ second y-min - y-max y-min - / gadget spline-dim>> second * ] bi 2array + ] map :> pts + + GL_LINE_STRIP glBegin + pts [ + first2 neg gadget spline-dim>> second + glVertex2f + ] each + glEnd ; + +:: ( polynomials dim steps -- gadget ) + spline-gadget new + dim >>spline-dim + polynomials >>polynomials + steps >>steps ; + +: spline. ( curve dim steps -- ) + gadget. ; From fcbeb3467d39f0bedf022046121a95141ae9ff92 Mon Sep 17 00:00:00 2001 From: Erik Charlebois Date: Tue, 16 Feb 2010 10:33:19 -0800 Subject: [PATCH 5/8] Line endings --- basis/tools/deploy/deploy-tests.factor | 250 ++++++++++++------------- 1 file changed, 125 insertions(+), 125 deletions(-) diff --git a/basis/tools/deploy/deploy-tests.factor b/basis/tools/deploy/deploy-tests.factor index 987b4aa8a1..f76ad7a557 100644 --- a/basis/tools/deploy/deploy-tests.factor +++ b/basis/tools/deploy/deploy-tests.factor @@ -1,125 +1,125 @@ -USING: tools.test system io io.encodings.ascii io.pathnames -io.files io.files.info io.files.temp kernel tools.deploy.config -tools.deploy.config.editor tools.deploy.backend math sequences -io.launcher arrays namespaces continuations layouts accessors -urls math.parser io.directories tools.deploy.test ; -IN: tools.deploy.tests - -[ ] [ "hello-world" shake-and-bake 500000 small-enough? ] unit-test - -[ ] [ "sudoku" shake-and-bake 800000 small-enough? ] unit-test - -[ ] [ "hello-ui" shake-and-bake 1300000 small-enough? ] unit-test - -[ "staging.math-threads-compiler-ui.image" ] [ - "hello-ui" deploy-config - [ bootstrap-profile staging-image-name file-name ] bind -] unit-test - -[ ] [ "maze" shake-and-bake 1200000 small-enough? ] unit-test - -[ ] [ "tetris" shake-and-bake 1500000 small-enough? ] unit-test - -[ ] [ "spheres" shake-and-bake 1500000 small-enough? ] unit-test - -[ ] [ "terrain" shake-and-bake 1700000 small-enough? ] unit-test - -[ ] [ "bunny" shake-and-bake 2500000 small-enough? ] unit-test - -os macosx? [ - [ ] [ "webkit-demo" shake-and-bake 500000 small-enough? ] unit-test -] when - -[ ] [ "benchmark.regex-dna" shake-and-bake 900000 small-enough? ] unit-test - -{ - "tools.deploy.test.1" - "tools.deploy.test.2" - "tools.deploy.test.3" - "tools.deploy.test.4" -} [ - [ ] swap [ - shake-and-bake - run-temp-image - ] curry unit-test -] each - -USING: http.client http.server http.server.dispatchers -http.server.responses http.server.static io.servers.connection ; - -SINGLETON: quit-responder - -M: quit-responder call-responder* - 2drop stop-this-server "Goodbye" "text/html" ; - -: add-quot-responder ( responder -- responder ) - quit-responder "quit" add-responder ; - -: test-httpd ( responder -- ) - [ - main-responder set - - 0 >>insecure - f >>secure - dup start-server* - sockets>> first addr>> port>> - dup number>string "resource:temp/port-number" ascii set-file-contents - ] with-scope - "port" set ; - -[ ] [ - - add-quot-responder - "vocab:http/test" >>default - - test-httpd -] unit-test - -[ ] [ - "tools.deploy.test.5" shake-and-bake - run-temp-image -] unit-test - -: add-port ( url -- url' ) - >url clone "port" get >>port ; - -[ ] [ "http://localhost/quit" add-port http-get 2drop ] unit-test - -{ - "tools.deploy.test.6" - "tools.deploy.test.7" - "tools.deploy.test.9" - "tools.deploy.test.10" - "tools.deploy.test.11" - "tools.deploy.test.12" -} [ - [ ] swap [ - shake-and-bake - run-temp-image - ] curry unit-test -] each - -os windows? os macosx? or [ - [ ] [ "tools.deploy.test.8" shake-and-bake run-temp-image ] unit-test -] when - -os macosx? [ - [ ] [ "tools.deploy.test.14" shake-and-bake run-temp-image ] unit-test -] when - -[ { "a" "b" "c" } ] [ - "tools.deploy.test.15" shake-and-bake deploy-test-command - { "a" "b" "c" } append - ascii [ lines ] with-process-reader - rest -] unit-test - -[ ] [ "tools.deploy.test.16" shake-and-bake run-temp-image ] unit-test - -[ ] [ "tools.deploy.test.17" shake-and-bake run-temp-image ] unit-test - -[ t ] [ - "tools.deploy.test.18" shake-and-bake - deploy-test-command ascii [ readln ] with-process-reader - "test.image" temp-file = -] unit-test +USING: tools.test system io io.encodings.ascii io.pathnames +io.files io.files.info io.files.temp kernel tools.deploy.config +tools.deploy.config.editor tools.deploy.backend math sequences +io.launcher arrays namespaces continuations layouts accessors +urls math.parser io.directories tools.deploy.test ; +IN: tools.deploy.tests + +[ ] [ "hello-world" shake-and-bake 500000 small-enough? ] unit-test + +[ ] [ "sudoku" shake-and-bake 800000 small-enough? ] unit-test + +[ ] [ "hello-ui" shake-and-bake 1300000 small-enough? ] unit-test + +[ "staging.math-threads-compiler-ui.image" ] [ + "hello-ui" deploy-config + [ bootstrap-profile staging-image-name file-name ] bind +] unit-test + +[ ] [ "maze" shake-and-bake 1200000 small-enough? ] unit-test + +[ ] [ "tetris" shake-and-bake 1500000 small-enough? ] unit-test + +[ ] [ "spheres" shake-and-bake 1500000 small-enough? ] unit-test + +[ ] [ "terrain" shake-and-bake 1700000 small-enough? ] unit-test + +[ ] [ "bunny" shake-and-bake 2500000 small-enough? ] unit-test + +os macosx? [ + [ ] [ "webkit-demo" shake-and-bake 500000 small-enough? ] unit-test +] when + +[ ] [ "benchmark.regex-dna" shake-and-bake 900000 small-enough? ] unit-test + +{ + "tools.deploy.test.1" + "tools.deploy.test.2" + "tools.deploy.test.3" + "tools.deploy.test.4" +} [ + [ ] swap [ + shake-and-bake + run-temp-image + ] curry unit-test +] each + +USING: http.client http.server http.server.dispatchers +http.server.responses http.server.static io.servers.connection ; + +SINGLETON: quit-responder + +M: quit-responder call-responder* + 2drop stop-this-server "Goodbye" "text/html" ; + +: add-quot-responder ( responder -- responder ) + quit-responder "quit" add-responder ; + +: test-httpd ( responder -- ) + [ + main-responder set + + 0 >>insecure + f >>secure + dup start-server* + sockets>> first addr>> port>> + dup number>string "resource:temp/port-number" ascii set-file-contents + ] with-scope + "port" set ; + +[ ] [ + + add-quot-responder + "vocab:http/test" >>default + + test-httpd +] unit-test + +[ ] [ + "tools.deploy.test.5" shake-and-bake + run-temp-image +] unit-test + +: add-port ( url -- url' ) + >url clone "port" get >>port ; + +[ ] [ "http://localhost/quit" add-port http-get 2drop ] unit-test + +{ + "tools.deploy.test.6" + "tools.deploy.test.7" + "tools.deploy.test.9" + "tools.deploy.test.10" + "tools.deploy.test.11" + "tools.deploy.test.12" +} [ + [ ] swap [ + shake-and-bake + run-temp-image + ] curry unit-test +] each + +os windows? os macosx? or [ + [ ] [ "tools.deploy.test.8" shake-and-bake run-temp-image ] unit-test +] when + +os macosx? [ + [ ] [ "tools.deploy.test.14" shake-and-bake run-temp-image ] unit-test +] when + +[ { "a" "b" "c" } ] [ + "tools.deploy.test.15" shake-and-bake deploy-test-command + { "a" "b" "c" } append + ascii [ lines ] with-process-reader + rest +] unit-test + +[ ] [ "tools.deploy.test.16" shake-and-bake run-temp-image ] unit-test + +[ ] [ "tools.deploy.test.17" shake-and-bake run-temp-image ] unit-test + +[ t ] [ + "tools.deploy.test.18" shake-and-bake + deploy-test-command ascii [ readln ] with-process-reader + "test.image" temp-file = +] unit-test From 7b22818192aec8638039f42a89e64f976eab7ac9 Mon Sep 17 00:00:00 2001 From: Erik Charlebois Date: Tue, 16 Feb 2010 22:37:31 -0800 Subject: [PATCH 6/8] Remove game.input dependency from chipmunk.demo so it works on linux --- extra/chipmunk/demo/demo.factor | 42 +++++++++++++++------------------ 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/extra/chipmunk/demo/demo.factor b/extra/chipmunk/demo/demo.factor index 031ed576b6..06f3c32dbe 100644 --- a/extra/chipmunk/demo/demo.factor +++ b/extra/chipmunk/demo/demo.factor @@ -1,9 +1,8 @@ ! Copyright (C) 2010 Erik Charlebois ! See http:// factorcode.org/license.txt for BSD license. -USING: accessors chipmunk classes.struct game.loop game.worlds gpu -gpu.util.wasd kernel literals locals math method-chains opengl.gl -random sequences specialized-arrays -specialized-arrays.instances.alien.c-types.void* ui.gadgets.worlds +USING: accessors chipmunk classes.struct game.worlds kernel locals +math method-chains opengl.gl random sequences specialized-arrays +specialized-arrays.instances.alien.c-types.void* ui ui.gadgets.worlds ui.pixel-formats ; IN: chipmunk.demo @@ -56,7 +55,7 @@ CONSTANT: image-bitmap B{ cpCircleShapeAlloc body 0.95 0 0 cpv cpCircleShapeInit cpCircleShape memory>struct [ shape>> 0 >>e ] [ shape>> 0 >>u ] bi drop ; -TUPLE: chipmunk-world < wasd-world +TUPLE: chipmunk-world < game-world space ; AFTER: chipmunk-world tick-game-world @@ -97,8 +96,6 @@ M:: chipmunk-world draw-world* ( world -- ) M:: chipmunk-world begin-game-world ( world -- ) cpInitChipmunk - init-gpu - world { -0.2 0.13 0.1 } 1.1 0.2 set-wasd-view drop cpSpaceAlloc cpSpaceInit cpSpace memory>struct :> space @@ -132,20 +129,19 @@ M: chipmunk-world end-game-world [ cpSpaceFreeChildren ] [ cpSpaceFree ] bi ; -M: chipmunk-world wasd-movement-speed drop 1/160. ; -M: chipmunk-world wasd-near-plane drop 1/32. ; -M: chipmunk-world wasd-far-plane drop 256.0 ; +: chipmunk-demo ( -- ) + [ + f + T{ game-attributes + { world-class chipmunk-world } + { title "Chipmunk Physics Demo" } + { pixel-format-attributes + { windowed double-buffered } + } + { pref-dim { 640 480 } } + { tick-interval-micros 16666 } + } + clone + open-window + ] with-ui ; -GAME: chipmunk-demo { - { world-class chipmunk-world } - { title "Chipmunk Physics Demo" } - { pixel-format-attributes { - windowed - double-buffered - T{ depth-bits { value 24 } } - } } - { grab-input? t } - { use-game-input? t } - { pref-dim { 640 480 } } - { tick-interval-micros $[ 60 fps ] } - } ; From d3d7392fa9424383d71e7af0dce8d9f5853fa174 Mon Sep 17 00:00:00 2001 From: Erik Charlebois Date: Thu, 18 Feb 2010 12:52:33 -0800 Subject: [PATCH 7/8] Implement input grabbing for x11; add do-nothing game.input backend for linux. The game and gpu demos now run correctly. --- basis/game/input/input.factor | 2 +- basis/game/input/linux/authors.txt | 1 + basis/game/input/linux/linux.factor | 49 +++++++++++++++++++++++++++++ basis/game/input/linux/summary.txt | 1 + basis/game/input/linux/tags.txt | 1 + basis/ui/backend/x11/x11.factor | 33 +++++++++++++------ basis/x11/xlib/xlib.factor | 14 +++++++++ 7 files changed, 91 insertions(+), 10 deletions(-) create mode 100644 basis/game/input/linux/authors.txt create mode 100644 basis/game/input/linux/linux.factor create mode 100644 basis/game/input/linux/summary.txt create mode 100644 basis/game/input/linux/tags.txt diff --git a/basis/game/input/input.factor b/basis/game/input/input.factor index a2afbe92a3..7543a05c60 100644 --- a/basis/game/input/input.factor +++ b/basis/game/input/input.factor @@ -93,5 +93,5 @@ M: mouse-state clone { { [ os windows? ] [ "game.input.xinput" require ] } { [ os macosx? ] [ "game.input.iokit" require ] } - { [ t ] [ ] } + { [ os linux? ] [ "game.input.linux" require ] } } cond diff --git a/basis/game/input/linux/authors.txt b/basis/game/input/linux/authors.txt new file mode 100644 index 0000000000..67cf648cf5 --- /dev/null +++ b/basis/game/input/linux/authors.txt @@ -0,0 +1 @@ +Erik Charlebois \ No newline at end of file diff --git a/basis/game/input/linux/linux.factor b/basis/game/input/linux/linux.factor new file mode 100644 index 0000000000..465cefa84b --- /dev/null +++ b/basis/game/input/linux/linux.factor @@ -0,0 +1,49 @@ +! Copyright (C) 2010 Erik Charlebois. +! See http://factorcode.org/license.txt for BSD license. +USING: kernel game.input namespaces classes windows.com.syntax +bit-arrays +vectors ; +IN: game.input.linux + +SINGLETON: linux-game-input-backend + +linux-game-input-backend game-input-backend set-global + +M: linux-game-input-backend (open-game-input) + ; + +M: linux-game-input-backend (close-game-input) + ; + +M: linux-game-input-backend (reset-game-input) + ; + +M: linux-game-input-backend get-controllers + { } ; + +M: linux-game-input-backend product-string + drop "" ; + +M: linux-game-input-backend product-id + drop GUID: {00000000-0000-0000-0000-000000000000} ; + +M: linux-game-input-backend instance-id + drop GUID: {00000000-0000-0000-0000-000000000000} ; + +M: linux-game-input-backend read-controller + drop controller-state new ; + +M: linux-game-input-backend calibrate-controller + drop ; + +M: linux-game-input-backend vibrate-controller + 3drop ; + +M: linux-game-input-backend read-keyboard + 256 keyboard-state boa ; + +M: linux-game-input-backend read-mouse + 0 0 0 0 2 mouse-state boa ; + +M: linux-game-input-backend reset-mouse + ; diff --git a/basis/game/input/linux/summary.txt b/basis/game/input/linux/summary.txt new file mode 100644 index 0000000000..5c88274722 --- /dev/null +++ b/basis/game/input/linux/summary.txt @@ -0,0 +1 @@ +Linux backend for game input. diff --git a/basis/game/input/linux/tags.txt b/basis/game/input/linux/tags.txt new file mode 100644 index 0000000000..84d4140a70 --- /dev/null +++ b/basis/game/input/linux/tags.txt @@ -0,0 +1 @@ +games diff --git a/basis/ui/backend/x11/x11.factor b/basis/ui/backend/x11/x11.factor index 4c977f17a4..673dd8e9c3 100644 --- a/basis/ui/backend/x11/x11.factor +++ b/basis/ui/backend/x11/x11.factor @@ -1,14 +1,13 @@ ! Copyright (C) 2005, 2009 Eduardo Cavazos and Slava Pestov ! See http://factorcode.org/license.txt for BSD license. -USING: accessors alien.c-types arrays ascii assocs colors -classes.struct combinators io.encodings.ascii -io.encodings.string io.encodings.utf8 kernel literals math -namespaces sequences strings ui ui.backend ui.clipboards -ui.event-loop ui.gadgets ui.gadgets.private ui.gadgets.worlds -ui.gestures ui.pixel-formats ui.pixel-formats.private -ui.private x11 x11.clipboard x11.constants x11.events x11.glx -x11.io x11.windows x11.xim x11.xlib environment command-line -combinators.short-circuit ; +USING: accessors alien.c-types ascii assocs classes.struct combinators +combinators.short-circuit command-line environment io.encodings.ascii +io.encodings.string io.encodings.utf8 kernel literals locals math +namespaces sequences specialized-arrays.instances.alien.c-types.uchar +strings ui ui.backend ui.clipboards ui.event-loop ui.gadgets +ui.gadgets.private ui.gadgets.worlds ui.gestures ui.pixel-formats +ui.pixel-formats.private ui.private x11 x11.clipboard x11.constants +x11.events x11.glx x11.io x11.windows x11.xim x11.xlib ; IN: ui.backend.x11 SINGLETON: x11-ui-backend @@ -328,6 +327,22 @@ M: x11-ui-backend (with-ui) ( quot -- ) M: x11-ui-backend beep ( -- ) dpy get 100 XBell drop ; +: black ( -- xcolor ) 0 0 0 0 0 0 XColor ; inline + +M:: x11-ui-backend (grab-input) ( handle -- ) + handle window>> :> wnd + dpy get :> dpy + dpy wnd uchar-array{ 0 0 0 0 0 0 0 0 } 8 8 XCreateBitmapFromData :> pixmap + dpy pixmap dup black dup 0 0 XCreatePixmapCursor :> cursor + + dpy wnd 1 NoEventMask GrabModeAsync dup wnd cursor CurrentTime XGrabPointer drop + + dpy cursor XFreeCursor drop + dpy pixmap XFreePixmap drop ; + +M: x11-ui-backend (ungrab-input) + drop dpy get CurrentTime XUngrabPointer drop ; + x11-ui-backend ui-backend set-global [ "DISPLAY" os-env "ui.tools" "listener" ? ] diff --git a/basis/x11/xlib/xlib.factor b/basis/x11/xlib/xlib.factor index a6097c9dad..7235aaf679 100644 --- a/basis/x11/xlib/xlib.factor +++ b/basis/x11/xlib/xlib.factor @@ -284,6 +284,11 @@ X-FUNCTION: int XConvertSelection ( Display* display, Atom selection, Atom targe X-FUNCTION: Pixmap XCreatePixmap ( Display* display, Drawable d, uint width, uint height, uint depth ) ; X-FUNCTION: int XFreePixmap ( Display* display, Pixmap pixmap ) ; +! 5.2 - Creating, Recoloring, and Freeing Cursors + +C-TYPE: XColor +X-FUNCTION: Cursor XCreatePixmapCursor ( Display* display, Pixmap source, Pixmap mask, XColor* foreground_color, XColor* background_color, uint x, uint y ) ; +X-FUNCTION: int XFreeCursor ( Display* display, Cursor cursor ) ; ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! 6 - Color Management Functions @@ -1096,6 +1101,7 @@ X-FUNCTION: int XGrabPointer ( X-FUNCTION: Status XUngrabPointer ( Display* display, Time time ) ; X-FUNCTION: Status XChangeActivePointerGrab ( Display* display, uint event_mask, Cursor cursor, Time time ) ; X-FUNCTION: Status XGrabKey ( Display* display, int keycode, uint modifiers, Window grab_window, Bool owner_events, int pointer_mode, int keyboard_mode ) ; +X-FUNCTION: int XGrabKeyboard ( Display* display, Window grab_window, Bool owner_events, int pointer_mode, int keyboard_mode, Time time ) ; X-FUNCTION: Status XSetInputFocus ( Display* display, Window focus, int revert_to, Time time ) ; X-FUNCTION: Status XGetInputFocus ( Display* display, @@ -1210,6 +1216,14 @@ STRUCT: XVisualInfo { colormap_size int } { bits_per_rgb int } ; +! 16.9 Manipulating Bitmaps +X-FUNCTION: Pixmap XCreateBitmapFromData ( + Display* display, + Drawable d, + char* data, + uint width, + uint height ) ; + ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! Appendix D - Compatibility Functions ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! From 5d80153d53671a6691feb1c72abffa38c902d940 Mon Sep 17 00:00:00 2001 From: Erik Charlebois Date: Thu, 18 Feb 2010 12:53:15 -0800 Subject: [PATCH 8/8] Bindings to libusb --- extra/libusb/authors.txt | 1 + extra/libusb/libusb.factor | 422 +++++++++++++++++++++++++++++++++++++ extra/libusb/summary.txt | 1 + extra/libusb/tags.txt | 1 + 4 files changed, 425 insertions(+) create mode 100644 extra/libusb/authors.txt create mode 100644 extra/libusb/libusb.factor create mode 100644 extra/libusb/summary.txt create mode 100644 extra/libusb/tags.txt diff --git a/extra/libusb/authors.txt b/extra/libusb/authors.txt new file mode 100644 index 0000000000..67cf648cf5 --- /dev/null +++ b/extra/libusb/authors.txt @@ -0,0 +1 @@ +Erik Charlebois \ No newline at end of file diff --git a/extra/libusb/libusb.factor b/extra/libusb/libusb.factor new file mode 100644 index 0000000000..d521015d6f --- /dev/null +++ b/extra/libusb/libusb.factor @@ -0,0 +1,422 @@ +! Copyright (C) 2010 Erik Charlebois. +! See http://factorcode.org/license.txt for BSD license. +USING: accessors alien alien.c-types alien.libraries +alien.syntax classes.struct combinators endian io.binary +kernel locals math sequences specialized-arrays +system unix.time unix.types ; +FROM: alien.c-types => short ; +IN: libusb + +<< "libusb" { + { [ os windows? ] [ "libusb-1.0.dll" ] } + { [ os macosx? ] [ "libusb-1.0.dylib" ] } + { [ os unix? ] [ "libusb-1.0.so" ] } + } cond "cdecl" add-library >> +LIBRARY: libusb + +: libusb_cpu_to_le16 ( x -- y ) + 2 >native-endian le> ; inline + +ALIAS: libusb_le16_to_cpu libusb_cpu_to_le16 + +CONSTANT: LIBUSB_CLASS_PER_INTERFACE 0 +CONSTANT: LIBUSB_CLASS_AUDIO 1 +CONSTANT: LIBUSB_CLASS_COMM 2 +CONSTANT: LIBUSB_CLASS_HID 3 +CONSTANT: LIBUSB_CLASS_PRINTER 7 +CONSTANT: LIBUSB_CLASS_PTP 6 +CONSTANT: LIBUSB_CLASS_MASS_STORAGE 8 +CONSTANT: LIBUSB_CLASS_HUB 9 +CONSTANT: LIBUSB_CLASS_DATA 10 +CONSTANT: LIBUSB_CLASS_VENDOR_SPEC HEX: ff +TYPEDEF: int libusb_class_code + +CONSTANT: LIBUSB_DT_DEVICE HEX: 01 +CONSTANT: LIBUSB_DT_CONFIG HEX: 02 +CONSTANT: LIBUSB_DT_STRING HEX: 03 +CONSTANT: LIBUSB_DT_INTERFACE HEX: 04 +CONSTANT: LIBUSB_DT_ENDPOINT HEX: 05 +CONSTANT: LIBUSB_DT_HID HEX: 21 +CONSTANT: LIBUSB_DT_REPORT HEX: 22 +CONSTANT: LIBUSB_DT_PHYSICAL HEX: 23 +CONSTANT: LIBUSB_DT_HUB HEX: 29 +TYPEDEF: int libusb_descriptor_type + +CONSTANT: LIBUSB_DT_DEVICE_SIZE 18 +CONSTANT: LIBUSB_DT_CONFIG_SIZE 9 +CONSTANT: LIBUSB_DT_INTERFACE_SIZE 9 +CONSTANT: LIBUSB_DT_ENDPOINT_SIZE 7 +CONSTANT: LIBUSB_DT_ENDPOINT_AUDIO_SIZE 9 +CONSTANT: LIBUSB_DT_HUB_NONVAR_SIZE 7 + +CONSTANT: LIBUSB_ENDPOINT_ADDRESS_MASK HEX: 0f +CONSTANT: LIBUSB_ENDPOINT_DIR_MASK HEX: 80 + +CONSTANT: LIBUSB_ENDPOINT_IN HEX: 80 +CONSTANT: LIBUSB_ENDPOINT_OUT HEX: 00 +TYPEDEF: int libusb_endpoint_direction + +CONSTANT: LIBUSB_TRANSFER_TYPE_MASK HEX: 03 + +CONSTANT: LIBUSB_TRANSFER_TYPE_CONTROL 0 +CONSTANT: LIBUSB_TRANSFER_TYPE_ISOCHRONOUS 1 +CONSTANT: LIBUSB_TRANSFER_TYPE_BULK 2 +CONSTANT: LIBUSB_TRANSFER_TYPE_INTERRUPT 3 +TYPEDEF: int libusb_transfer_type + +CONSTANT: LIBUSB_REQUEST_GET_STATUS HEX: 00 +CONSTANT: LIBUSB_REQUEST_CLEAR_FEATURE HEX: 01 +CONSTANT: LIBUSB_REQUEST_SET_FEATURE HEX: 03 +CONSTANT: LIBUSB_REQUEST_SET_ADDRESS HEX: 05 +CONSTANT: LIBUSB_REQUEST_GET_DESCRIPTOR HEX: 06 +CONSTANT: LIBUSB_REQUEST_SET_DESCRIPTOR HEX: 07 +CONSTANT: LIBUSB_REQUEST_GET_CONFIGURATION HEX: 08 +CONSTANT: LIBUSB_REQUEST_SET_CONFIGURATION HEX: 09 +CONSTANT: LIBUSB_REQUEST_GET_INTERFACE HEX: 0A +CONSTANT: LIBUSB_REQUEST_SET_INTERFACE HEX: 0B +CONSTANT: LIBUSB_REQUEST_SYNCH_FRAME HEX: 0C +TYPEDEF: int libusb_standard_request + +CONSTANT: LIBUSB_REQUEST_TYPE_STANDARD HEX: 00 +CONSTANT: LIBUSB_REQUEST_TYPE_CLASS HEX: 20 +CONSTANT: LIBUSB_REQUEST_TYPE_VENDOR HEX: 40 +CONSTANT: LIBUSB_REQUEST_TYPE_RESERVED HEX: 60 + +CONSTANT: LIBUSB_RECIPIENT_DEVICE HEX: 00 +CONSTANT: LIBUSB_RECIPIENT_INTERFACE HEX: 01 +CONSTANT: LIBUSB_RECIPIENT_ENDPOINT HEX: 02 +CONSTANT: LIBUSB_RECIPIENT_OTHER HEX: 03 +TYPEDEF: int libusb_request_recipient + +CONSTANT: LIBUSB_ISO_SYNC_TYPE_MASK HEX: 0C + +CONSTANT: LIBUSB_ISO_SYNC_TYPE_NONE 0 +CONSTANT: LIBUSB_ISO_SYNC_TYPE_ASYNC 1 +CONSTANT: LIBUSB_ISO_SYNC_TYPE_ADAPTIVE 2 +CONSTANT: LIBUSB_ISO_SYNC_TYPE_SYNC 3 +TYPEDEF: int libusb_iso_sync_type + +CONSTANT: LIBUSB_ISO_USAGE_TYPE_MASK HEX: 30 + +CONSTANT: LIBUSB_ISO_USAGE_TYPE_DATA 0 +CONSTANT: LIBUSB_ISO_USAGE_TYPE_FEEDBACK 1 +CONSTANT: LIBUSB_ISO_USAGE_TYPE_IMPLICIT 2 +TYPEDEF: int libusb_iso_usage_type + +STRUCT: libusb_device_descriptor + { bLength uint8_t } + { bDescriptorType uint8_t } + { bcdUSB uint16_t } + { bDeviceClass uint8_t } + { bDeviceSubClass uint8_t } + { bDeviceProtocol uint8_t } + { bMaxPacketSize0 uint8_t } + { idVendor uint16_t } + { idProduct uint16_t } + { bcdDevice uint16_t } + { iManufacturer uint8_t } + { iProduct uint8_t } + { iSerialNumber uint8_t } + { bNumConfigurations uint8_t } ; + +STRUCT: libusb_endpoint_descriptor + { bLength uint8_t } + { bDescriptorType uint8_t } + { bEndpointAddress uint8_t } + { bmAttributes uint8_t } + { wMaxPacketSize uint16_t } + { bInterval uint8_t } + { bRefresh uint8_t } + { bSynchAddress uint8_t } + { extra uchar* } + { extra_length int } ; + +STRUCT: libusb_interface_descriptor + { bLength uint8_t } + { bDescriptorType uint8_t } + { bInterfaceNumber uint8_t } + { bAlternateSetting uint8_t } + { bNumEndpoints uint8_t } + { bInterfaceClass uint8_t } + { bInterfaceSubClass uint8_t } + { bInterfaceProtocol uint8_t } + { iInterface uint8_t } + { endpoint libusb_endpoint_descriptor* } + { extra uchar* } + { extra_length int } ; + +STRUCT: libusb_interface + { altsetting libusb_interface_descriptor* } + { num_altsetting int } ; + +STRUCT: libusb_config_descriptor + { bLength uint8_t } + { bDescriptorType uint8_t } + { wTotalLength uint16_t } + { bNumInterfaces uint8_t } + { bConfigurationValue uint8_t } + { iConfiguration uint8_t } + { bmAttributes uint8_t } + { MaxPower uint8_t } + { interface libusb_interface* } + { extra uchar* } + { extra_length int } ; + +STRUCT: libusb_control_setup + { bmRequestType uint8_t } + { bRequest uint8_t } + { wValue uint16_t } + { wIndex uint16_t } + { wLength uint16_t } ; + +: LIBUSB_CONTROL_SETUP_SIZE ( -- x ) libusb_control_setup heap-size ; inline + +C-TYPE: libusb_context +C-TYPE: libusb_device +C-TYPE: libusb_device_handle + +CONSTANT: LIBUSB_SUCCESS 0 +CONSTANT: LIBUSB_ERROR_IO -1 +CONSTANT: LIBUSB_ERROR_INVALID_PARAM -2 +CONSTANT: LIBUSB_ERROR_ACCESS -3 +CONSTANT: LIBUSB_ERROR_NO_DEVICE -4 +CONSTANT: LIBUSB_ERROR_NOT_FOUND -5 +CONSTANT: LIBUSB_ERROR_BUSY -6 +CONSTANT: LIBUSB_ERROR_TIMEOUT -7 +CONSTANT: LIBUSB_ERROR_OVERFLOW -8 +CONSTANT: LIBUSB_ERROR_PIPE -9 +CONSTANT: LIBUSB_ERROR_INTERRUPTED -10 +CONSTANT: LIBUSB_ERROR_NO_MEM -11 +CONSTANT: LIBUSB_ERROR_NOT_SUPPORTED -12 +CONSTANT: LIBUSB_ERROR_OTHER -99 +TYPEDEF: int libusb_error + +C-ENUM: + LIBUSB_TRANSFER_COMPLETED + LIBUSB_TRANSFER_ERROR + LIBUSB_TRANSFER_TIMED_OUT + LIBUSB_TRANSFER_CANCELLED + LIBUSB_TRANSFER_STALL + LIBUSB_TRANSFER_NO_DEVICE + LIBUSB_TRANSFER_OVERFLOW ; +TYPEDEF: int libusb_transfer_status + +CONSTANT: LIBUSB_TRANSFER_SHORT_NOT_OK 1 +CONSTANT: LIBUSB_TRANSFER_FREE_BUFFER 2 +CONSTANT: LIBUSB_TRANSFER_FREE_TRANSFER 4 +TYPEDEF: int libusb_transfer_flags + +STRUCT: libusb_iso_packet_descriptor + { length uint } + { actual_length uint } + { status libusb_transfer_status } ; +SPECIALIZED-ARRAY: libusb_iso_packet_descriptor + +C-TYPE: libusb_transfer + +CALLBACK: void libusb_transfer_cb_fn ( libusb_transfer* transfer ) ; + +STRUCT: libusb_transfer + { dev_handle libusb_device_handle* } + { flags uint8_t } + { endpoint uchar } + { type uchar } + { timeout uint } + { status libusb_transfer_status } + { length int } + { actual_length int } + { callback libusb_transfer_cb_fn } + { user_data void* } + { buffer uchar* } + { num_iso_packets int } + { iso_packet_desc libusb_iso_packet_descriptor[0] } ; + +FUNCTION: int libusb_init ( libusb_context** ctx ) ; +FUNCTION: void libusb_exit ( libusb_context* ctx ) ; +FUNCTION: void libusb_set_debug ( libusb_context* ctx, int level ) ; + +FUNCTION: ssize_t libusb_get_device_list ( libusb_context* ctx, libusb_device*** list ) ; +FUNCTION: void libusb_free_device_list ( libusb_device** list, int unref_devices ) ; +FUNCTION: libusb_device* libusb_ref_device ( libusb_device* dev ) ; +FUNCTION: void libusb_unref_device ( libusb_device* dev ) ; + +FUNCTION: int libusb_get_configuration ( libusb_device_handle* dev, int* config ) ; +FUNCTION: int libusb_get_device_descriptor ( libusb_device* dev, libusb_device_descriptor* desc ) ; +FUNCTION: int libusb_get_active_config_descriptor ( libusb_device* dev, libusb_config_descriptor** config ) ; +FUNCTION: int libusb_get_config_descriptor ( libusb_device* dev, uint8_t config_index, libusb_config_descriptor** config ) ; +FUNCTION: int libusb_get_config_descriptor_by_value ( libusb_device* dev, uint8_t bConfigurationValue, libusb_config_descriptor** config ) ; +FUNCTION: void libusb_free_config_descriptor ( libusb_config_descriptor* config ) ; +FUNCTION: uint8_t libusb_get_bus_number ( libusb_device* dev ) ; +FUNCTION: uint8_t libusb_get_device_address ( libusb_device* dev ) ; +FUNCTION: int libusb_get_max_packet_size ( libusb_device* dev, uchar endpoint ) ; + +FUNCTION: int libusb_open ( libusb_device* dev, libusb_device_handle** handle ) ; +FUNCTION: void libusb_close ( libusb_device_handle* dev_handle ) ; +FUNCTION: libusb_device* libusb_get_device ( libusb_device_handle* dev_handle ) ; + +FUNCTION: int libusb_set_configuration ( libusb_device_handle* dev, int configuration ) ; +FUNCTION: int libusb_claim_interface ( libusb_device_handle* dev, int iface ) ; +FUNCTION: int libusb_release_interface ( libusb_device_handle* dev, int iface ) ; + +FUNCTION: libusb_device_handle* libusb_open_device_with_vid_pid ( libusb_context* ctx, uint16_t vendor_id, uint16_t product_id ) ; + +FUNCTION: int libusb_set_interface_alt_setting ( libusb_device_handle* dev, int interface_number, int alternate_setting ) ; +FUNCTION: int libusb_clear_halt ( libusb_device_handle* dev, uchar endpoint ) ; +FUNCTION: int libusb_reset_device ( libusb_device_handle* dev ) ; + +FUNCTION: int libusb_kernel_driver_active ( libusb_device_handle* dev, int interface ) ; +FUNCTION: int libusb_detach_kernel_driver ( libusb_device_handle* dev, int interface ) ; +FUNCTION: int libusb_attach_kernel_driver ( libusb_device_handle* dev, int interface ) ; + +: libusb_control_transfer_get_data ( transfer -- data ) + buffer>> LIBUSB_CONTROL_SETUP_SIZE swap ; inline + +: libusb_control_transfer_get_setup ( transfer -- setup ) + buffer>> libusb_control_setup memory>struct ; inline + +:: libusb_fill_control_setup ( buffer bmRequestType bRequest wValue wIndex wLength -- ) + buffer libusb_control_setup memory>struct + bmRequestType >>bmRequestType + bRequest >>bRequest + wValue libusb_cpu_to_le16 >>wValue + wIndex libusb_cpu_to_le16 >>wIndex + wLength libusb_cpu_to_le16 >>wLength drop ; inline + +FUNCTION: libusb_transfer* libusb_alloc_transfer ( int iso_packets ) ; +FUNCTION: int libusb_submit_transfer ( libusb_transfer* transfer ) ; +FUNCTION: int libusb_cancel_transfer ( libusb_transfer* transfer ) ; +FUNCTION: void libusb_free_transfer ( libusb_transfer* transfer ) ; + +:: libusb_fill_control_transfer ( transfer dev_handle buffer callback user_data timeout -- ) + transfer + dev_handle >>dev_handle + 0 >>endpoint + LIBUSB_TRANSFER_TYPE_CONTROL >>type + timeout >>timeout + buffer >>buffer + user_data >>user_data + callback >>callback + + buffer [ + libusb_control_setup memory>struct wLength>> LIBUSB_CONTROL_SETUP_SIZE + + ] [ 0 ] if* >>length drop ; inline + +:: libusb_fill_bulk_transfer ( transfer dev_handle endpoint buffer length callback user_data timeout -- ) + transfer + dev_handle >>dev_handle + endpoint >>endpoint + LIBUSB_TRANSFER_TYPE_BULK >>type + timeout >>timeout + buffer >>buffer + length >>length + user_data >>user_data + callback >>callback + drop ; inline + +:: libusb_fill_interrupt_transfer ( transfer dev_handle endpoint buffer length callback user_data timeout -- ) + transfer + dev_handle >>dev_handle + endpoint >>endpoint + LIBUSB_TRANSFER_TYPE_INTERRUPT >>type + timeout >>timeout + buffer >>buffer + length >>length + user_data >>user_data + callback >>callback + drop ; inline + +:: libusb_fill_iso_transfer ( transfer dev_handle endpoint buffer length num_iso_packets callback user_data timeout -- ) + transfer + dev_handle >>dev_handle + endpoint >>endpoint + LIBUSB_TRANSFER_TYPE_ISOCHRONOUS >>type + timeout >>timeout + buffer >>buffer + length >>length + num_iso_packets >>num_iso_packets + user_data >>user_data + callback >>callback + drop ; inline + +: libusb_set_iso_packet_lengths ( transfer length -- ) + [ [ iso_packet_desc>> >c-ptr ] + [ num_iso_packets>> ] bi + + ] dip [ >>length drop ] curry each ; inline + +:: libusb_get_iso_packet_buffer ( transfer packet -- data ) + packet transfer num_iso_packets>> >= + [ f ] + [ + transfer + [ iso_packet_desc>> >c-ptr ] + [ num_iso_packets>> ] bi + 0 + [ length>> + ] reduce + transfer buffer>> + ] if ; + +:: libusb_get_iso_packet_buffer_simple ( transfer packet -- data ) + packet transfer num_iso_packets>> >= + [ f ] + [ + 0 transfer + [ iso_packet_desc>> >c-ptr ] + [ num_iso_packets>> ] bi + nth + length>> packet * + transfer buffer>> + ] if ; + +FUNCTION: int libusb_control_transfer ( libusb_device_handle* dev_handle, + uint8_t request_type, uint8_t request, uint16_t value, uint16_t index, + uchar* data, uint16_t length, uint timeout ) ; + +FUNCTION: int libusb_bulk_transfer ( libusb_device_handle* dev_handle, + uchar endpoint, uchar* data, int length, + int* actual_length, uint timeout ) ; + +FUNCTION: int libusb_interrupt_transfer ( libusb_device_handle* dev_handle, + uchar endpoint, uchar* data, int length, + int* actual_length, int timeout ) ; + +:: libusb_get_descriptor ( dev desc_type desc_index data length -- int ) + dev LIBUSB_ENDPOINT_IN LIBUSB_REQUEST_GET_DESCRIPTOR + desc_type 8 shift desc_index bitor 0 data + length 1000 libusb_control_transfer ; inline + +:: libusb_get_string_descriptor ( dev desc_index langid data length -- int ) + dev LIBUSB_ENDPOINT_IN LIBUSB_REQUEST_GET_DESCRIPTOR + LIBUSB_DT_STRING 8 shift desc_index bitor + langid data length 1000 libusb_control_transfer ; inline + +FUNCTION: int libusb_get_string_descriptor_ascii ( libusb_device_handle* dev, + uint8_t index, + uchar* data, + int length ) ; + +FUNCTION: int libusb_try_lock_events ( libusb_context* ctx ) ; +FUNCTION: void libusb_lock_events ( libusb_context* ctx ) ; +FUNCTION: void libusb_unlock_events ( libusb_context* ctx ) ; +FUNCTION: int libusb_event_handling_ok ( libusb_context* ctx ) ; +FUNCTION: int libusb_event_handler_active ( libusb_context* ctx ) ; +FUNCTION: void libusb_lock_event_waiters ( libusb_context* ctx ) ; +FUNCTION: void libusb_unlock_event_waiters ( libusb_context* ctx ) ; +FUNCTION: int libusb_wait_for_event ( libusb_context* ctx, timeval* tv ) ; +FUNCTION: int libusb_handle_events_timeout ( libusb_context* ctx, timeval* tv ) ; +FUNCTION: int libusb_handle_events ( libusb_context* ctx ) ; +FUNCTION: int libusb_handle_events_locked ( libusb_context* ctx, timeval* tv ) ; +FUNCTION: int libusb_get_next_timeout ( libusb_context* ctx, timeval* tv ) ; + +STRUCT: libusb_pollfd + { fd int } + { events short } ; + +CALLBACK: void libusb_pollfd_added_cb ( int fd, short events, void* user_data ) ; +CALLBACK: void libusb_pollfd_removed_cb ( int fd, void* user_data ) ; + +FUNCTION: libusb_pollfd** libusb_get_pollfds ( libusb_context* ctx ) ; +FUNCTION: void libusb_set_pollfd_notifiers ( libusb_context* ctx, + libusb_pollfd_added_cb added_cb, + libusb_pollfd_removed_cb removed_cb, + void* user_data ) ; diff --git a/extra/libusb/summary.txt b/extra/libusb/summary.txt new file mode 100644 index 0000000000..fc00ac5307 --- /dev/null +++ b/extra/libusb/summary.txt @@ -0,0 +1 @@ +Bindings to libusb diff --git a/extra/libusb/tags.txt b/extra/libusb/tags.txt new file mode 100644 index 0000000000..bb863cf9a0 --- /dev/null +++ b/extra/libusb/tags.txt @@ -0,0 +1 @@ +bindings