Skip to content

Commit

Permalink
Save keycodes to /data/local/tmp/menuKeycodes.json
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaDoes committed Jul 30, 2023
1 parent 806d665 commit c209f18
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 96 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
YOU CANNOT DOWNLOAD THIS UPDATE THROUGH MAGISK'S IN-APP MODULE UPDATER.

You can read the changelog and install this new update here: [Release v2.0.3](https://github.com/JoshuaDoes/pixel-tensor-audio-decompressor/releases/tag/203)
You can read the changelog and install this new update here: [Release v2.0.4](https://github.com/JoshuaDoes/pixel-tensor-audio-decompressor/releases/tag/204)
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ popd () {
}

echo "* Configuring the build environment"
export VER="v2.0.3"
export VER="v2.0.4"
export ZIP="pixel-tensor-audio-decompressor-$VER.zip"
export GOOS=linux
export GOARCH=arm64
Expand Down
188 changes: 111 additions & 77 deletions menu/keycalibrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"time"
Expand Down Expand Up @@ -49,7 +50,8 @@ func (kc *KeyCalibration) Input(keyboard string, keycode uint16, onRelease bool)
if !kc.Ready {
os.Exit(0)
}
if kc.Action == "" {
if kc.Action == "" || kc.Action == "cancel" {
kc.Action = ""
return
}
if onRelease {
Expand All @@ -68,95 +70,127 @@ func (kc *KeyCalibration) Input(keyboard string, keycode uint16, onRelease bool)

func calibrate() {
//Generate a key calibration file if one doesn't exist yet
if _, err := os.Stat(keyCalibrationFile); err != nil {
calibrator := &KeyCalibration{KLs: make([]*KeycodeListener, 0)}
calibrator := &KeyCalibration{KLs: make([]*KeycodeListener, 0)}

//Get a list of keyboards
keyboards := make([]string, 0)
err := filepath.Walk("/dev/input", func(path string, info os.FileInfo, err error) error {
if len(path) < 16 || string(path[:16]) != "/dev/input/event" {
return nil
}
keyboards = append(keyboards, path)
//Get a list of keyboards
keyboards := make([]string, 0)
err := filepath.Walk("/dev/input", func(path string, info os.FileInfo, err error) error {
if len(path) < 16 || string(path[:16]) != "/dev/input/event" {
return nil
})
if err != nil {
panic(fmt.Sprintf("error walking inputs: %v", err))
}
keyboards = append(keyboards, path)
return nil
})
if err != nil {
panic(fmt.Sprintf("error walking inputs: %v", err))
}

//Bind all keyboards to calibrator input
for _, keyboard := range keyboards {
kl, err := NewKeycodeListener(keyboard)
if err != nil {
panic(fmt.Sprintf("error listening to walked keyboard %s: %v", keyboard, err))
}
kl.RootBind = calibrator.Input
calibrator.KLs = append(calibrator.KLs, kl)
go kl.Run()
//Bind all keyboards to calibrator input
for _, keyboard := range keyboards {
kl, err := NewKeycodeListener(keyboard)
if err != nil {
panic(fmt.Sprintf("error listening to walked keyboard %s: %v", keyboard, err))
}
kl.RootBind = calibrator.Input
calibrator.KLs = append(calibrator.KLs, kl)
go kl.Run()
}

//Start calibrating!
stages := 5
for stage := 0; stage < stages; stage++ {
switch stage {
case 0:
clear(5)
fmt.Println("\t\tWelcome to the calibrator!\n")
time.Sleep(time.Second * 2)
fmt.Println("\t\tControllers and remotes\n\t\tare also supported.\n")
//Start calibrating!
stages := 6
for stage := 0; stage < stages; stage++ {
switch stage {
case 0:
keyCalibrationJSON, err := ioutil.ReadFile(keyCalibrationFile)
if err == nil {
keyCalibration = make(map[string][]*MenuKeycodeBinding)
err = json.Unmarshal(keyCalibrationJSON, &keyCalibration)
if err != nil {
stage = 1
continue
}

clear(3)
fmt.Println("\t\tYou've calibrated before!\n")
time.Sleep(time.Second * 2)
fmt.Println("\t\tThis is a guided process.\n")
fmt.Println("\t\tPress any key within\n\t\t5 seconds to recalibrate.\n")
calibrator.Ready = true
time.Sleep(time.Second * 2)
fmt.Println("\t\tGet ready!\n")
time.Sleep(time.Second * 3)
case 1:
clear(1)
calibrator.Action = "nextItem"
fmt.Printf("\n")
fmt.Println("\t\tPress any key to use to\n\t\tnavigate down in a menu.\n")
fmt.Println("\t\t\tRecommended: volume down")
for calibrator.Action != "" {
}
case 2:
calibrator.Action = "prevItem"
fmt.Printf("\n")
fmt.Println("\t\tPress any key to use to\n\t\tnavigate up in a menu.\n")
fmt.Println("\t\t\tRecommended: volume up")
for calibrator.Action != "" {
}
case 3:
calibrator.Action = "selectItem"
fmt.Printf("\n")
fmt.Println("\t\tPress any key to use to\n\t\tselect a menu item.\n")
fmt.Println("\t\t\tRecommended: touch screen")
calibrator.Action = "cancel"
timeout := time.Now()
for calibrator.Action != "" {
if time.Now().Sub(timeout).Seconds() > 5 {
break
}
time.Sleep(time.Millisecond * 100)
}
case 4:
clear(5)
fmt.Println("\t\tSaving results...\n")
keyboards, err := json.Marshal(keyCalibration, true)
if err != nil {
panic(fmt.Sprintf("error encoding calibration results: %v", err))
if time.Now().Sub(timeout).Seconds() < 5 {
calibrator.Action = ""
fmt.Println("\t\tRecalibration time!")
time.Sleep(time.Second * 2)
continue
}
keyboardsFile, err := os.Create(keyCalibrationFile)
if err != nil {
panic(fmt.Sprintf("error creating calibration file: %v", err))
}
defer keyboardsFile.Close()
_, err = keyboardsFile.Write(keyboards)
if err != nil {
panic(fmt.Sprintf("error writing calibration file: %v", err))
}
//fmt.Println(string(keyboards))
fmt.Println("\t\tCalibration complete!")
time.Sleep(time.Second * 2)
//calibrator.Ready = false
stage = stages-1 //Skip to the end of the stages
}
case 1:
calibrator.Ready = false
keyCalibration = make(map[string][]*MenuKeycodeBinding)
clear(5)
fmt.Println("\t\tWelcome to the calibrator!\n")
fmt.Println("\t\tPress any key to cancel.\n")
time.Sleep(time.Second * 2)
fmt.Println("\t\tControllers and remotes\n\t\tare also supported.\n")
time.Sleep(time.Second * 2)
fmt.Println("\t\tThis is a guided process.\n")
time.Sleep(time.Second * 2)
fmt.Println("\t\tGet ready!\n")
time.Sleep(time.Second * 3)
case 2:
clear(1)
calibrator.Ready = true
calibrator.Action = "nextItem"
fmt.Printf("\n")
fmt.Println("\t\tPress any key to use to\n\t\tnavigate down in a menu.\n")
fmt.Println("\t\t\tRecommended: volume down")
for calibrator.Action != "" {
}
case 3:
calibrator.Action = "prevItem"
fmt.Printf("\n")
fmt.Println("\t\tPress any key to use to\n\t\tnavigate up in a menu.\n")
fmt.Println("\t\t\tRecommended: volume up")
for calibrator.Action != "" {
}
case 4:
calibrator.Action = "selectItem"
fmt.Printf("\n")
fmt.Println("\t\tPress any key to use to\n\t\tselect a menu item.\n")
fmt.Println("\t\t\tRecommended: touch screen")
for calibrator.Action != "" {
}
case 5:
clear(5)
fmt.Println("\t\tSaving results...\n")
keyboards, err := json.Marshal(keyCalibration, true)
if err != nil {
panic(fmt.Sprintf("error encoding calibration results: %v", err))
}
keyboardsFile, err := os.Create(keyCalibrationFile)
if err != nil {
panic(fmt.Sprintf("error creating calibration file: %v", err))
}
defer keyboardsFile.Close()
_, err = keyboardsFile.Write(keyboards)
if err != nil {
panic(fmt.Sprintf("error writing calibration file: %v", err))
}
//fmt.Println(string(keyboards))
fmt.Println("\t\tCalibration complete!")
time.Sleep(time.Second * 2)
//calibrator.Ready = false
}
}

for i := 0; i < len(calibrator.KLs); i++ {
calibrator.KLs[i].Close()
}
for i := 0; i < len(calibrator.KLs); i++ {
calibrator.KLs[i].Close()
}
}
9 changes: 0 additions & 9 deletions menu/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,6 @@ func init() {
vLines = 100
}

keyCalibrationJSON, err := ioutil.ReadFile(keyCalibrationFile)
if err == nil {
keyCalibration = make(map[string][]*MenuKeycodeBinding)
err = json.Unmarshal(keyCalibrationJSON, &keyCalibration)
if err != nil {
panic(fmt.Sprintf("error parsing key calibration file: %v", err))
}
}

configJSON, err := ioutil.ReadFile(configFile)
if err != nil {
panic(fmt.Sprintf("error reading config file: %v", err))
Expand Down
4 changes: 2 additions & 2 deletions module/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ print_modname() {
ui_print ""
ui_print "***********************************"
ui_print "* Pixel Tensor Audio Decompressor *"
ui_print " * 2.0.3 * "
ui_print " * 2.0.4 * "
ui_print "** Made and tested by JoshuaDoes **"
ui_print "***********************************"
ui_print "For the following devices:"
Expand Down Expand Up @@ -42,7 +42,7 @@ on_install() {
export TERM=xterm-256color
mkdir "$MODPATH"
unzip -o "$ZIPFILE" "*" -d "$MODPATH" >&2
exec "$MODPATH/bin/menu" --workingDir "$MODPATH" 2>&1
exec "$MODPATH/bin/menu" --workingDir "$MODPATH" --keyCalibration "/data/local/tmp/menuKeycodes.json" 2>&1
}

set_permissions() {
Expand Down
2 changes: 1 addition & 1 deletion module/menu.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"menus": {
"home": {
"noGoBack": true,
"title": "Pixel Tensor Audio Decompressor\n JoshuaDoes | v2.0.3 ",
"title": "Pixel Tensor Audio Decompressor\n JoshuaDoes | v2.0.4 ",
"subtitle": "\tIf you calibrated wrongly,\n\tclose Magisk and try again.",
"items": [
{
Expand Down
4 changes: 2 additions & 2 deletions module/module.prop
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
id=pixel-tensor-audio-decompressor
name=Pixel Tensor Audio Decompressor
version=v2.0.3
versionCode=203
version=v2.0.4
versionCode=204
author=JoshuaDoes
description=Patches mixer_paths.xml on Pixel Tensor devices to decompress the digital PCM volume.
updateJson=https://raw.githubusercontent.com/JoshuaDoes/pixel-tensor-audio-decompressor/dev/update.json
6 changes: 3 additions & 3 deletions update.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"version": "v2.0.3",
"versionCode": 203,
"zipUrl": "https://github.com/JoshuaDoes/pixel-tensor-audio-decompressor/releases/tag/203",
"version": "v2.0.4",
"versionCode": 204,
"zipUrl": "https://github.com/JoshuaDoes/pixel-tensor-audio-decompressor/releases/tag/204",
"changelog": "https://raw.githubusercontent.com/JoshuaDoes/pixel-tensor-audio-decompressor/dev/CHANGELOG.md"
}

0 comments on commit c209f18

Please sign in to comment.