Skip to content

Commit

Permalink
Revert "added timeout feature"
Browse files Browse the repository at this point in the history
This reverts commit 9addc34.
  • Loading branch information
SaintSampo committed Aug 25, 2024
1 parent 9addc34 commit 8eb5a9b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 36 deletions.
8 changes: 4 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@
<div id="toggle-mobile-layout" class="toggle-round"><div class="toggle-nub"></div></div>
</div>

<div class="settings-label help-row">Override axes <br> with WASD</div>
<div class="settings-label">Override axes <br> with WASD</div>

<div class="settings-toggle help-row">
<div class="settings-toggle">
<div id="toggle-keyboard-style" class="toggle-round"><div class="toggle-nub"></div></div>
</div>

<div class="settings-label help-row">Help/Info!</div>
<div class="settings-label">Help/Info!</div>

<div class="settings-toggle help-row">
<div class="settings-toggle">
<div id="toggle-info" class="toggle-round"><div class="toggle-nub"></div></div>
</div>

Expand Down
33 changes: 3 additions & 30 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ let buttonCallback = null

let mobileElements = document.getElementsByClassName("mobile-only");
let desktopElements = document.getElementsByClassName("desktop-only");

let helpRow = document.getElementsByClassName("help-row");

let infoElement = document.getElementById("info-container");
let hackSpacerElement = document.getElementById("hack-spacer");

Expand All @@ -32,8 +29,6 @@ if (localStorage.getItem(toggleMobile.id) == null) {
updateMobileSlider(toggleMobile, false);
}

if(isMobile) for (let element of helpRow) element.style.display = "none";

document.addEventListener('DOMContentLoaded', function () {
updateMobileSlider(toggleMobile, toggleState=false);
updateSlider(toggleKeyboardWASD, toggleState=false);
Expand Down Expand Up @@ -107,7 +102,7 @@ function renderLoop() {
//bytes 0: packet version
//bytes 1-4: axes
//bytes 5-6: button states
//bytes 7-17: pressed keyboard keys
//bytes 7-19: pressed keyboard keys
let rawPacket = new Uint8Array(1 + 4 + 2 + 11)

rawPacket[0] = 0x01; //packet version
Expand Down Expand Up @@ -147,7 +142,7 @@ function renderLoop() {

if (!document.hasFocus()) { rawPacket.fill(0, 0, 20); }

console.log(rawPacket)
//console.log(rawPacket)
bleAgent.attemptSend(rawPacket);
}

Expand Down Expand Up @@ -210,9 +205,9 @@ function createBleAgent() {

await device.addEventListener('gattserverdisconnected', robotDisconnect);

displayBleStatus('Connected', '#4dae50'); //green
isConnectedBLE = true;
buttonBLE.innerHTML = '❌';
batteryWatchdogReset();

} catch (error) {
if (error.name === 'NotFoundError') {
Expand All @@ -228,7 +223,6 @@ function createBleAgent() {
}

function handleBatteryCharacteristic(event){
batteryWatchdogReset();
let value = event.target.value.getUint8(0);
let voltage = (value/255.0) * 12
batteryDisplay.innerHTML = "🔋:" + voltage.toFixed(2) + "V";
Expand All @@ -237,7 +231,6 @@ function createBleAgent() {
async function disconnectBLE() {
displayBleStatus('Disconnecting');
try {
batteryWatchdogStop();
await device.removeEventListener('gattserverdisconnected', robotDisconnect);
await device.gatt.disconnect();

Expand All @@ -253,7 +246,6 @@ function createBleAgent() {
}

function robotDisconnect(event) {
batteryWatchdogStop();
displayBleStatus('Not Connected', 'grey');
isConnectedBLE = false;
connectBLE();
Expand All @@ -269,30 +261,11 @@ function createBleAgent() {
}
}

// Function to create and manage the watchdog timer
let timer;
const timeout = 1000; // 400ms
// Function to start or reset the watchdog timer
function batteryWatchdogReset() {
displayBleStatus('Connected', '#4dae50'); //green
if (timer) {clearTimeout(timer);}
timer = setTimeout(() => {
displayBleStatus('timeout?', 'black');
}, timeout);
}
// Function to stop the watchdog timer
function batteryWatchdogStop() {
batteryWatchdogReset()
if (timer) {clearTimeout(timer);timer = null;}
}

return {
attemptSend: sendPacketBLE
};
}



// -------------------------------------------- mobile --------------------------------------- //

function createMobileAxisAgent() {
Expand Down
6 changes: 4 additions & 2 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ body {
grid-column: 1;
cursor: pointer;
border: none;
color: #e6e5e5;
color: #fff;
text-align: center;
transition: background-color 0.3s, transform 0.1s, box-shadow 0.3s;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
#ble-button:hover {
background-color: rgb(121, 121, 121);
background-color: rgb(169, 169, 169);
}
#ble-button:active {
background-color: rgb(159, 159, 159);
Expand All @@ -155,6 +155,7 @@ body {
font-size: 2vw;
grid-row: 1;
grid-column: 2;
cursor: pointer;
}

#ble-status {
Expand All @@ -163,6 +164,7 @@ body {
grid-row: 2;
grid-column: 1;
grid-column: span 2;
cursor: pointer;
}


Expand Down

0 comments on commit 8eb5a9b

Please sign in to comment.