Skip to content

Commit

Permalink
Fix version on Android, extra error-handling in connectvector
Browse files Browse the repository at this point in the history
  • Loading branch information
kercre123 committed Apr 22, 2024
1 parent 4f2c0c7 commit f64099b
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 24 deletions.
3 changes: 3 additions & 0 deletions chipper/pkg/vars/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ func Init() {
Certs = join(podDir, "./certs")
SessionCertPath = join(podDir, SessionCertPath)
SavedChatsPath = join(podDir, SavedChatsPath)
if runtime.GOOS == "android" {
VersionFile = AndroidPath + "/static/version"
}
os.Mkdir(JdocsDir, 0777)
os.Mkdir(SessionCertPath, 0777)
os.Mkdir(Certs, 0777)
Expand Down
5 changes: 4 additions & 1 deletion chipper/pkg/wirepod/setup/ble.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,10 @@ func BluetoothSetupAPI(w http.ResponseWriter, r *http.Request) {
err = ConnectVector(BleClient, id)
if err != nil {
fmt.Fprint(w, "error: "+err.Error())
return
if err.Error() == "error: took more than 5 seconds" {
logger.Println("It took too long to connect to Vector. Quitting and letting systemd restart")
os.Exit(1)
}
}
fmt.Fprint(w, "success")
return
Expand Down
7 changes: 6 additions & 1 deletion chipper/pkg/wirepod/stt/vosk/Vosk.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log"
"os"
"path/filepath"
"runtime"
"sync"
"time"

Expand Down Expand Up @@ -112,7 +113,11 @@ func runTest() {
withGrm = false
}
rec, recind := getRec(withGrm)
pcmBytes, _ := os.ReadFile("./stttest.pcm")
sttTestPath := "./stttest.pcm"
if runtime.GOOS == "android" {
sttTestPath = vars.AndroidPath + "/static/stttest.pcm"
}
pcmBytes, _ := os.ReadFile(sttTestPath)
var micData [][]byte
cTime := time.Now()
micData = sr.SplitVAD(pcmBytes)
Expand Down
57 changes: 35 additions & 22 deletions chipper/webroot/js/ble.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function showBotAuth() {
}

function checkBLECapability() {
document.getElementById("disconnectButton").innerHTML = "";
updateAuthel("Checking if wire-pod can use BLE directly...");
fetch("/api-ble/init")
.then((response) => response.text())
Expand Down Expand Up @@ -161,6 +162,14 @@ function ConnectRobot(id) {
if (response.includes("success")) {
CreatePinEntry();
return;
} else {
alert(
"There was an error connecting. WirePod will restart and this will return to the first screen of setup."
);
updateAuthel("Waiting for WirePod to restart...");
setTimeout(function () {
checkBLECapability();
}, 3000);
}
});
}
Expand Down Expand Up @@ -447,37 +456,41 @@ function DoAuth() {
authEl.appendChild(document.createElement("br"));
authEl.appendChild(m2);
} else {
updateAuthel("Authentication was successful! How would you like to wake Vector up?");
updateAuthel(
"Authentication was successful! How would you like to wake Vector up?"
);
wakeWithAnim = document.createElement("button");
wakeWithAnim.onclick = function () {
DoOnboard(true)
DoOnboard(true);
};
wakeWithAnim.innerHTML = "Wake with wake-up animation (recommended)";
wakeWithoutAnim = document.createElement("button");
wakeWithoutAnim.innerHTML = "Wake immediately, without wake-up animation";
wakeWithoutAnim.innerHTML =
"Wake immediately, without wake-up animation";
wakeWithoutAnim.onclick = function () {
DoOnboard(false)
DoOnboard(false);
};
authEl.appendChild(wakeWithAnim)
authEl.appendChild(document.createElement("br"))
authEl.appendChild(wakeWithoutAnim)
authEl.appendChild(wakeWithAnim);
authEl.appendChild(document.createElement("br"));
authEl.appendChild(wakeWithoutAnim);
}
});
}

function DoOnboard(wAnim) {
updateAuthel("Onboarding robot...")
fetch("/api-ble/onboard?with_anim=" + wAnim)
.then(() => {
fetch("/api-ble/disconnect");
updateAuthel("Vector is now fully set up! Use the Bot Settings tab to further configure your bot.");
disconnectButtonDiv = document.getElementById("disconnectButton");
disconnectButtonDiv.innerHTML = "";
disconnectButton = document.createElement("button");
disconnectButton.onclick = function () {
checkBLECapability();
};
disconnectButton.innerHTML = "Return to pair instructions";
disconnectButtonDiv.appendChild(disconnectButton);
})
}
updateAuthel("Onboarding robot...");
fetch("/api-ble/onboard?with_anim=" + wAnim).then(() => {
fetch("/api-ble/disconnect");
updateAuthel(
"Vector is now fully set up! Use the Bot Settings tab to further configure your bot."
);
disconnectButtonDiv = document.getElementById("disconnectButton");
disconnectButtonDiv.innerHTML = "";
disconnectButton = document.createElement("button");
disconnectButton.onclick = function () {
checkBLECapability();
};
disconnectButton.innerHTML = "Return to pair instructions";
disconnectButtonDiv.appendChild(disconnectButton);
});
}

0 comments on commit f64099b

Please sign in to comment.