Skip to content

Commit

Permalink
v0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
temoto committed Jul 16, 2017
1 parent 76ae609 commit 68777ff
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 10 deletions.
14 changes: 4 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
# Binaries for programs and plugins
*.exe
*.dll
*.so
*.dylib

# Test binary, build with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.exe
*.out

# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
*.so
*.test
.glide/
linux-input-control
60 changes: 60 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package main

import (
"encoding/binary"
"log"
"os"
)

var (
senable = []byte("a")
sdisable = []byte("d")
)

func main() {
// TODO: command line flag
masterPath := "/dev/input/event0"
slavePath := "/sys/bus/i2c/devices/0-0050/neocmd"

var master, slave *os.File
var err error
if master, err = os.Open(masterPath); err != nil {
log.Fatal("open ", masterPath, err)
}

slaveState := true
evb := make([]byte, 16)
for {
n, err := master.Read(evb)
if err != nil {
log.Print("master.Read: ", err)
continue
}
if n != 16 {
log.Printf("master.Read invalid event size=%d, ignore", n)
continue
}
evType := binary.LittleEndian.Uint16(evb[8:])
evCode := binary.LittleEndian.Uint16(evb[10:])
evValue := binary.LittleEndian.Uint32(evb[12:])
log.Printf("event type=%d code=%d value=%d", evType, evCode, evValue)

if evType == 1 && evCode == 116 && evValue == 1 {
sb := senable
slaveState = !slaveState
if !slaveState {
sb = sdisable
}
log.Printf("power key pressed, new slavestate=%v writing=%s", slaveState, string(sb))
if slave, err = os.OpenFile(slavePath, os.O_WRONLY|os.O_TRUNC, 0644); err != nil {
log.Fatal("open ", slavePath, err)
}
if _, err = slave.WriteAt(sb, 0); err != nil {
log.Fatal("slave.Write ", err)
}
if err = slave.Close(); err != nil {
log.Fatal("slave.Close ", err)
}
}
}
}
17 changes: 17 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
What
====

For XCSoar flight pilots. Switch IR touchpad on/off with power button on Kobo.


Instruction
===========

Build: `ARCH=arm GOARM=7 GOOS=linux go build`
Upload: `tnftp -u [email protected]: linux-input-control`


Contact
=======

[email protected]

0 comments on commit 68777ff

Please sign in to comment.