From 2172fd75071a842f6b43764c9abde845a8742d6c Mon Sep 17 00:00:00 2001 From: terry feng Date: Wed, 24 Jul 2024 17:32:35 -0700 Subject: [PATCH 01/27] bump documentation hash --- docs/classes/Chuck.html | 116 ++++++++++++++++++++-------------------- docs/classes/HID.html | 32 +++++------ 2 files changed, 74 insertions(+), 74 deletions(-) diff --git a/docs/classes/Chuck.html b/docs/classes/Chuck.html index 6257fc1..79198fe 100644 --- a/docs/classes/Chuck.html +++ b/docs/classes/Chuck.html @@ -27,7 +27,7 @@

Hierarchy

+
  • Defined in src/Chuck.ts:30
  • @@ -148,39 +148,39 @@

    Returns

    +
  • Defined in src/Chuck.ts:51
  • Properties

    deferredPromises: DeferredPromisesMap = {}
    +
  • Defined in src/Chuck.ts:31
  • deferredPromiseCounter: number = 0
    +
  • Defined in src/Chuck.ts:32
  • eventCallbacks: EventCallbacksMap = {}
    +
  • Defined in src/Chuck.ts:33
  • eventCallbackCounter: number = 0
    +
  • Defined in src/Chuck.ts:34
  • isReady: default<void> = ...
    +
  • Defined in src/Chuck.ts:35
  • chugins: string[] = []
    +
  • Defined in src/Chuck.ts:41
  • onprocessorerror: null | ((this, ev) => any)
    @@ -265,7 +265,7 @@

    Parameters

    +
  • Defined in src/Chuck.ts:111
  • +
  • Defined in src/Chuck.ts:218
  • +
  • Defined in src/Chuck.ts:153
  • +
  • Defined in src/Chuck.ts:168
  • +
  • Defined in src/Chuck.ts:184
  • +
  • Defined in src/Chuck.ts:228
  • +
  • Defined in src/Chuck.ts:238
  • +
  • Defined in src/Chuck.ts:268
  • +
  • Defined in src/Chuck.ts:307
  • +
  • Defined in src/Chuck.ts:327
  • +
  • Defined in src/Chuck.ts:362
  • +
  • Defined in src/Chuck.ts:402
  • +
  • Defined in src/Chuck.ts:445
  • +
  • Defined in src/Chuck.ts:494
  • +
  • Defined in src/Chuck.ts:508
  • +
  • Defined in src/Chuck.ts:522
  • +
  • Defined in src/Chuck.ts:530
  • +
  • Defined in src/Chuck.ts:541
  • +
  • Defined in src/Chuck.ts:559
  • +
  • Defined in src/Chuck.ts:575
  • +
  • Defined in src/Chuck.ts:589
  • +
  • Defined in src/Chuck.ts:599
  • +
  • Defined in src/Chuck.ts:613
  • +
  • Defined in src/Chuck.ts:622
  • +
  • Defined in src/Chuck.ts:636
  • +
  • Defined in src/Chuck.ts:645
  • +
  • Defined in src/Chuck.ts:660
  • +
  • Defined in src/Chuck.ts:669
  • +
  • Defined in src/Chuck.ts:684
  • +
  • Defined in src/Chuck.ts:698
  • +
  • Defined in src/Chuck.ts:716
  • +
  • Defined in src/Chuck.ts:731
  • +
  • Defined in src/Chuck.ts:747
  • +
  • Defined in src/Chuck.ts:757
  • +
  • Defined in src/Chuck.ts:772
  • +
  • Defined in src/Chuck.ts:787
  • +
  • Defined in src/Chuck.ts:805
  • +
  • Defined in src/Chuck.ts:820
  • +
  • Defined in src/Chuck.ts:837
  • +
  • Defined in src/Chuck.ts:846
  • +
  • Defined in src/Chuck.ts:860
  • +
  • Defined in src/Chuck.ts:868
  • +
  • Defined in src/Chuck.ts:882
  • +
  • Defined in src/Chuck.ts:891
  • +
  • Defined in src/Chuck.ts:905
  • +
  • Defined in src/Chuck.ts:915
  • +
  • Defined in src/Chuck.ts:922
  • +
  • Defined in src/Chuck.ts:943
    • diff --git a/docs/classes/HID.html b/docs/classes/HID.html index 691377e..8325063 100644 --- a/docs/classes/HID.html +++ b/docs/classes/HID.html @@ -31,7 +31,7 @@

      Hierarchy

      • HID
    +
  • Defined in src/Hid.ts:27
  • @@ -64,22 +64,22 @@

    Properties

    theChuck: Chuck
    +
  • Defined in src/Hid.ts:29
  • keymap: boolean[]
    +
  • Defined in src/Hid.ts:30
  • _mouseActive: boolean = false
    +
  • Defined in src/Hid.ts:31
  • _kbdActive: boolean = false
    +
  • Defined in src/Hid.ts:32
  • boundHandleMouseMove: {}
    @@ -89,7 +89,7 @@

    Type declaration

    • +
    • Defined in src/Hid.ts:35
    • boundHandleMouseDown: {}
      @@ -99,7 +99,7 @@

      Type declaration

      • +
      • Defined in src/Hid.ts:36
      • boundHandleMouseUp: {}
        @@ -109,7 +109,7 @@

        Type declaration

        • +
        • Defined in src/Hid.ts:37
        • boundHandleMouseWheel: {}
          @@ -119,7 +119,7 @@

          Type declaration

          • +
          • Defined in src/Hid.ts:38
          • boundHandleKeyDown: {}
            @@ -129,7 +129,7 @@

            Type declaration

            • +
            • Defined in src/Hid.ts:39
            • boundHandleKeyUp: {}
              @@ -139,7 +139,7 @@

              Type declaration

              • +
              • Defined in src/Hid.ts:40
              • Methods

                @@ -178,7 +178,7 @@

                Example

                theChuck
                +
              • Defined in src/Hid.ts:75
                • @@ -194,7 +194,7 @@

                  Example

                  // If mouse HI
                   
                +
              • Defined in src/Hid.ts:136
                • @@ -208,7 +208,7 @@

                  Example

                  // If mouse HI
                   
                +
              • Defined in src/Hid.ts:152
                • @@ -223,7 +223,7 @@

                  Example

                  // If keyboard
                   
                +
              • Defined in src/Hid.ts:169
                • @@ -237,7 +237,7 @@

                  Example

                  // If keyboard
                   
                +
              • Defined in src/Hid.ts:182
              • +
              • Defined in src/Chuck.ts:235
                • @@ -336,7 +342,7 @@

                  Returns number

                +
              • Defined in src/Chuck.ts:159
              • +
              • Defined in src/Chuck.ts:174
              • +
                + +
                  + +
                • +

                  Create a virtual directory in ChucK's filesystem.

                  +
                  +
                  +

                  Parameters

                  +
                    +
                  • +
                    parent: string
                    +

                    Virtual directory to create the new directory in

                    +
                    +
                  • +
                  • +
                    name: string
                    +

                    Name of directory to create

                    +
                    +
                  +

                  Returns void

                  +
                +
              • Defined in src/Chuck.ts:201
              • +
              • Defined in src/Chuck.ts:245
              • +
              • Defined in src/Chuck.ts:255
              • +
              • Defined in src/Chuck.ts:285
              • +
              • Defined in src/Chuck.ts:324
              • +
              • Defined in src/Chuck.ts:344
              • +
              • Defined in src/Chuck.ts:379
              • +
              • Defined in src/Chuck.ts:419
              • +
              • Defined in src/Chuck.ts:462
              • +
              • Defined in src/Chuck.ts:511
              • +
              • Defined in src/Chuck.ts:525
              • +
              • Defined in src/Chuck.ts:539
              • +
              • Defined in src/Chuck.ts:547
              • +
              • Defined in src/Chuck.ts:558
              • +
              • Defined in src/Chuck.ts:576
              • +
              • Defined in src/Chuck.ts:592
              • +
              • Defined in src/Chuck.ts:606
              • +
              • Defined in src/Chuck.ts:616
              • +
              • Defined in src/Chuck.ts:630
              • +
              • Defined in src/Chuck.ts:639
              • +
              • Defined in src/Chuck.ts:653
              • +
              • Defined in src/Chuck.ts:662
              • +
              • Defined in src/Chuck.ts:677
              • +
              • Defined in src/Chuck.ts:686
              • +
              • Defined in src/Chuck.ts:701
              • +
              • Defined in src/Chuck.ts:715
              • +
              • Defined in src/Chuck.ts:733
              • +
              • Defined in src/Chuck.ts:748
              • +
              • Defined in src/Chuck.ts:764
              • +
              • Defined in src/Chuck.ts:774
              • +
              • Defined in src/Chuck.ts:789
              • +
              • Defined in src/Chuck.ts:804
              • +
              • Defined in src/Chuck.ts:822
              • +
              • Defined in src/Chuck.ts:837
              • +
              • Defined in src/Chuck.ts:854
              • +
              • Defined in src/Chuck.ts:863
              • +
              • Defined in src/Chuck.ts:877
              • +
              • Defined in src/Chuck.ts:885
              • +
              • Defined in src/Chuck.ts:899
              • +
              • Defined in src/Chuck.ts:908
              • +
              • Defined in src/Chuck.ts:922
              • +
              • Defined in src/Chuck.ts:932
              • +
              • Defined in src/Chuck.ts:939
              • +
              • Defined in src/Chuck.ts:960
              • Class HID

                -

                Introducing HID (Human Interface Device) support for WebChucK. HID wraps +

                HID (Human Interface Device) support for WebChucK. HID wraps JavaScript mouse/keyboard event listeners enabling mouse and keyboard -communication with the native HID +input via the HID class in ChucK.

                To get started with HID:

                @@ -31,7 +31,7 @@

                Hierarchy

                • HID
                +
              • Defined in src/Hid.ts:27
              • @@ -64,22 +64,22 @@

                Properties

                theChuck: Chuck
                +
              • Defined in src/Hid.ts:29
              • keymap: boolean[]
                +
              • Defined in src/Hid.ts:30
              • _mouseActive: boolean = false
                +
              • Defined in src/Hid.ts:31
              • _kbdActive: boolean = false
                +
              • Defined in src/Hid.ts:32
              • boundHandleMouseMove: {}
                @@ -89,7 +89,7 @@

                Type declaration

                • +
                • Defined in src/Hid.ts:35
                • boundHandleMouseDown: {}
                  @@ -99,7 +99,7 @@

                  Type declaration

                  • +
                  • Defined in src/Hid.ts:36
                  • boundHandleMouseUp: {}
                    @@ -109,7 +109,7 @@

                    Type declaration

                    • +
                    • Defined in src/Hid.ts:37
                    • boundHandleMouseWheel: {}
                      @@ -119,7 +119,7 @@

                      Type declaration

                      • +
                      • Defined in src/Hid.ts:38
                      • boundHandleKeyDown: {}
                        @@ -129,7 +129,7 @@

                        Type declaration

                        • +
                        • Defined in src/Hid.ts:39
                        • boundHandleKeyUp: {}
                          @@ -139,7 +139,7 @@

                          Type declaration

                          • +
                          • Defined in src/Hid.ts:40
                          • Methods

                            @@ -178,7 +178,7 @@

                            Example

                            theChuck
                            +
                          • Defined in src/Hid.ts:75
                            • @@ -194,7 +194,7 @@

                              Example

                              // If mouse HI
                               
                            +
                          • Defined in src/Hid.ts:136
                            • @@ -208,7 +208,7 @@

                              Example

                              // If mouse HI
                               
                            +
                          • Defined in src/Hid.ts:152
                            • @@ -223,7 +223,7 @@

                              Example

                              // If keyboard
                               
                            +
                          • Defined in src/Hid.ts:169
                            • @@ -237,7 +237,7 @@

                              Example

                              // If keyboard
                               
                            +
                          • Defined in src/Hid.ts:182
                          • +
                          • Defined in src/Chuck.ts:117
                            • @@ -329,7 +329,7 @@

                              Example

                              Chuck
                            +
                          • Defined in src/Chuck.ts:235
                          • +
                          • Defined in src/Chuck.ts:159
                          • +
                          • Defined in src/Chuck.ts:174
                          • +
                          • Defined in src/Chuck.ts:186
                          • +
                          • Defined in src/Chuck.ts:201
                          • +
                          • Defined in src/Chuck.ts:245
                          • +
                          • Defined in src/Chuck.ts:255
                          • +
                          • Defined in src/Chuck.ts:285
                          • +
                          • Defined in src/Chuck.ts:324
                          • +
                          • Defined in src/Chuck.ts:344
                          • +
                          • Defined in src/Chuck.ts:379
                          • +
                          • Defined in src/Chuck.ts:419
                          • +
                          • Defined in src/Chuck.ts:462
                          • +
                          • Defined in src/Chuck.ts:511
                          • +
                          • Defined in src/Chuck.ts:525
                          • +
                          • Defined in src/Chuck.ts:539
                          • +
                          • Defined in src/Chuck.ts:547
                          • +
                          • Defined in src/Chuck.ts:558
                          • +
                          • Defined in src/Chuck.ts:576
                          • +
                          • Defined in src/Chuck.ts:592
                          • +
                          • Defined in src/Chuck.ts:606
                          • +
                          • Defined in src/Chuck.ts:616
                          • +
                          • Defined in src/Chuck.ts:630
                          • +
                          • Defined in src/Chuck.ts:639
                          • +
                          • Defined in src/Chuck.ts:653
                          • +
                          • Defined in src/Chuck.ts:662
                          • +
                          • Defined in src/Chuck.ts:677
                          • +
                          • Defined in src/Chuck.ts:686
                          • +
                          • Defined in src/Chuck.ts:701
                          • +
                          • Defined in src/Chuck.ts:715
                          • +
                          • Defined in src/Chuck.ts:733
                          • +
                          • Defined in src/Chuck.ts:748
                          • +
                          • Defined in src/Chuck.ts:764
                          • +
                          • Defined in src/Chuck.ts:774
                          • +
                          • Defined in src/Chuck.ts:789
                          • +
                          • Defined in src/Chuck.ts:804
                          • +
                          • Defined in src/Chuck.ts:822
                          • +
                          • Defined in src/Chuck.ts:837
                          • +
                          • Defined in src/Chuck.ts:854
                          • +
                          • Defined in src/Chuck.ts:863
                          • +
                          • Defined in src/Chuck.ts:877
                          • +
                          • Defined in src/Chuck.ts:885
                          • +
                          • Defined in src/Chuck.ts:899
                          • +
                          • Defined in src/Chuck.ts:908
                          • +
                          • Defined in src/Chuck.ts:922
                          • +
                          • Defined in src/Chuck.ts:932
                          • +
                          • Defined in src/Chuck.ts:939
                          • +
                          • Defined in src/Chuck.ts:960
                          • \ No newline at end of file diff --git a/docs/classes/HID.html b/docs/classes/HID.html index 07ba628..e457388 100644 --- a/docs/classes/HID.html +++ b/docs/classes/HID.html @@ -31,7 +31,7 @@

                            Hierarchy

                            • HID
                            +
                          • Defined in src/Hid.ts:27
                          • @@ -64,22 +64,22 @@

                            Properties

                            theChuck: Chuck
                            +
                          • Defined in src/Hid.ts:29
                          • keymap: boolean[]
                            +
                          • Defined in src/Hid.ts:30
                          • _mouseActive: boolean = false
                            +
                          • Defined in src/Hid.ts:31
                          • _kbdActive: boolean = false
                            +
                          • Defined in src/Hid.ts:32
                          • boundHandleMouseMove: {}
                            @@ -89,7 +89,7 @@

                            Type declaration

                            • +
                            • Defined in src/Hid.ts:35
                            • boundHandleMouseDown: {}
                              @@ -99,7 +99,7 @@

                              Type declaration

                              • +
                              • Defined in src/Hid.ts:36
                              • boundHandleMouseUp: {}
                                @@ -109,7 +109,7 @@

                                Type declaration

                                • +
                                • Defined in src/Hid.ts:37
                                • boundHandleMouseWheel: {}
                                  @@ -119,7 +119,7 @@

                                  Type declaration

                                  • +
                                  • Defined in src/Hid.ts:38
                                  • boundHandleKeyDown: {}
                                    @@ -129,7 +129,7 @@

                                    Type declaration

                                    • +
                                    • Defined in src/Hid.ts:39
                                    • boundHandleKeyUp: {}
                                      @@ -139,7 +139,7 @@

                                      Type declaration

                                      • +
                                      • Defined in src/Hid.ts:40
                                      • Methods

                                        @@ -178,7 +178,7 @@

                                        Example

                                        theChuck
                                        +
                                      • Defined in src/Hid.ts:75
                                        • @@ -194,7 +194,7 @@

                                          Example

                                          // If mouse HI
                                           
                                        +
                                      • Defined in src/Hid.ts:136
                                        • @@ -208,7 +208,7 @@

                                          Example

                                          // If mouse HI
                                           
                                        +
                                      • Defined in src/Hid.ts:152
                                        • @@ -223,7 +223,7 @@

                                          Example

                                          // If keyboard
                                           
                                        +
                                      • Defined in src/Hid.ts:169
                                        • @@ -237,7 +237,7 @@

                                          Example

                                          // If keyboard
                                           
                                        +
                                      • Defined in src/Hid.ts:182
                                      • +
                                      • HID
                                      • +
                                      • Gyro
                                      • +
                                      • Accel
                                      • \ No newline at end of file diff --git a/docs/index.html b/docs/index.html index 7b2ce14..38e381d 100644 --- a/docs/index.html +++ b/docs/index.html @@ -73,5 +73,7 @@

                                        webchuck +
                                      • HID
                                      • +
                                      • Gyro
                                      • +
                                      • Accel
                                      • \ No newline at end of file diff --git a/docs/modules.html b/docs/modules.html index 1f1c4c5..192d4e1 100644 --- a/docs/modules.html +++ b/docs/modules.html @@ -19,6 +19,8 @@

                                        Index

                                        Classes

                                        +
                                        +
                                        +
                                          +
                                        • Preparing search index...
                                        • +
                                        • The search index is not available
                                        webchuck
                                        +
                                        +
                                        +
                                        +
                                        + +

                                        Class Accel

                                        +
                                        +

                                        Introducing Accel (accelerometer, on mobile) support for WebChucK. Accel wraps +JavaScript DeviceMotionEvent listeners easing access to mobile device accelerometers +in WebChucK code.

                                        +

                                        To get started with Accel:

                                        +
                                        +
                                        +

                                        Example

                                        import { Chuck, Accel } from "webchuck";

                                        const theChuck = await Chuck.init([]);
                                        const accel = await Accel.init(theChuck); // Initialize Accel +
                                        +
                                        +
                                        +

                                        Hierarchy

                                        +
                                          +
                                        • Accel
                                        +
                                        +
                                        +
                                        + +
                                        +
                                        +

                                        Properties

                                        +
                                        + +
                                        theChuck: Chuck
                                        +
                                        + +
                                        _accelActive: boolean = false
                                        +
                                        + +
                                        boundHandleMotion: {}
                                        +
                                        +

                                        Type declaration

                                        +
                                          +
                                        • +
                                          +
                                          +

                                          Methods

                                          +
                                          + +
                                            + +
                                          • +

                                            Initialize Accel functionality in your WebChucK instance. +This adds a Accel and AccelMsg class to the ChucK Virtual Machine (VM). +Accelerometer event (DeviceMotionEvent) listeners are added if enableAccel is true (default).

                                            +
                                            +
                                            +

                                            Parameters

                                            +
                                              +
                                            • +
                                              theChuck: Chuck
                                            • +
                                            • +
                                              enableAccel: boolean = true
                                            +

                                            Returns Promise<Accel>

                                            +
                                            +

                                            Example

                                            theChuck = await Chuck.init([]);
                                            accel = await Accel.init(theChuck); // Initialize Accel +
                                            +
                                          +
                                          + +
                                            + +
                                          • +

                                            Enable Javascript event (DeviceMotionEvent) listeners for Accel

                                            +
                                            +

                                            Returns void

                                            +
                                            +

                                            Example

                                            // If accel is not yet enabled
                                            accel.enableAccel(); +
                                            +
                                          +
                                          + +
                                            + +
                                          • +

                                            Disable Javascript event (DeviceMotionEvent) listeners for Accel

                                            +
                                            +

                                            Returns void

                                            +
                                            +

                                            Example

                                            // If accel is enabled
                                            accel.disableAccel(); +
                                            +
                                          +
                                          + +
                                          +
                                          \ No newline at end of file diff --git a/docs/classes/Gyro.html b/docs/classes/Gyro.html new file mode 100644 index 0000000..586ec74 --- /dev/null +++ b/docs/classes/Gyro.html @@ -0,0 +1,156 @@ +Gyro | webchuck
                                          +
                                          + +
                                          +
                                          +
                                          +
                                          + +

                                          Class Gyro

                                          +
                                          +

                                          Introducing Gyro (gyroerometer, on mobile) support for WebChucK. Gyro wraps +JavaScript DeviceMotionEvent listeners easing access to mobile device gyroerometers +in WebChucK code.

                                          +

                                          To get started with Gyro:

                                          +
                                          +
                                          +

                                          Example

                                          import { Chuck, Gyro } from "webchuck";

                                          const theChuck = await Chuck.init([]);
                                          const gyro = await Gyro.init(theChuck); // Initialize Gyro +
                                          +
                                          +
                                          +

                                          Hierarchy

                                          +
                                            +
                                          • Gyro
                                          +
                                          +
                                          +
                                          + +
                                          +
                                          +

                                          Properties

                                          +
                                          + +
                                          theChuck: Chuck
                                          +
                                          + +
                                          _gyroActive: boolean = false
                                          +
                                          + +
                                          boundHandleOrientation: {}
                                          +
                                          +

                                          Type declaration

                                          +
                                            +
                                          • +
                                            +
                                            +

                                            Methods

                                            +
                                            + +
                                              + +
                                            • +

                                              Initialize Gyro functionality in your WebChucK instance. +This adds a Gyro and GyroMsg class to the ChucK Virtual Machine (VM). +Gyroerometer event (DeviceMotionEvent) listeners are added if enableGyro is true (default).

                                              +
                                              +
                                              +

                                              Parameters

                                              +
                                                +
                                              • +
                                                theChuck: Chuck
                                              • +
                                              • +
                                                enableGyro: boolean = true
                                              +

                                              Returns Promise<Gyro>

                                              +
                                              +

                                              Example

                                              theChuck = await Chuck.init([]);
                                              gyro = await Gyro.init(theChuck); // Initialize Gyro +
                                              +
                                            +
                                            + +
                                              + +
                                            • +

                                              Enable Javascript event (DeviceMotionEvent) listeners for Gyro

                                              +
                                              +

                                              Returns void

                                              +
                                              +

                                              Example

                                              // If gyro is not yet enabled
                                              gyro.enableGyro(); +
                                              +
                                            +
                                            + +
                                              + +
                                            • +

                                              Disable Javascript event (DeviceMotionEvent) listeners for Gyro

                                              +
                                              +

                                              Returns void

                                              +
                                              +

                                              Example

                                              // If gyro is enabled
                                              gyro.disableGyro(); +
                                              +
                                            +
                                            + +
                                            +
                                            \ No newline at end of file From 556bc52fbbe0b2579c839291cc51b0472a7be1b7 Mon Sep 17 00:00:00 2001 From: Mike Mulshine Date: Fri, 18 Oct 2024 16:38:51 -0700 Subject: [PATCH 18/27] Added accel, gyro, hid to subfolders for organization, refactored to reflect path changes. --- dist/accel/Accel.d.ts | 57 +++++++++ dist/accel/Accel.js | 105 ++++++++++++++++ dist/accel/accelCk.d.ts | 3 + dist/accel/accelCk.js | 94 ++++++++++++++ dist/gyro/Gyro.d.ts | 57 +++++++++ dist/gyro/Gyro.js | 103 +++++++++++++++ dist/gyro/gyroCk.d.ts | 3 + dist/gyro/gyroCk.js | 94 ++++++++++++++ dist/hid/Hid.d.ts | 129 +++++++++++++++++++ dist/hid/Hid.js | 252 +++++++++++++++++++++++++++++++++++++ dist/hid/hidCk.d.ts | 3 + dist/hid/hidCk.js | 168 +++++++++++++++++++++++++ dist/index.d.ts | 6 +- dist/index.js | 6 +- src/{ => accel}/Accel.ts | 2 +- src/{ => accel}/accelCk.ts | 0 src/{ => gyro}/Gyro.ts | 2 +- src/{ => gyro}/gyroCk.ts | 0 src/{ => hid}/Hid.ts | 2 +- src/{ => hid}/hidCk.ts | 0 src/index.ts | 6 +- 21 files changed, 1080 insertions(+), 12 deletions(-) create mode 100644 dist/accel/Accel.d.ts create mode 100644 dist/accel/Accel.js create mode 100644 dist/accel/accelCk.d.ts create mode 100644 dist/accel/accelCk.js create mode 100644 dist/gyro/Gyro.d.ts create mode 100644 dist/gyro/Gyro.js create mode 100644 dist/gyro/gyroCk.d.ts create mode 100644 dist/gyro/gyroCk.js create mode 100644 dist/hid/Hid.d.ts create mode 100644 dist/hid/Hid.js create mode 100644 dist/hid/hidCk.d.ts create mode 100644 dist/hid/hidCk.js rename src/{ => accel}/Accel.ts (99%) rename src/{ => accel}/accelCk.ts (100%) rename src/{ => gyro}/Gyro.ts (99%) rename src/{ => gyro}/gyroCk.ts (100%) rename src/{ => hid}/Hid.ts (99%) rename src/{ => hid}/hidCk.ts (100%) diff --git a/dist/accel/Accel.d.ts b/dist/accel/Accel.d.ts new file mode 100644 index 0000000..0b9ede4 --- /dev/null +++ b/dist/accel/Accel.d.ts @@ -0,0 +1,57 @@ +import Chuck from "../Chuck"; +/** + * Introducing Accel (accelerometer, on mobile) support for WebChucK. Accel wraps + * JavaScript DeviceMotionEvent listeners easing access to mobile device accelerometers + * in WebChucK code. + * + * To get started with Accel: + * @example + * ```ts + * import { Chuck, Accel } from "webchuck"; + * + * const theChuck = await Chuck.init([]); + * const accel = await Accel.init(theChuck); // Initialize Accel + * ``` + */ +export default class Accel { + private theChuck; + private _accelActive; + private boundHandleMotion; + /** @internal */ + constructor(theChuck: Chuck); + /** + * Initialize Accel functionality in your WebChucK instance. + * This adds a `Accel` and `AccelMsg` class to the ChucK Virtual Machine (VM). + * Accelerometer event (DeviceMotionEvent) listeners are added if `enableAccel` is true (default). + * @example + * ```ts + * theChuck = await Chuck.init([]); + * accel = await Accel.init(theChuck); // Initialize Accel + */ + static init(theChuck: Chuck, enableAccel?: boolean): Promise; + /** + * @internal + * Check if accel is active + */ + accelActive(): Promise; + /** + * Enable Javascript event (DeviceMotionEvent) listeners for Accel + * @example + * ```ts + * // If accel is not yet enabled + * accel.enableAccel(); + * ``` + */ + enableAccel(): void; + /** + * Disable Javascript event (DeviceMotionEvent) listeners for Accel + * @example + * ```ts + * // If accel is enabled + * accel.disableAccel(); + * ``` + */ + disableAccel(): void; + /** @internal */ + private handleMotion; +} diff --git a/dist/accel/Accel.js b/dist/accel/Accel.js new file mode 100644 index 0000000..136d780 --- /dev/null +++ b/dist/accel/Accel.js @@ -0,0 +1,105 @@ +import { Accel_ck, AccelMsg_ck } from "./accelCk"; +/** + * Introducing Accel (accelerometer, on mobile) support for WebChucK. Accel wraps + * JavaScript DeviceMotionEvent listeners easing access to mobile device accelerometers + * in WebChucK code. + * + * To get started with Accel: + * @example + * ```ts + * import { Chuck, Accel } from "webchuck"; + * + * const theChuck = await Chuck.init([]); + * const accel = await Accel.init(theChuck); // Initialize Accel + * ``` + */ +export default class Accel { + /** @internal */ + constructor(theChuck) { + this._accelActive = false; + // Initialize members + this.theChuck = theChuck; + this.boundHandleMotion = this.handleMotion.bind(this); + } + /** + * Initialize Accel functionality in your WebChucK instance. + * This adds a `Accel` and `AccelMsg` class to the ChucK Virtual Machine (VM). + * Accelerometer event (DeviceMotionEvent) listeners are added if `enableAccel` is true (default). + * @example + * ```ts + * theChuck = await Chuck.init([]); + * accel = await Accel.init(theChuck); // Initialize Accel + */ + static async init(theChuck, enableAccel = true) { + const accel = new Accel(theChuck); + // Add Accel and AccelMsg classes to ChucK VM + await accel.theChuck.runCode(AccelMsg_ck); + await accel.theChuck.runCode(Accel_ck); + // Enable mouse and keyboard + /* + if (enableAccel) { + // If iOS, request permission + if (typeof (DeviceOrientationEvent as any).requestPermission === 'function') { + const permission = await (DeviceOrientationEvent as any).requestPermission(); + if (permission === 'granted') { + accel.enableAccel(); + } else { + console.log("Accelscope permission denied."); + } + } else { + // just try to enable + accel.enableAccel(); + } + } + */ + accel.enableAccel(); + return accel; + } + /** + * @internal + * Check if accel is active + */ + async accelActive() { + const x = await this.theChuck.getInt("_accelActive"); + this._accelActive = x == 1; + } + /** + * Enable Javascript event (DeviceMotionEvent) listeners for Accel + * @example + * ```ts + * // If accel is not yet enabled + * accel.enableAccel(); + * ``` + */ + enableAccel() { + // consider using "deviceorientationabsolute" + // https://developer.mozilla.org/en-US/docs/Web/API/Window/deviceorientationabsolute_event + window.addEventListener("devicemotion", this.boundHandleMotion); + } + /** + * Disable Javascript event (DeviceMotionEvent) listeners for Accel + * @example + * ```ts + * // If accel is enabled + * accel.disableAccel(); + * ``` + */ + disableAccel() { + window.removeEventListener("devicemotion", this.boundHandleMotion); + } + //----------------------------------------- + // JAVASCRIPT HID EVENT HANDLERS + //----------------------------------------- + /** @internal */ + handleMotion(event) { + this.accelActive(); + if (this._accelActive) { + if (event.acceleration != null) { + this.theChuck.setFloat("_accelX", event.acceleration.x ? event.acceleration.x : 0.0); + this.theChuck.setFloat("_accelY", event.acceleration.y ? event.acceleration.y : 0.0); + this.theChuck.setFloat("_accelZ", event.acceleration.z ? event.acceleration.z : 0.0); + this.theChuck.broadcastEvent("_accelReading"); + } + } + } +} diff --git a/dist/accel/accelCk.d.ts b/dist/accel/accelCk.d.ts new file mode 100644 index 0000000..9e086fa --- /dev/null +++ b/dist/accel/accelCk.d.ts @@ -0,0 +1,3 @@ +declare const AccelMsg_ck = "\npublic class AccelMsg {\n float accelX;\n float accelY;\n float accelZ;\n\n function float getAccelX() {\n return accelX;\n }\n\n function float getAccelY() {\n return accelY;\n }\n\n function float getAccelZ() {\n return accelZ;\n }\n\n function void _copy(AccelMsg localMsg) {\n localMsg.accelX => accelX;\n localMsg.accelY => accelY;\n localMsg.accelZ => accelZ;\n }\n}\n"; +declare const Accel_ck = "\nglobal Event _accelReading;\nglobal int _accelActive;\n\nglobal float _accelX;\nglobal float _accelY;\nglobal float _accelZ;\n\npublic class Accel extends Event {\n\n 0 => int isAccelOpen;\n 0 => int active;\n\n string deviceName; \n\n // AccelMsg Queue\n AccelMsg _accelMsgQueue[0];\n\n function string name() {\n return deviceName;\n }\n\n function int openAccel(int num) {\n if (num < 0) {\n false => active;\n } else {\n \"js DeviceMotionEvent\" => deviceName;\n true => active;\n }\n active => isAccelOpen => _accelActive;\n spork ~ _accelListener();\n return active;\n }\n\n\n // Pop the first AccelMsg from the queue\n // Write it to msg and return 1\n function int recv(AccelMsg msg) {\n // is empty\n if (_accelMsgQueue.size() <= 0) {\n return 0;\n }\n\n // pop the first AccelMsg to msg, return true\n _accelMsgQueue[0] @=> AccelMsg localMsg;\n msg._copy(localMsg); \n _accelMsgQueue.popFront();\n return 1;\n }\n\n // Accel Listener\n // Get variables from JS and write to the AccelMsg \n function void _accelListener() {\n AccelMsg @ msg;\n while(true){\n new AccelMsg @=> msg;\n _accelReading => now;\n\n _accelX => msg.accelX;\n _accelY => msg.accelY;\n _accelZ => msg.accelZ;\n\n _accelMsgQueue << msg;\n this.broadcast();\n }\n }\n}\n"; +export { AccelMsg_ck, Accel_ck }; diff --git a/dist/accel/accelCk.js b/dist/accel/accelCk.js new file mode 100644 index 0000000..fd68455 --- /dev/null +++ b/dist/accel/accelCk.js @@ -0,0 +1,94 @@ +const AccelMsg_ck = ` +public class AccelMsg { + float accelX; + float accelY; + float accelZ; + + function float getAccelX() { + return accelX; + } + + function float getAccelY() { + return accelY; + } + + function float getAccelZ() { + return accelZ; + } + + function void _copy(AccelMsg localMsg) { + localMsg.accelX => accelX; + localMsg.accelY => accelY; + localMsg.accelZ => accelZ; + } +} +`; +const Accel_ck = ` +global Event _accelReading; +global int _accelActive; + +global float _accelX; +global float _accelY; +global float _accelZ; + +public class Accel extends Event { + + 0 => int isAccelOpen; + 0 => int active; + + string deviceName; + + // AccelMsg Queue + AccelMsg _accelMsgQueue[0]; + + function string name() { + return deviceName; + } + + function int openAccel(int num) { + if (num < 0) { + false => active; + } else { + "js DeviceMotionEvent" => deviceName; + true => active; + } + active => isAccelOpen => _accelActive; + spork ~ _accelListener(); + return active; + } + + + // Pop the first AccelMsg from the queue + // Write it to msg and return 1 + function int recv(AccelMsg msg) { + // is empty + if (_accelMsgQueue.size() <= 0) { + return 0; + } + + // pop the first AccelMsg to msg, return true + _accelMsgQueue[0] @=> AccelMsg localMsg; + msg._copy(localMsg); + _accelMsgQueue.popFront(); + return 1; + } + + // Accel Listener + // Get variables from JS and write to the AccelMsg + function void _accelListener() { + AccelMsg @ msg; + while(true){ + new AccelMsg @=> msg; + _accelReading => now; + + _accelX => msg.accelX; + _accelY => msg.accelY; + _accelZ => msg.accelZ; + + _accelMsgQueue << msg; + this.broadcast(); + } + } +} +`; +export { AccelMsg_ck, Accel_ck }; diff --git a/dist/gyro/Gyro.d.ts b/dist/gyro/Gyro.d.ts new file mode 100644 index 0000000..3fd547a --- /dev/null +++ b/dist/gyro/Gyro.d.ts @@ -0,0 +1,57 @@ +import Chuck from "../Chuck"; +/** + * Introducing Gyro (gyroerometer, on mobile) support for WebChucK. Gyro wraps + * JavaScript DeviceMotionEvent listeners easing access to mobile device gyroerometers + * in WebChucK code. + * + * To get started with Gyro: + * @example + * ```ts + * import { Chuck, Gyro } from "webchuck"; + * + * const theChuck = await Chuck.init([]); + * const gyro = await Gyro.init(theChuck); // Initialize Gyro + * ``` + */ +export default class Gyro { + private theChuck; + private _gyroActive; + private boundHandleOrientation; + /** @internal */ + constructor(theChuck: Chuck); + /** + * Initialize Gyro functionality in your WebChucK instance. + * This adds a `Gyro` and `GyroMsg` class to the ChucK Virtual Machine (VM). + * Gyroerometer event (DeviceMotionEvent) listeners are added if `enableGyro` is true (default). + * @example + * ```ts + * theChuck = await Chuck.init([]); + * gyro = await Gyro.init(theChuck); // Initialize Gyro + */ + static init(theChuck: Chuck, enableGyro?: boolean): Promise; + /** + * @internal + * Check if gyro is active + */ + gyroActive(): Promise; + /** + * Enable Javascript event (DeviceMotionEvent) listeners for Gyro + * @example + * ```ts + * // If gyro is not yet enabled + * gyro.enableGyro(); + * ``` + */ + enableGyro(): void; + /** + * Disable Javascript event (DeviceMotionEvent) listeners for Gyro + * @example + * ```ts + * // If gyro is enabled + * gyro.disableGyro(); + * ``` + */ + disableGyro(): void; + /** @internal */ + private handleOrientation; +} diff --git a/dist/gyro/Gyro.js b/dist/gyro/Gyro.js new file mode 100644 index 0000000..6cb0051 --- /dev/null +++ b/dist/gyro/Gyro.js @@ -0,0 +1,103 @@ +import { Gyro_ck, GyroMsg_ck } from "./gyroCk"; +/** + * Introducing Gyro (gyroerometer, on mobile) support for WebChucK. Gyro wraps + * JavaScript DeviceMotionEvent listeners easing access to mobile device gyroerometers + * in WebChucK code. + * + * To get started with Gyro: + * @example + * ```ts + * import { Chuck, Gyro } from "webchuck"; + * + * const theChuck = await Chuck.init([]); + * const gyro = await Gyro.init(theChuck); // Initialize Gyro + * ``` + */ +export default class Gyro { + /** @internal */ + constructor(theChuck) { + this._gyroActive = false; + // Initialize members + this.theChuck = theChuck; + this.boundHandleOrientation = this.handleOrientation.bind(this); + } + /** + * Initialize Gyro functionality in your WebChucK instance. + * This adds a `Gyro` and `GyroMsg` class to the ChucK Virtual Machine (VM). + * Gyroerometer event (DeviceMotionEvent) listeners are added if `enableGyro` is true (default). + * @example + * ```ts + * theChuck = await Chuck.init([]); + * gyro = await Gyro.init(theChuck); // Initialize Gyro + */ + static async init(theChuck, enableGyro = true) { + const gyro = new Gyro(theChuck); + // Add Gyro and GyroMsg classes to ChucK VM + await gyro.theChuck.runCode(GyroMsg_ck); + await gyro.theChuck.runCode(Gyro_ck); + // Enable mouse and keyboard + /* + if (enableGyro) { + // If iOS, request permission + if (typeof (DeviceOrientationEvent as any).requestPermission === 'function') { + const permission = await (DeviceOrientationEvent as any).requestPermission(); + if (permission === 'granted') { + gyro.enableGyro(); + } else { + console.log("Gyroscope permission denied."); + } + } else { + // just try to enable + gyro.enableGyro(); + } + } + */ + gyro.enableGyro(); + return gyro; + } + /** + * @internal + * Check if gyro is active + */ + async gyroActive() { + const x = await this.theChuck.getInt("_gyroActive"); + this._gyroActive = x == 1; + } + /** + * Enable Javascript event (DeviceMotionEvent) listeners for Gyro + * @example + * ```ts + * // If gyro is not yet enabled + * gyro.enableGyro(); + * ``` + */ + enableGyro() { + // consider using "deviceorientationabsolute" + // https://developer.mozilla.org/en-US/docs/Web/API/Window/deviceorientationabsolute_event + window.addEventListener("deviceorientation", this.boundHandleOrientation); + } + /** + * Disable Javascript event (DeviceMotionEvent) listeners for Gyro + * @example + * ```ts + * // If gyro is enabled + * gyro.disableGyro(); + * ``` + */ + disableGyro() { + window.removeEventListener("deviceorientation", this.boundHandleOrientation); + } + //----------------------------------------- + // JAVASCRIPT HID EVENT HANDLERS + //----------------------------------------- + /** @internal */ + handleOrientation(event) { + this.gyroActive(); + if (this._gyroActive) { + this.theChuck.setFloat("_gyroX", event.alpha ? event.alpha : 0.0); + this.theChuck.setFloat("_gyroY", event.beta ? event.beta : 0.0); + this.theChuck.setFloat("_gyroZ", event.gamma ? event.gamma : 0.0); + this.theChuck.broadcastEvent("_gyroReading"); + } + } +} diff --git a/dist/gyro/gyroCk.d.ts b/dist/gyro/gyroCk.d.ts new file mode 100644 index 0000000..42eb772 --- /dev/null +++ b/dist/gyro/gyroCk.d.ts @@ -0,0 +1,3 @@ +declare const GyroMsg_ck = "\npublic class GyroMsg {\n float gyroX;\n float gyroY;\n float gyroZ;\n\n function float getGyroX() {\n return gyroX;\n }\n\n function float getGyroY() {\n return gyroY;\n }\n\n function float getGyroZ() {\n return gyroZ;\n }\n\n function void _copy(GyroMsg localMsg) {\n localMsg.gyroX => gyroX;\n localMsg.gyroY => gyroY;\n localMsg.gyroZ => gyroZ;\n }\n}\n"; +declare const Gyro_ck = "\nglobal Event _gyroReading;\nglobal int _gyroActive;\n\nglobal float _gyroX;\nglobal float _gyroY;\nglobal float _gyroZ;\n\npublic class Gyro extends Event {\n\n 0 => int isGyroOpen;\n 0 => int active;\n\n string deviceName; \n\n // GyroMsg Queue\n GyroMsg _gyroMsgQueue[0];\n\n function string name() {\n return deviceName;\n }\n\n function int openGyro(int num) {\n if (num < 0) {\n false => active;\n } else {\n \"js DeviceOrientationEvent\" => deviceName;\n true => active;\n }\n active => isGyroOpen => _gyroActive;\n spork ~ _gyroListener();\n return active;\n }\n\n\n // Pop the first GyroMsg from the queue\n // Write it to msg and return 1\n function int recv(GyroMsg msg) {\n // is empty\n if (_gyroMsgQueue.size() <= 0) {\n return 0;\n }\n\n // pop the first GyroMsg to msg, return true\n _gyroMsgQueue[0] @=> GyroMsg localMsg;\n msg._copy(localMsg); \n _gyroMsgQueue.popFront();\n return 1;\n }\n\n // Gyro Listener\n // Get variables from JS and write to the GyroMsg \n function void _gyroListener() {\n GyroMsg @ msg;\n while(true){\n new GyroMsg @=> msg;\n _gyroReading => now;\n\n _gyroX => msg.gyroX;\n _gyroY => msg.gyroY;\n _gyroZ => msg.gyroZ;\n\n _gyroMsgQueue << msg;\n this.broadcast();\n }\n }\n}\n"; +export { GyroMsg_ck, Gyro_ck }; diff --git a/dist/gyro/gyroCk.js b/dist/gyro/gyroCk.js new file mode 100644 index 0000000..6171fa2 --- /dev/null +++ b/dist/gyro/gyroCk.js @@ -0,0 +1,94 @@ +const GyroMsg_ck = ` +public class GyroMsg { + float gyroX; + float gyroY; + float gyroZ; + + function float getGyroX() { + return gyroX; + } + + function float getGyroY() { + return gyroY; + } + + function float getGyroZ() { + return gyroZ; + } + + function void _copy(GyroMsg localMsg) { + localMsg.gyroX => gyroX; + localMsg.gyroY => gyroY; + localMsg.gyroZ => gyroZ; + } +} +`; +const Gyro_ck = ` +global Event _gyroReading; +global int _gyroActive; + +global float _gyroX; +global float _gyroY; +global float _gyroZ; + +public class Gyro extends Event { + + 0 => int isGyroOpen; + 0 => int active; + + string deviceName; + + // GyroMsg Queue + GyroMsg _gyroMsgQueue[0]; + + function string name() { + return deviceName; + } + + function int openGyro(int num) { + if (num < 0) { + false => active; + } else { + "js DeviceOrientationEvent" => deviceName; + true => active; + } + active => isGyroOpen => _gyroActive; + spork ~ _gyroListener(); + return active; + } + + + // Pop the first GyroMsg from the queue + // Write it to msg and return 1 + function int recv(GyroMsg msg) { + // is empty + if (_gyroMsgQueue.size() <= 0) { + return 0; + } + + // pop the first GyroMsg to msg, return true + _gyroMsgQueue[0] @=> GyroMsg localMsg; + msg._copy(localMsg); + _gyroMsgQueue.popFront(); + return 1; + } + + // Gyro Listener + // Get variables from JS and write to the GyroMsg + function void _gyroListener() { + GyroMsg @ msg; + while(true){ + new GyroMsg @=> msg; + _gyroReading => now; + + _gyroX => msg.gyroX; + _gyroY => msg.gyroY; + _gyroZ => msg.gyroZ; + + _gyroMsgQueue << msg; + this.broadcast(); + } + } +} +`; +export { GyroMsg_ck, Gyro_ck }; diff --git a/dist/hid/Hid.d.ts b/dist/hid/Hid.d.ts new file mode 100644 index 0000000..3304915 --- /dev/null +++ b/dist/hid/Hid.d.ts @@ -0,0 +1,129 @@ +import Chuck from "../Chuck"; +/** + * HID (Human Interface Device) support for WebChucK. HID wraps + * JavaScript mouse/keyboard event listeners enabling mouse and keyboard + * input via the {@link https://chuck.stanford.edu/doc/reference/io.html#Hid | HID} + * class in ChucK. + * + * To get started with HID: + * @example + * ```ts + * import { Chuck, HID } from "webchuck"; + * + * const theChuck = await Chuck.init([]); + * const hid = await HID.init(theChuck); // Initialize HID with mouse and keyboard + * ``` + */ +export default class HID { + private theChuck; + private keymap; + private _mouseActive; + private _kbdActive; + private boundHandleMouseMove; + private boundHandleMouseDown; + private boundHandleMouseUp; + private boundHandleMouseWheel; + private boundHandleKeyDown; + private boundHandleKeyUp; + /** @internal */ + constructor(theChuck: Chuck); + /** + * Initialize HID functionality in your WebChucK instance. + * This adds a `Hid` and `HidMsg` class to the ChucK Virtual Machine (VM). + * Mouse and keyboard event listeners are added if `enableMouse` and `enableKeyboard` are true (default). + * @example + * ```ts + * theChuck = await Chuck.init([]); + * hid = await HID.init(theChuck); // Initialize HID with mouse and keyboard + * ``` + * @example + * ```ts + * theChuck = await Chuck.init([]); + * hid = await HID.init(theChuck, false, true); // Initialize HID, no mouse, only keyboard + * ``` + * @param theChuck WebChucK instance + * @param enableMouse boolean to enable mouse HID + * @param enableKeyboard boolean to enable keyboard HID + */ + static init(theChuck: Chuck, enableMouse?: boolean, enableKeyboard?: boolean): Promise; + /** + * @internal + * Check if keyboard is active + */ + kbdActive(): Promise; + /** + * @internal + * Check if mouse is active + */ + mouseActive(): Promise; + /** + * @internal + * Get mouse position from the MouseEvent + * @param mouseEvent Mouse event + * @returns mouse position + */ + getMousePos(mouseEvent: MouseEvent): { + x: number; + y: number; + }; + /** + * Enable Mouse HID Javascript event listeners for HID. + * Adds a mousemove, mousedown, mouseup, and wheel listener to the document. + * This will also disable the context menu on right click. + * @example + * ```ts + * // If mouse HID is not yet enabled + * hid.enableMouse(); + * ``` + */ + enableMouse(): void; + /** + * Disable Mouse HID Javascript event listeners + * @example + * ```ts + * // If mouse HID is enabled + * hid.disableMouse(); + * ``` + */ + disableMouse(): void; + /** + * Enable keyboard HID Javascript event listeners for HID. + * Adds a keydown and keyup listener to the document. + * @example + * ```ts + * // If keyboard HID is not yet enabled + * hid.enableKeyboard(); + * ``` + */ + enableKeyboard(): void; + /** + * Disable keyboard HID javascript event listeners + * @example + * ```ts + * // If keyboard HID is enabled + * hid.disableKeyboard(); + * ``` + */ + disableKeyboard(): void; + /** @internal */ + private handleMouseMove; + /** @internal */ + private handleMouseDown; + /** @internal */ + private handleMouseUp; + /** @internal */ + private handleMouseWheel; + /** @internal */ + private static handleContextMenu; + /** @internal */ + private handleKeyDown; + /** @internal */ + private handleKeyUp; + /** + * @internal + * Handle keyboard presses to send to chuck + * @param e Keyboard event + * @param isDown Is key down + */ + private keyPressManager; +} diff --git a/dist/hid/Hid.js b/dist/hid/Hid.js new file mode 100644 index 0000000..89b57d2 --- /dev/null +++ b/dist/hid/Hid.js @@ -0,0 +1,252 @@ +import { Hid_ck, HidMsg_ck } from "./hidCk"; +var HidMsgType; +(function (HidMsgType) { + HidMsgType[HidMsgType["BUTTON_DOWN"] = 1] = "BUTTON_DOWN"; + HidMsgType[HidMsgType["BUTTON_UP"] = 2] = "BUTTON_UP"; + HidMsgType[HidMsgType["MOUSE_MOTION"] = 5] = "MOUSE_MOTION"; + HidMsgType[HidMsgType["WHEEL_MOTION"] = 6] = "WHEEL_MOTION"; +})(HidMsgType || (HidMsgType = {})); +//TODO: Update the latest mouse.ck and kb.ck files +/** + * HID (Human Interface Device) support for WebChucK. HID wraps + * JavaScript mouse/keyboard event listeners enabling mouse and keyboard + * input via the {@link https://chuck.stanford.edu/doc/reference/io.html#Hid | HID} + * class in ChucK. + * + * To get started with HID: + * @example + * ```ts + * import { Chuck, HID } from "webchuck"; + * + * const theChuck = await Chuck.init([]); + * const hid = await HID.init(theChuck); // Initialize HID with mouse and keyboard + * ``` + */ +export default class HID { + /** @internal */ + constructor(theChuck) { + this._mouseActive = false; + this._kbdActive = false; + // Initialize members + this.theChuck = theChuck; + this.keymap = new Array(256).fill(false); + // Bind handlers + this.boundHandleMouseMove = this.handleMouseMove.bind(this); + this.boundHandleMouseDown = this.handleMouseDown.bind(this); + this.boundHandleMouseUp = this.handleMouseUp.bind(this); + this.boundHandleMouseWheel = this.handleMouseWheel.bind(this); + this.boundHandleKeyDown = this.handleKeyDown.bind(this); + this.boundHandleKeyUp = this.handleKeyUp.bind(this); + } + /** + * Initialize HID functionality in your WebChucK instance. + * This adds a `Hid` and `HidMsg` class to the ChucK Virtual Machine (VM). + * Mouse and keyboard event listeners are added if `enableMouse` and `enableKeyboard` are true (default). + * @example + * ```ts + * theChuck = await Chuck.init([]); + * hid = await HID.init(theChuck); // Initialize HID with mouse and keyboard + * ``` + * @example + * ```ts + * theChuck = await Chuck.init([]); + * hid = await HID.init(theChuck, false, true); // Initialize HID, no mouse, only keyboard + * ``` + * @param theChuck WebChucK instance + * @param enableMouse boolean to enable mouse HID + * @param enableKeyboard boolean to enable keyboard HID + */ + static async init(theChuck, enableMouse = true, enableKeyboard = true) { + const hid = new HID(theChuck); + // Add HID and HIDMsg classes to ChucK VM + await hid.theChuck.runCode(HidMsg_ck); + await hid.theChuck.runCode(Hid_ck); + // Enable mouse and keyboard + if (enableMouse) { + hid.enableMouse(); + } + if (enableKeyboard) { + hid.enableKeyboard(); + } + return hid; + } + /** + * @internal + * Check if keyboard is active + */ + async kbdActive() { + const x = await this.theChuck.getInt("_kbdActive"); + this._kbdActive = x == 1; + } + /** + * @internal + * Check if mouse is active + */ + async mouseActive() { + const x = await this.theChuck.getInt("_mouseActive"); + this._mouseActive = x == 1; + } + /** + * @internal + * Get mouse position from the MouseEvent + * @param mouseEvent Mouse event + * @returns mouse position + */ + getMousePos(mouseEvent) { + return { + x: mouseEvent.clientX, + y: mouseEvent.clientY, + }; + } + /** + * Enable Mouse HID Javascript event listeners for HID. + * Adds a mousemove, mousedown, mouseup, and wheel listener to the document. + * This will also disable the context menu on right click. + * @example + * ```ts + * // If mouse HID is not yet enabled + * hid.enableMouse(); + * ``` + */ + enableMouse() { + document.addEventListener("mousemove", this.boundHandleMouseMove); + document.addEventListener("mousedown", this.boundHandleMouseDown); + document.addEventListener("mouseup", this.boundHandleMouseUp); + document.addEventListener("wheel", this.boundHandleMouseWheel); + document.addEventListener("contextmenu", HID.handleContextMenu); + } + /** + * Disable Mouse HID Javascript event listeners + * @example + * ```ts + * // If mouse HID is enabled + * hid.disableMouse(); + * ``` + */ + disableMouse() { + document.removeEventListener("mousemove", this.boundHandleMouseMove); + document.removeEventListener("mousedown", this.boundHandleMouseDown); + document.removeEventListener("mouseup", this.boundHandleMouseUp); + document.removeEventListener("wheel", this.boundHandleMouseWheel); + document.removeEventListener("contextmenu", HID.handleContextMenu); + } + /** + * Enable keyboard HID Javascript event listeners for HID. + * Adds a keydown and keyup listener to the document. + * @example + * ```ts + * // If keyboard HID is not yet enabled + * hid.enableKeyboard(); + * ``` + */ + enableKeyboard() { + document.addEventListener("keydown", this.boundHandleKeyDown); + document.addEventListener("keyup", this.boundHandleKeyUp); + } + /** + * Disable keyboard HID javascript event listeners + * @example + * ```ts + * // If keyboard HID is enabled + * hid.disableKeyboard(); + * ``` + */ + disableKeyboard() { + document.removeEventListener("keydown", this.boundHandleKeyDown); + document.removeEventListener("keyup", this.boundHandleKeyUp); + } + //----------------------------------------- + // JAVASCRIPT HID EVENT HANDLERS + //----------------------------------------- + //----------- MOUSE --------- // + /** @internal */ + handleMouseMove(e) { + this.mouseActive(); + if (this._mouseActive) { + const mousePos = this.getMousePos(e); + this.theChuck.setInt("_cursorX", mousePos.x); + this.theChuck.setInt("_cursorY", mousePos.y); + this.theChuck.setFloat("_deltaX", e.movementX); + this.theChuck.setFloat("_deltaY", e.movementY); + this.theChuck.setFloat("_scaledCursorX", mousePos.x / document.documentElement.clientWidth); + this.theChuck.setFloat("_scaledCursorY", mousePos.y / document.documentElement.clientHeight); + this.theChuck.setInt("_type", HidMsgType.MOUSE_MOTION); + this.theChuck.broadcastEvent("_mouseHid"); + } + } + /** @internal */ + handleMouseDown(e) { + this.mouseActive(); + if (this._mouseActive) { + this.theChuck.setInt("_which", e.which); + this.theChuck.setInt("_type", HidMsgType.BUTTON_DOWN); + this.theChuck.broadcastEvent("_mouseHid"); + } + } + /** @internal */ + handleMouseUp(e) { + this.mouseActive(); + if (this._mouseActive) { + this.theChuck.setInt("_which", e.which); + this.theChuck.setInt("_type", HidMsgType.BUTTON_UP); + this.theChuck.broadcastEvent("_mouseHid"); + } + } + /** @internal */ + handleMouseWheel(e) { + this.mouseActive(); + if (this._mouseActive) { + this.theChuck.setFloat("_deltaX", clamp(e.deltaX, -1, 1)); + this.theChuck.setFloat("_deltaY", clamp(e.deltaY, -1, 1)); + this.theChuck.setInt("_type", HidMsgType.WHEEL_MOTION); + this.theChuck.broadcastEvent("_mouseHid"); + } + } + /** @internal */ + static handleContextMenu(e) { + e.preventDefault(); + } + //----------- KEYBOARD --------- // + /** @internal */ + handleKeyDown(e) { + this.kbdActive(); + if (this._kbdActive && !this.keymap[e.keyCode]) { + this.keymap[e.keyCode] = true; + this.keyPressManager(e, true); + } + } + /** @internal */ + handleKeyUp(e) { + this.kbdActive(); + if (this._kbdActive) { + this.keymap[e.keyCode] = false; + this.keyPressManager(e, false); + } + } + /** + * @internal + * Handle keyboard presses to send to chuck + * @param e Keyboard event + * @param isDown Is key down + */ + keyPressManager(e, isDown) { + this.theChuck.setString("_key", e.key); + this.theChuck.setInt("_which", e.which); + this.theChuck.setInt("_ascii", e.keyCode); + this.theChuck.setInt("_type", isDown ? HidMsgType.BUTTON_DOWN : HidMsgType.BUTTON_UP); + this.theChuck.broadcastEvent("_kbHid"); + } +} +//----------------------------------------------- +// HELPER FUNCTIONS +//----------------------------------------------- +/** + * Clamp a value between two numbers + * @param val value to clamp + * @param min min value + * @param max max value + * @returns clamped value + */ +function clamp(val, min, max) { + return Math.min(Math.max(val, min), max); +} diff --git a/dist/hid/hidCk.d.ts b/dist/hid/hidCk.d.ts new file mode 100644 index 0000000..f2bb945 --- /dev/null +++ b/dist/hid/hidCk.d.ts @@ -0,0 +1,3 @@ +declare const HidMsg_ck = "\npublic class HidMsg {\n int type;\n int deviceType;\n int cursorX;\n int cursorY;\n float deltaX;\n float deltaY;\n float scaledCursorX;\n float scaledCursorY;\n int which;\n int ascii;\n string key;\n\n // type 1 message\n function int isButtonDown() {\n return type == 1;\n }\n\n // type 2 message\n function int isButtonUp() {\n return type == 2;\n }\n\n // type 5 message\n function int isMouseMotion(){\n return type == 5;\n }\n\n // type 6 message\n function int isWheelMotion(){\n return type == 6;\n }\n\n function void _copy(HidMsg localMsg) {\n localMsg.type => type;\n localMsg.deviceType => deviceType;\n localMsg.cursorX => cursorX;\n localMsg.cursorY => cursorY;\n localMsg.deltaX => deltaX;\n localMsg.deltaY => deltaY;\n localMsg.scaledCursorX => scaledCursorX;\n localMsg.scaledCursorY => scaledCursorY;\n localMsg.which => which;\n localMsg.ascii => ascii;\n localMsg.key => key;\n }\n}\n"; +declare const Hid_ck = "\nglobal Event _kbHid;\nglobal Event _mouseHid;\nglobal int _type;\nglobal int _mouseActive;\nglobal int _kbdActive;\n\nglobal int _cursorX;\nglobal int _cursorY;\nglobal float _deltaX;\nglobal float _deltaY;\nglobal float _scaledCursorX;\nglobal float _scaledCursorY;\n\nglobal int _ascii;\nglobal int _which;\nglobal string _key;\n\npublic class Hid extends Event {\n\n 0 => int isMouseOpen;\n 0 => int isKBDOpen;\n 0 => int active;\n\n string deviceName; \n int deviceType; // mouse = 2, keyboard = 3\n\n // HidMsg Queue\n HidMsg _hidMsgQueue[0];\n\n function string name() {\n return deviceName;\n }\n\n function int openMouse(int num) {\n if (num < 0) {\n false => active;\n } else {\n \"virtualJS mouse/trackpad\" => deviceName;\n 2 => deviceType;\n true => active;\n }\n active => isMouseOpen => _mouseActive;\n spork ~ _mouseListener();\n return active;\n }\n\n function int openKeyboard(int num) {\n if (num < 0) {\n false => active;\n } else {\n \"virtualJS keyboard\" => deviceName;\n 3 => deviceType;\n true => active;\n }\n active => isKBDOpen => _kbdActive;\n spork ~ _keyboardListener();\n return active;\n }\n\n // Pop the first HidMsg from the queue\n // Write it to msg and return 1\n function int recv(HidMsg msg) {\n // is empty\n if (_hidMsgQueue.size() <= 0) {\n return 0;\n }\n\n // pop the first HidMsg to msg, return true\n _hidMsgQueue[0] @=> HidMsg localMsg;\n msg._copy(localMsg); \n _hidMsgQueue.popFront();\n return 1;\n }\n\n // Keyboard Hid Listener\n // Get variables from JS and write to the HidMsg \n function void _keyboardListener() {\n HidMsg @ msg;\n while(true){\n new HidMsg @=> msg;\n deviceType => msg.deviceType;\n _kbHid => now;\n\n _type => msg.type;\n _which => msg.which;\n _ascii => msg.ascii;\n _key => msg.key;\n\n _hidMsgQueue << msg;\n this.broadcast();\n }\n }\n\n // Mouse Hid Listener\n // Get variables from JS and write to the HidMsg \n function void _mouseListener() {\n HidMsg @ msg;\n while(true){\n new HidMsg @=> msg;\n deviceType => msg.deviceType;\n _mouseHid => now;\n\n _type => msg.type;\n _cursorX => msg.cursorX;\n _cursorY => msg.cursorY;\n _deltaX => msg.deltaX;\n _deltaY => msg.deltaY;\n _scaledCursorX => msg.scaledCursorX;\n _scaledCursorY => msg.scaledCursorY;\n _which => msg.which;\n\n _hidMsgQueue << msg;\n this.broadcast();\n }\n }\n}\n"; +export { HidMsg_ck, Hid_ck }; diff --git a/dist/hid/hidCk.js b/dist/hid/hidCk.js new file mode 100644 index 0000000..77f1464 --- /dev/null +++ b/dist/hid/hidCk.js @@ -0,0 +1,168 @@ +const HidMsg_ck = ` +public class HidMsg { + int type; + int deviceType; + int cursorX; + int cursorY; + float deltaX; + float deltaY; + float scaledCursorX; + float scaledCursorY; + int which; + int ascii; + string key; + + // type 1 message + function int isButtonDown() { + return type == 1; + } + + // type 2 message + function int isButtonUp() { + return type == 2; + } + + // type 5 message + function int isMouseMotion(){ + return type == 5; + } + + // type 6 message + function int isWheelMotion(){ + return type == 6; + } + + function void _copy(HidMsg localMsg) { + localMsg.type => type; + localMsg.deviceType => deviceType; + localMsg.cursorX => cursorX; + localMsg.cursorY => cursorY; + localMsg.deltaX => deltaX; + localMsg.deltaY => deltaY; + localMsg.scaledCursorX => scaledCursorX; + localMsg.scaledCursorY => scaledCursorY; + localMsg.which => which; + localMsg.ascii => ascii; + localMsg.key => key; + } +} +`; +const Hid_ck = ` +global Event _kbHid; +global Event _mouseHid; +global int _type; +global int _mouseActive; +global int _kbdActive; + +global int _cursorX; +global int _cursorY; +global float _deltaX; +global float _deltaY; +global float _scaledCursorX; +global float _scaledCursorY; + +global int _ascii; +global int _which; +global string _key; + +public class Hid extends Event { + + 0 => int isMouseOpen; + 0 => int isKBDOpen; + 0 => int active; + + string deviceName; + int deviceType; // mouse = 2, keyboard = 3 + + // HidMsg Queue + HidMsg _hidMsgQueue[0]; + + function string name() { + return deviceName; + } + + function int openMouse(int num) { + if (num < 0) { + false => active; + } else { + "virtualJS mouse/trackpad" => deviceName; + 2 => deviceType; + true => active; + } + active => isMouseOpen => _mouseActive; + spork ~ _mouseListener(); + return active; + } + + function int openKeyboard(int num) { + if (num < 0) { + false => active; + } else { + "virtualJS keyboard" => deviceName; + 3 => deviceType; + true => active; + } + active => isKBDOpen => _kbdActive; + spork ~ _keyboardListener(); + return active; + } + + // Pop the first HidMsg from the queue + // Write it to msg and return 1 + function int recv(HidMsg msg) { + // is empty + if (_hidMsgQueue.size() <= 0) { + return 0; + } + + // pop the first HidMsg to msg, return true + _hidMsgQueue[0] @=> HidMsg localMsg; + msg._copy(localMsg); + _hidMsgQueue.popFront(); + return 1; + } + + // Keyboard Hid Listener + // Get variables from JS and write to the HidMsg + function void _keyboardListener() { + HidMsg @ msg; + while(true){ + new HidMsg @=> msg; + deviceType => msg.deviceType; + _kbHid => now; + + _type => msg.type; + _which => msg.which; + _ascii => msg.ascii; + _key => msg.key; + + _hidMsgQueue << msg; + this.broadcast(); + } + } + + // Mouse Hid Listener + // Get variables from JS and write to the HidMsg + function void _mouseListener() { + HidMsg @ msg; + while(true){ + new HidMsg @=> msg; + deviceType => msg.deviceType; + _mouseHid => now; + + _type => msg.type; + _cursorX => msg.cursorX; + _cursorY => msg.cursorY; + _deltaX => msg.deltaX; + _deltaY => msg.deltaY; + _scaledCursorX => msg.scaledCursorX; + _scaledCursorY => msg.scaledCursorY; + _which => msg.which; + + _hidMsgQueue << msg; + this.broadcast(); + } + } +} +`; +export { HidMsg_ck, Hid_ck }; diff --git a/dist/index.d.ts b/dist/index.d.ts index 66855c3..fcbeec2 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -1,6 +1,6 @@ import DeferredPromise from "./DeferredPromise"; import Chuck from "./Chuck"; -import HID from "./Hid"; -import Gyro from "./Gyro"; -import Accel from "./Accel"; +import HID from "./hid/Hid"; +import Gyro from "./gyro/Gyro"; +import Accel from "./accel/Accel"; export { Chuck, HID, Gyro, Accel, DeferredPromise }; diff --git a/dist/index.js b/dist/index.js index 66855c3..fcbeec2 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,6 +1,6 @@ import DeferredPromise from "./DeferredPromise"; import Chuck from "./Chuck"; -import HID from "./Hid"; -import Gyro from "./Gyro"; -import Accel from "./Accel"; +import HID from "./hid/Hid"; +import Gyro from "./gyro/Gyro"; +import Accel from "./accel/Accel"; export { Chuck, HID, Gyro, Accel, DeferredPromise }; diff --git a/src/Accel.ts b/src/accel/Accel.ts similarity index 99% rename from src/Accel.ts rename to src/accel/Accel.ts index f66ce8e..df2a8fd 100644 --- a/src/Accel.ts +++ b/src/accel/Accel.ts @@ -1,4 +1,4 @@ -import Chuck from "./Chuck"; +import Chuck from "../Chuck"; import { Accel_ck, AccelMsg_ck } from "./accelCk"; diff --git a/src/accelCk.ts b/src/accel/accelCk.ts similarity index 100% rename from src/accelCk.ts rename to src/accel/accelCk.ts diff --git a/src/Gyro.ts b/src/gyro/Gyro.ts similarity index 99% rename from src/Gyro.ts rename to src/gyro/Gyro.ts index add5222..e5f5e93 100644 --- a/src/Gyro.ts +++ b/src/gyro/Gyro.ts @@ -1,4 +1,4 @@ -import Chuck from "./Chuck"; +import Chuck from "../Chuck"; import { Gyro_ck, GyroMsg_ck } from "./gyroCk"; diff --git a/src/gyroCk.ts b/src/gyro/gyroCk.ts similarity index 100% rename from src/gyroCk.ts rename to src/gyro/gyroCk.ts diff --git a/src/Hid.ts b/src/hid/Hid.ts similarity index 99% rename from src/Hid.ts rename to src/hid/Hid.ts index d3248f2..e3315d0 100644 --- a/src/Hid.ts +++ b/src/hid/Hid.ts @@ -1,4 +1,4 @@ -import Chuck from "./Chuck"; +import Chuck from "../Chuck"; import { Hid_ck, HidMsg_ck } from "./hidCk"; enum HidMsgType { diff --git a/src/hidCk.ts b/src/hid/hidCk.ts similarity index 100% rename from src/hidCk.ts rename to src/hid/hidCk.ts diff --git a/src/index.ts b/src/index.ts index 7736d0e..0a75cd9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,7 @@ import DeferredPromise from "./DeferredPromise"; import Chuck from "./Chuck"; -import HID from "./Hid"; -import Gyro from "./Gyro"; -import Accel from "./Accel"; +import HID from "./hid/Hid"; +import Gyro from "./gyro/Gyro"; +import Accel from "./accel/Accel"; export { Chuck, HID, Gyro, Accel, DeferredPromise }; From d339100f6c72f4fb0fb4035fe69ec9916499fd03 Mon Sep 17 00:00:00 2001 From: terry feng Date: Fri, 18 Oct 2024 16:48:53 -0700 Subject: [PATCH 19/27] add context.suspended note to website --- docs/classes/Chuck.html | 124 ++++++++++++++++++++-------------------- docs/classes/HID.html | 32 +++++------ index.html | 6 ++ src/Chuck.ts | 12 ++-- 4 files changed, 90 insertions(+), 84 deletions(-) diff --git a/docs/classes/Chuck.html b/docs/classes/Chuck.html index 34559ff..c1012d8 100644 --- a/docs/classes/Chuck.html +++ b/docs/classes/Chuck.html @@ -17,7 +17,7 @@

                                            Class Chuck

                                            WebChucK extends the Web Audio AudioWorkletNode and provides an interface -to interact with the ChucK Virtual Machine.

                                            +to interact with the ChucK Virtual Machine.

                                            Get started with init() to create a ChucK instance.

                                            @@ -28,7 +28,7 @@

                                            Hierarchy

                                            • Chuck
                                            +
                                          • Defined in src/Chuck.ts:32
                                          • @@ -120,7 +120,7 @@
                                            +
                                          • Defined in src/Chuck.ts:54
                                          • Properties

                                            deferredPromises: DeferredPromisesMap = {}
                                            +
                                          • Defined in src/Chuck.ts:33
                                          • deferredPromiseCounter: number = 0
                                            +
                                          • Defined in src/Chuck.ts:34
                                          • eventCallbacks: EventCallbacksMap = {}
                                            +
                                          • Defined in src/Chuck.ts:35
                                          • eventCallbackCounter: number = 0
                                            +
                                          • Defined in src/Chuck.ts:36
                                          • isReady: default<void> = ...
                                            +
                                          • Defined in src/Chuck.ts:37
                                          • chugins: string[] = []
                                            +
                                          • Defined in src/Chuck.ts:43
                                          • onprocessorerror: null | ((this, ev) => any)
                                            @@ -260,10 +260,10 @@
                                            +
                                          • Defined in src/Chuck.ts:117
                                          • +
                                          • Defined in src/Chuck.ts:235
                                          • +
                                          • Defined in src/Chuck.ts:159
                                          • +
                                          • Defined in src/Chuck.ts:174
                                          • +
                                          • Defined in src/Chuck.ts:186
                                          • +
                                          • Defined in src/Chuck.ts:201
                                          • +
                                          • Defined in src/Chuck.ts:245
                                          • +
                                          • Defined in src/Chuck.ts:255
                                          • +
                                          • Defined in src/Chuck.ts:285
                                          • +
                                          • Defined in src/Chuck.ts:324
                                          • +
                                          • Defined in src/Chuck.ts:344
                                          • +
                                          • Defined in src/Chuck.ts:379
                                          • +
                                          • Defined in src/Chuck.ts:419
                                          • +
                                          • Defined in src/Chuck.ts:462
                                          • +
                                          • Defined in src/Chuck.ts:511
                                          • +
                                          • Defined in src/Chuck.ts:525
                                          • +
                                          • Defined in src/Chuck.ts:539
                                          • +
                                          • Defined in src/Chuck.ts:547
                                          • +
                                          • Defined in src/Chuck.ts:558
                                          • +
                                          • Defined in src/Chuck.ts:576
                                          • +
                                          • Defined in src/Chuck.ts:592
                                          • +
                                          • Defined in src/Chuck.ts:606
                                          • +
                                          • Defined in src/Chuck.ts:616
                                          • +
                                          • Defined in src/Chuck.ts:630
                                          • +
                                          • Defined in src/Chuck.ts:639
                                          • +
                                          • Defined in src/Chuck.ts:653
                                          • +
                                          • Defined in src/Chuck.ts:662
                                          • +
                                          • Defined in src/Chuck.ts:677
                                          • +
                                          • Defined in src/Chuck.ts:686
                                          • +
                                          • Defined in src/Chuck.ts:701
                                          • +
                                          • Defined in src/Chuck.ts:715
                                          • +
                                          • Defined in src/Chuck.ts:733
                                          • +
                                          • Defined in src/Chuck.ts:748
                                          • +
                                          • Defined in src/Chuck.ts:764
                                          • +
                                          • Defined in src/Chuck.ts:774
                                          • +
                                          • Defined in src/Chuck.ts:789
                                          • +
                                          • Defined in src/Chuck.ts:804
                                          • +
                                          • Defined in src/Chuck.ts:822
                                          • +
                                          • Defined in src/Chuck.ts:837
                                          • +
                                          • Defined in src/Chuck.ts:854
                                          • +
                                          • Defined in src/Chuck.ts:863
                                          • +
                                          • Defined in src/Chuck.ts:877
                                          • +
                                          • Defined in src/Chuck.ts:885
                                          • +
                                          • Defined in src/Chuck.ts:899
                                          • +
                                          • Defined in src/Chuck.ts:908
                                          • +
                                          • Defined in src/Chuck.ts:922
                                          • +
                                          • Defined in src/Chuck.ts:932
                                          • +
                                          • Defined in src/Chuck.ts:939
                                          • +
                                          • Defined in src/Chuck.ts:960
                                            • diff --git a/docs/classes/HID.html b/docs/classes/HID.html index 07ba628..b650c9d 100644 --- a/docs/classes/HID.html +++ b/docs/classes/HID.html @@ -31,7 +31,7 @@

                                              Hierarchy

                                              • HID
                                            +
                                          • Defined in src/Hid.ts:27
                                          • @@ -64,22 +64,22 @@

                                            Properties

                                            theChuck: Chuck
                                            +
                                          • Defined in src/Hid.ts:29
                                          • keymap: boolean[]
                                            +
                                          • Defined in src/Hid.ts:30
                                          • _mouseActive: boolean = false
                                            +
                                          • Defined in src/Hid.ts:31
                                          • _kbdActive: boolean = false
                                            +
                                          • Defined in src/Hid.ts:32
                                          • boundHandleMouseMove: {}
                                            @@ -89,7 +89,7 @@

                                            Type declaration

                                            • +
                                            • Defined in src/Hid.ts:35
                                            • boundHandleMouseDown: {}
                                              @@ -99,7 +99,7 @@

                                              Type declaration

                                              • +
                                              • Defined in src/Hid.ts:36
                                              • boundHandleMouseUp: {}
                                                @@ -109,7 +109,7 @@

                                                Type declaration

                                                • +
                                                • Defined in src/Hid.ts:37
                                                • boundHandleMouseWheel: {}
                                                  @@ -119,7 +119,7 @@

                                                  Type declaration

                                                  • +
                                                  • Defined in src/Hid.ts:38
                                                  • boundHandleKeyDown: {}
                                                    @@ -129,7 +129,7 @@

                                                    Type declaration

                                                    • +
                                                    • Defined in src/Hid.ts:39
                                                    • boundHandleKeyUp: {}
                                                      @@ -139,7 +139,7 @@

                                                      Type declaration

                                                      • +
                                                      • Defined in src/Hid.ts:40
                                                      • Methods

                                                        @@ -178,7 +178,7 @@

                                                        Example

                                                        theChuck
                                                        +
                                                      • Defined in src/Hid.ts:75
                                                        • @@ -194,7 +194,7 @@

                                                          Example

                                                          // If mouse HI
                                                           
                                                        +
                                                      • Defined in src/Hid.ts:136
                                                        • @@ -208,7 +208,7 @@

                                                          Example

                                                          // If mouse HI
                                                           
                                                        +
                                                      • Defined in src/Hid.ts:152
                                                        • @@ -223,7 +223,7 @@

                                                          Example

                                                          // If keyboard
                                                           
                                                        +
                                                      • Defined in src/Hid.ts:169
                                                        • @@ -237,7 +237,7 @@

                                                          Example

                                                          // If keyboard
                                                           
                                                        +
                                                      • Defined in src/Hid.ts:182
                                                      • +
                                                      • Defined in src/accel/Accel.ts:28
                                                      • Methods

                                                        @@ -94,7 +96,7 @@

                                                        Example

                                                        theChuck
                                                        +
                                                      • Defined in src/accel/Accel.ts:48
                                                        • @@ -108,7 +110,7 @@

                                                          Example

                                                          // If accel is
                                                           
                                                        +
                                                      • Defined in src/accel/Accel.ts:81
                                                      • +
                                                      • Defined in src/accel/Accel.ts:95
                                                      • +
                                                      • Defined in src/Chuck.ts:117
                                                        • @@ -329,7 +329,7 @@

                                                          Example

                                                          Chuck
                                                        +
                                                      • Defined in src/Chuck.ts:235
                                                      • +
                                                      • Defined in src/Chuck.ts:159
                                                      • +
                                                      • Defined in src/Chuck.ts:174
                                                      • +
                                                      • Defined in src/Chuck.ts:186
                                                      • +
                                                      • Defined in src/Chuck.ts:201
                                                      • +
                                                      • Defined in src/Chuck.ts:245
                                                      • +
                                                      • Defined in src/Chuck.ts:255
                                                      • +
                                                      • Defined in src/Chuck.ts:285
                                                      • +
                                                      • Defined in src/Chuck.ts:324
                                                      • +
                                                      • Defined in src/Chuck.ts:344
                                                      • +
                                                      • Defined in src/Chuck.ts:379
                                                      • +
                                                      • Defined in src/Chuck.ts:419
                                                      • +
                                                      • Defined in src/Chuck.ts:462
                                                      • +
                                                      • Defined in src/Chuck.ts:511
                                                      • +
                                                      • Defined in src/Chuck.ts:525
                                                      • +
                                                      • Defined in src/Chuck.ts:539
                                                      • +
                                                      • Defined in src/Chuck.ts:547
                                                      • +
                                                      • Defined in src/Chuck.ts:558
                                                      • +
                                                      • Defined in src/Chuck.ts:576
                                                      • +
                                                      • Defined in src/Chuck.ts:592
                                                      • +
                                                      • Defined in src/Chuck.ts:606
                                                      • +
                                                      • Defined in src/Chuck.ts:616
                                                      • +
                                                      • Defined in src/Chuck.ts:630
                                                      • +
                                                      • Defined in src/Chuck.ts:639
                                                      • +
                                                      • Defined in src/Chuck.ts:653
                                                      • +
                                                      • Defined in src/Chuck.ts:662
                                                      • +
                                                      • Defined in src/Chuck.ts:677
                                                      • +
                                                      • Defined in src/Chuck.ts:686
                                                      • +
                                                      • Defined in src/Chuck.ts:701
                                                      • +
                                                      • Defined in src/Chuck.ts:715
                                                      • +
                                                      • Defined in src/Chuck.ts:733
                                                      • +
                                                      • Defined in src/Chuck.ts:748
                                                      • +
                                                      • Defined in src/Chuck.ts:764
                                                      • +
                                                      • Defined in src/Chuck.ts:774
                                                      • +
                                                      • Defined in src/Chuck.ts:789
                                                      • +
                                                      • Defined in src/Chuck.ts:804
                                                      • +
                                                      • Defined in src/Chuck.ts:822
                                                      • +
                                                      • Defined in src/Chuck.ts:837
                                                      • +
                                                      • Defined in src/Chuck.ts:854
                                                      • +
                                                      • Defined in src/Chuck.ts:863
                                                      • +
                                                      • Defined in src/Chuck.ts:877
                                                      • +
                                                      • Defined in src/Chuck.ts:885
                                                      • +
                                                      • Defined in src/Chuck.ts:899
                                                      • +
                                                      • Defined in src/Chuck.ts:908
                                                      • +
                                                      • Defined in src/Chuck.ts:922
                                                      • +
                                                      • Defined in src/Chuck.ts:932
                                                      • +
                                                      • Defined in src/Chuck.ts:939
                                                      • +
                                                      • Defined in src/Chuck.ts:960
                                                        • diff --git a/docs/classes/Gyro.html b/docs/classes/Gyro.html index 586ec74..92849c1 100644 --- a/docs/classes/Gyro.html +++ b/docs/classes/Gyro.html @@ -24,13 +24,15 @@

                                                          Class Gyro

                                                          Example

                                                          import { Chuck, Gyro } from "webchuck";

                                                          const theChuck = await Chuck.init([]);
                                                          const gyro = await Gyro.init(theChuck); // Initialize Gyro
                                                          +

                                                          The "deviceorientation" event gives motion of the device around the three axes (x, y, and z) represented as degrees from 0 to 360. +More on the "deviceorientation" event can be found online here.

                                                        Hierarchy

                                                        • Gyro
                                                        +
                                                      • Defined in src/gyro/Gyro.ts:23
                                                      • @@ -54,12 +56,12 @@

                                                        Properties

                                                        theChuck: Chuck
                                                        +
                                                      • Defined in src/gyro/Gyro.ts:25
                                                      • _gyroActive: boolean = false
                                                        +
                                                      • Defined in src/gyro/Gyro.ts:26
                                                      • boundHandleOrientation: {}
                                                        @@ -69,7 +71,7 @@

                                                        Type declaration

                                                        • +
                                                        • Defined in src/gyro/Gyro.ts:28
                                                        • Methods

                                                          @@ -94,7 +96,7 @@

                                                          Example

                                                          theChuck
                                                          +
                                                        • Defined in src/gyro/Gyro.ts:48
                                                          • @@ -108,7 +110,7 @@

                                                            Example

                                                            // If gyro is
                                                             
                                                          +
                                                        • Defined in src/gyro/Gyro.ts:81
                                                        • +
                                                        • Defined in src/gyro/Gyro.ts:95
                                                        • +
                                                        • Defined in src/hid/Hid.ts:36
                                                        • boundHandleMouseUp: {}
                                                          @@ -109,7 +109,7 @@

                                                          Type declaration

                                                          • +
                                                          • Defined in src/hid/Hid.ts:37
                                                          • boundHandleMouseWheel: {}
                                                            @@ -119,7 +119,7 @@

                                                            Type declaration

                                                            • +
                                                            • Defined in src/hid/Hid.ts:38
                                                            • boundHandleKeyDown: {}
                                                              @@ -129,7 +129,7 @@

                                                              Type declaration

                                                              • +
                                                              • Defined in src/hid/Hid.ts:39
                                                              • boundHandleKeyUp: {}
                                                                @@ -139,7 +139,7 @@

                                                                Type declaration

                                                                • +
                                                                • Defined in src/hid/Hid.ts:40
                                                                • Methods

                                                                  @@ -178,7 +178,7 @@

                                                                  Example

                                                                  theChuck
                                                                  +
                                                                • Defined in src/hid/Hid.ts:75
                                                                  • @@ -194,7 +194,7 @@

                                                                    Example

                                                                    // If mouse HI
                                                                     
                                                                  +
                                                                • Defined in src/hid/Hid.ts:136
                                                                  • @@ -208,7 +208,7 @@

                                                                    Example

                                                                    // If mouse HI
                                                                     
                                                                  +
                                                                • Defined in src/hid/Hid.ts:152
                                                                  • @@ -223,7 +223,7 @@

                                                                    Example

                                                                    // If keyboard
                                                                     
                                                                  +
                                                                • Defined in src/hid/Hid.ts:169
                                                                  • @@ -237,7 +237,7 @@

                                                                    Example

                                                                    // If keyboard
                                                                     
                                                                  +
                                                                • Defined in src/hid/Hid.ts:182