Skip to content

Commit

Permalink
add download logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Stevie-Ray committed Feb 29, 2024
1 parent a537ae8 commit b821df8
Show file tree
Hide file tree
Showing 18 changed files with 306 additions and 195 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ motherboardButton.addEventListener("click", () => {
// Manually call stop method if stream is continues
// await stop(Motherboard)

// Download data to CSV: format => timestamp, frame, battery, samples, masses
// download()

// Disconnect from device after we are done
disconnect(Motherboard)
})
Expand All @@ -74,25 +77,24 @@ available services with us.

- ✅ Griptonite Motherboard
- ✅ Tindeq Progressor
- Entralpi
- ☑️ Entralpi (not verified)
- ➡️ Climbro
- ➡️ mySmartBoard
- ➡️ MAT Muscle Meter

### Features

- ✅ Connect
- ✅ Disconnect
- ✅ Start data stream (live data)
- ✅ Stop data stream
- ✅ Connect / Disconnect
- ✅ Start / Stop data stream
- ✅ Battery status
- ✅ Read calibration
- ✅ Device info (firmware / serial etc.)
- ✅ Device info: firmware / serial etc.
- ✅ Check if device is connected
- ✅ Peak / Average load
- ✅️ Tare / unladen weight
- ✅️ Download data to CVS
- ➡️ Endurance
- ➡️ Rate of Force Development (RFD)
- ➡️ Rate of Force Development: RFD
- ➡️ Critical Force

## Development
Expand Down
4 changes: 2 additions & 2 deletions examples/chart/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"preview": "vite preview"
},
"dependencies": {
"@hangtime/grip-connect": "^0.2.7",
"chart.js": "^4.4.1"
"@hangtime/grip-connect": "^0.3.0",
"chart.js": "^4.4.2"
},
"devDependencies": {
"typescript": "^5.3.3",
Expand Down
23 changes: 14 additions & 9 deletions examples/chart/src/devices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
battery,
connect,
disconnect,
download,
info,
notify,
stream,
Expand All @@ -29,13 +30,14 @@ export function outputValue(element: HTMLDivElement, data: string) {
}

export function setupDevice(
element: HTMLSelectElement,
stopElement: HTMLButtonElement,
deviceElement: HTMLSelectElement,
tareElement: HTMLButtonElement,
outputElement: HTMLDivElement,
downloadElement: HTMLButtonElement,
stopElement: HTMLButtonElement,
) {
element.addEventListener("change", () => {
const selectedDevice = element.value
// Device
deviceElement.addEventListener("change", () => {
const selectedDevice = deviceElement.value
let device: Device = Motherboard

if (selectedDevice === "climbro") {
Expand All @@ -55,7 +57,6 @@ export function setupDevice(
notify((data: massObject) => {
addData(data.massTotal, data.massMax, data.massAverage)
chartHeight = Number(data.massMax)
outputValue(outputElement, JSON.stringify(data))
})

// read battery + device info
Expand All @@ -74,13 +75,17 @@ export function setupDevice(
}
})
})

// Tare
tareElement.addEventListener("click", async () => {
await tare()
})

// Download
downloadElement.addEventListener("click", async () => {
download()
})
// Stop
stopElement.addEventListener("click", async () => {
const selectedDevice = element.value
const selectedDevice = deviceElement.value

if (selectedDevice === "motherboard") {
await stop(Motherboard)
Expand Down
18 changes: 11 additions & 7 deletions examples/chart/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,35 @@ import { setupChart, setupDevice } from "./devices"

document.querySelector<HTMLDivElement>("#app")!.innerHTML = `
<div>
<h1>Grip Connect</h1>
<h2>Vite + TypeScript example</h2>
<h1>
<a href="https://github.com/Stevie-Ray/hangtime-grip-connect" target="_blank" rel="noreferrer">
Grip Connect
</a>
</h1>
<h2>Web Bluetooth API Force-Sensing strength analysis for climbers</h2>
<canvas class="chart"></canvas>
<div class="card">
<select id="deviceSelect">
<option>Select device</option>
<option value="">Select device</option>
<option value="climbro" disabled>Climbro</option>
<option value="entralpi">Entralpi</option>
<option value="motherboard">Motherboard</option>
<option value="musclemeter" disabled>Muscle Meter</option>
<option value="smartboard" disabled>mySmartBoard</option>
<option value="progressor">Progressor</option>
</select>
<button id="tare">Tare (5sec)</button>
<button id="stop">Stop</button>
<button id="download">Download</button>
</div>
<p class="output"></p>
</div>
`

setupDevice(
document.querySelector<HTMLSelectElement>("#deviceSelect")!,
document.querySelector<HTMLButtonElement>("#stop")!,
document.querySelector<HTMLButtonElement>("#tare")!,
document.querySelector<HTMLDivElement>(".output")!,
document.querySelector<HTMLButtonElement>("#download")!,
document.querySelector<HTMLButtonElement>("#stop")!,
)

setupChart(document.querySelector<HTMLCanvasElement>(".chart")!)
9 changes: 4 additions & 5 deletions examples/chart/src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ h1 {
line-height: 1.1;
}

h1 a {
color: inherit;
}

#app {
max-width: 1280px;
margin: 0 auto;
Expand All @@ -51,11 +55,6 @@ h1 {
padding: 2em;
}

.output {
color: #888;
font-size: 1.25rem;
}

button {
border-radius: 8px;
border: 1px solid transparent;
Expand Down
2 changes: 1 addition & 1 deletion examples/flappy-bird/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"preview": "vite preview"
},
"dependencies": {
"@hangtime/grip-connect": "^0.2.7"
"@hangtime/grip-connect": "^0.3.0"
},
"devDependencies": {
"typescript": "^5.3.3",
Expand Down
7 changes: 4 additions & 3 deletions examples/flappy-bird/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import { setupDevice, setupWeight, setupDifficulty } from "./game"

document.querySelector<HTMLDivElement>("#controller")!.innerHTML += `
<select id="deviceSelect">
<option>Select device</option>
<option value="">Select device</option>
<option value="climbro" disabled>Climbro</option>
<option value="entralpi">Entralpi</option>
<option value="motherboard">Motherboard</option>
<option value="smartboard" disabled>SmartBoard</option>
<option value="progressor" selected>Progressor</option>
<option value="musclemeter" disabled>Muscle Meter</option>
<option value="smartboard" disabled>mySmartBoard</option>
<option value="progressor">Progressor</option>
</select>
<input id="weightInput" placeholder="weight" value="75" type="number">
<select id="difficultySelect">
Expand Down
2 changes: 1 addition & 1 deletion examples/pong/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"preview": "vite preview"
},
"dependencies": {
"@hangtime/grip-connect": "^0.2.7"
"@hangtime/grip-connect": "^0.3.0"
},
"devDependencies": {
"typescript": "^5.3.3",
Expand Down
7 changes: 4 additions & 3 deletions examples/pong/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import { setupDevice, setupWeight, setupDifficulty } from "./game"

document.querySelector<HTMLDivElement>("#controller")!.innerHTML += `
<select id="deviceSelect">
<option>Select device</option>
<option value="">Select device</option>
<option value="climbro" disabled>Climbro</option>
<option value="entralpi">Entralpi</option>
<option value="motherboard">Motherboard</option>
<option value="smartboard" disabled>SmartBoard</option>
<option value="progressor" selected>Progressor</option>
<option value="musclemeter" disabled>Muscle Meter</option>
<option value="smartboard" disabled>mySmartBoard</option>
<option value="progressor">Progressor</option>
</select>
<input id="weightInput" placeholder="weight" value="75" type="number">
<select id="difficultySelect">
Expand Down
Loading

0 comments on commit b821df8

Please sign in to comment.