From c209f1800e265276a955eed30f3a37803977c0f1 Mon Sep 17 00:00:00 2001 From: JoshuaDoes Date: Sun, 30 Jul 2023 03:51:56 -0400 Subject: [PATCH] Save keycodes to /data/local/tmp/menuKeycodes.json --- CHANGELOG.md | 2 +- build.sh | 2 +- menu/keycalibrator.go | 188 +++++++++++++++++++++++++----------------- menu/main.go | 9 -- module/install.sh | 4 +- module/menu.json | 2 +- module/module.prop | 4 +- update.json | 6 +- 8 files changed, 121 insertions(+), 96 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8182362..0e27e38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) \ No newline at end of file +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) \ No newline at end of file diff --git a/build.sh b/build.sh index be3663d..5ff79c9 100755 --- a/build.sh +++ b/build.sh @@ -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 diff --git a/menu/keycalibrator.go b/menu/keycalibrator.go index 82eec90..8cf7d30 100644 --- a/menu/keycalibrator.go +++ b/menu/keycalibrator.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "io/ioutil" "os" "path/filepath" "time" @@ -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 { @@ -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() } } diff --git a/menu/main.go b/menu/main.go index 2531d98..df2fdf8 100644 --- a/menu/main.go +++ b/menu/main.go @@ -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)) diff --git a/module/install.sh b/module/install.sh index 05a235c..3e4cbcd 100644 --- a/module/install.sh +++ b/module/install.sh @@ -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:" @@ -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() { diff --git a/module/menu.json b/module/menu.json index 30e6370..7811719 100644 --- a/module/menu.json +++ b/module/menu.json @@ -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": [ { diff --git a/module/module.prop b/module/module.prop index bf66194..9617395 100644 --- a/module/module.prop +++ b/module/module.prop @@ -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 diff --git a/update.json b/update.json index 4c6e278..61ee851 100644 --- a/update.json +++ b/update.json @@ -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" }