KittenBot Hardware and API Documentation

website·Indexed 31 days ago

https://w.kittenbot.net/

Documentation for KittenBot hardware, including the AgileWhisker customizable mechanical keyboard, Elite60, Num Keypad, and Grapebit. Includes API references and firmware update guides for Jacdac modules such as the RGB Strip, Servo, Accelerometer, Env Sensor, and various sensors and controllers compatible with DeviceScript.

Tokens
10.4K
Snippets
70
Records
98
Agent score
50%

What's inside KittenBot

  1. Overview of AgileWhisker Programmable Peripherals

    AgileWhisker is a set of open-source PC peripheral widgets (including the AgileWhisker Elite and Keypad-Base) designed to be fully customizable. Unlike traditional custom keyboards, AgileWhisker allows users to program hardware behavior using TypeScript and JavaScript, lowering the barrier for creating custom macros and workflow actions.
  2. Overview of the AgileWhisker Keyboard host app

    The AgileWhisker Keyboard host app is an open-source desktop application written in TypeScript. It acts as a bridge between jacdac devices and the system, exposing system abilities to the keyboard.
  3. Initialize the EmailClient in DeviceScript

    Use the ds.EmailClient class from the @devicescript/core library to interact with email services and receive notifications for new emails.
    import * as ds from "@devicescript/core"
    
    const email = new ds.EmailClient()
  4. Control an RGB LED using a rotary encoder

    This skill demonstrates how to use a rotary encoder to control an RGB Ring LED. To implement this functionality, you will need a rotary encoder and an RGB Ring LED connected to your hardware setup.
  5. Initialize and use the VibrationMotor class

    The VibrationMotor class from the @devicescript/core library provides an interface to control a haptic vibration motor on a supported device.
    import { VibrationMotor } from "@devicescript/core"
    
    const vibrationMotor = new VibrationMotor()
  6. Initialize and use the Magnet Sensor

    The Magnet Sensor measures the strength and polarity of a magnetic field. It is implemented via the MagneticFieldLevel class from the @devicescript/core library.
    import { MagneticFieldLevel } from "@devicescript/core"
    
    const magneticFieldLevel = new MagneticFieldLevel()
  7. Use the accelerometer skill to control mouse movement and clicks

    The accelerometer skill monitors a user's physical movement via an accelerometer module and translates that input into mouse cursor movement. It also supports a button module to translate physical button presses into mouse left-click actions.
  8. Open a URL or file using the OpenURL skill

    The OpenURL skill allows a device to open a web page or a local file on a connected PC when a button is pressed. It functions by calling the open_url function from the PC Controller class within the device script core library.
  9. Initialize and use the RotaryEncoder in DeviceScript

    The RotaryEncoder class is used to interface with an incremental rotary encoder, which converts the angular motion of a shaft into a digital signal.
    import { RotaryEncoder } from "@devicescript/core"
    
    const rotaryEncoder = new RotaryEncoder()
  10. Create a custom RGB lighting effect on AgileWhisker

    You can customize the keyboard's RGB LEDs using TypeScript and DeviceScript. This example demonstrates how to light up a key in red when it is pressed and automatically turn it off after 400ms.

    Key components used:

    • KeyboardClient: To listen for key press events.
    • startLed: To initialize the LED strip (WS2812B_GRB on GPIO 7).
    • hid2idx: A utility mapping to translate HID key codes to LED indices.
    import { KeyboardClient, LedStripLightType, LedVariant, gpio } from "@devicescript/core";
    import { startLed } from "@devicescript/drivers";
    import { hid2idx } from "./utils/ledmap";
    
    // Initialize keyboard LEDs
    const led = await startLed({
        length: 13*5,
        columns: 5,
        variant: LedVariant.Strip,
        hwConfig: { type: LedStripLightType.WS2812B_GRB, pin: gpio(7) },
    })
    await led.showAll(0) // Turn all LEDs off
    
    // Initialize keyboard client
    const kb = new KeyboardClient()
    // Get the pixel buffer
    const pixels = await led.buffer()
    
    let lastLightNum = 0
    let lastClearLight: number = null
    
    // Listen for key down events
    kb.down.subscribe(async (key) => {
      if (hid2idx[key]) {
          if(lastClearLight && lastLightNum === hid2idx[key]){
            // Clear timeout if key is held down
            clearTimeout(lastClearLight)
          } else {
            let lastLight = hid2idx[key]
            // Set pressed key color to red
            pixels.setAt(hid2idx[key], 0xff0000)
            await led.show();
          }
          
          // Set auto-off timer for 400ms
          lastClearLight = setTimeout(async() => {
            pixels.setAt(hid2idx[key], 0)
            await led.show();
            lastClearLight = null
          }, 400)
      }
    })
    
  11. Program AgileWhisker hardware using TypeScript

    AgileWhisker supports programming and reprogramming keyboard hardware using TypeScript. This allows developers to create custom macros and specific workflow actions tailored to their needs.