Skip to content

Commit

Permalink
WIP: Add targets/sgkey-ble
Browse files Browse the repository at this point in the history
  • Loading branch information
sago35 committed Oct 31, 2023
1 parent 6c67abe commit 4b88c9c
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 0 deletions.
9 changes: 9 additions & 0 deletions targets/sgkey-ble/left/def.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package main

import keyboard "github.com/sago35/tinygo-keyboard"

func loadKeyboardDef() {
keyboard.KeyboardDef = []byte{
0x5D, 0x00, 0x00, 0x80, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x3D, 0x82, 0x80, 0x19, 0x1B, 0x9A, 0xE8, 0xB8, 0xA7, 0x6E, 0x26, 0x77, 0x5D, 0x26, 0xFB, 0x93, 0xC2, 0xE2, 0xE7, 0x46, 0x70, 0xE9, 0xC5, 0x5C, 0x25, 0x18, 0xBE, 0xAF, 0x39, 0x0B, 0xA2, 0x5E, 0x69, 0x76, 0xF2, 0x88, 0x22, 0x64, 0xD8, 0x8C, 0x86, 0x95, 0x27, 0x0D, 0xE9, 0x6E, 0xE8, 0x5A, 0x8B, 0x49, 0x2F, 0xC8, 0x8A, 0xE8, 0x9F, 0x7D, 0x15, 0x0A, 0x17, 0x74, 0xF1, 0xC6, 0x0D, 0x1D, 0x3B, 0x21, 0x36, 0xC0, 0x2C, 0xF4, 0xAD, 0x5E, 0x45, 0x34, 0x81, 0x7E, 0x37, 0x98, 0x72, 0x10, 0x9C, 0x64, 0xA9, 0xC2, 0x7C, 0x8F, 0xE7, 0xFE, 0xA7, 0x4A, 0xC2, 0x31, 0x69, 0xA9, 0x39, 0xA0, 0x92, 0xCF, 0x3E, 0x49, 0xE9, 0x02, 0xED, 0x02, 0x9B, 0x0A, 0x25, 0x5C, 0x22, 0xB8, 0x36, 0x72, 0x2A, 0xB2, 0x80, 0xA7, 0x41, 0xEB, 0x67, 0x3C, 0xCE, 0x0C, 0xCD, 0xAF, 0x22, 0x73, 0x9C, 0x29, 0x56, 0x27, 0xF9, 0x2C, 0xE0, 0xD1, 0x48, 0x79, 0x53, 0x6B, 0x2F, 0xAE, 0x4A, 0xF1, 0x3E, 0x0A, 0x0D, 0xE9, 0x8F, 0xBF, 0xFF, 0x75, 0x49, 0x80, 0x00,
}
}
58 changes: 58 additions & 0 deletions targets/sgkey-ble/left/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package main

import (
_ "embed"
"log"
"machine/usb"
"time"

keyboard "github.com/sago35/tinygo-keyboard"
"github.com/sago35/tinygo-keyboard/keycodes/jp"
)

func main() {
usb.Product = "sgkey-ble-0.1.0"

err := run()
if err != nil {
log.Fatal(err)
}
}

func run() error {
time.Sleep(2 * time.Second)
d := keyboard.New()

d.AddBleKeyboard(6, "sgkey-left", [][]keyboard.Keycode{
{
jp.KeyT, jp.KeyI, jp.KeyN,
jp.KeyY, jp.KeyG, jp.KeyO,
},
{
jp.KeyT, jp.KeyI, jp.KeyN,
jp.KeyY, jp.KeyG, jp.KeyO,
},
{
jp.KeyT, jp.KeyI, jp.KeyN,
jp.KeyY, jp.KeyG, jp.KeyO,
},
})

// for Vial
loadKeyboardDef()

err := d.Init()
if err != nil {
return err
}

cont := true
for cont {
err := d.Tick()
if err != nil {
return err
}
time.Sleep(1 * time.Millisecond)
}
return nil
}
12 changes: 12 additions & 0 deletions targets/sgkey-ble/left/vial.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "tinygo-sgkey-ble",
"vendorId": "0x2886",
"productId": "0x8045",
"matrix": {"rows": 1, "cols": 6},
"layouts": {
"keymap": [
["0,0","0,1","0,2"],
["0,3","0,4","0,5"]
]
}
}
69 changes: 69 additions & 0 deletions targets/sgkey-ble/right/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package main

import (
_ "embed"
"log"
"machine"
"time"

keyboard "github.com/sago35/tinygo-keyboard"
)

func main() {
err := run()
if err != nil {
log.Fatal(err)
}
}

type RCS struct {
row, col int
state keyboard.State
}

func run() error {
d := keyboard.New()

colPins := []machine.Pin{
machine.D8,
machine.D9,
machine.D10,
}

rowPins := []machine.Pin{
machine.D1,
machine.D2,
}

d.AddMatrixKeyboard(colPins, rowPins, [][]keyboard.Keycode{
{
0x0000, 0x0001, 0x0002,
0x0003, 0x0004, 0x0005,
},
})

bleKeyboard := keyboard.BleTxKeyboard{
RxBleName: "sgkey-left",
}
d.Keyboard = &bleKeyboard

err := bleKeyboard.Connect()
if err != nil {
return err
}

err = d.Init()
if err != nil {
return err
}

cont := true
for cont {
err := d.Tick()
if err != nil {
return err
}
time.Sleep(1 * time.Millisecond)
}
return nil
}

0 comments on commit 4b88c9c

Please sign in to comment.