Skip to content

Commit

Permalink
fix: use i32 for new firmware (#35)
Browse files Browse the repository at this point in the history
* fix: use i32 for new firmware

* chore: bump patch number
  • Loading branch information
beeb authored Dec 15, 2023
1 parent 5a05210 commit 1ec6270
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 42 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "coffee-scale-app",
"version": "2.1.0",
"version": "2.1.1",
"private": true,
"scripts": {
"dev": "vite dev",
Expand All @@ -13,14 +13,14 @@
},
"devDependencies": {
"@biomejs/biome": "^1.4.1",
"@iconify-json/mingcute": "^1.1.13",
"@iconify-json/mingcute": "^1.1.14",
"@macfja/svelte-persistent-store": "^2.4.1",
"@sveltejs/adapter-static": "^2.0.3",
"@sveltejs/kit": "^1.27.7",
"@sveltejs/kit": "^1.30.3",
"@types/web-bluetooth": "^0.0.20",
"autoprefixer": "^10.4.16",
"chart.js": "^4.4.1",
"daisyui": "^4.4.19",
"daisyui": "^4.4.20",
"postcss": "^8.4.32",
"svelte": "^4.2.8",
"svelte-check": "^3.6.2",
Expand Down
66 changes: 33 additions & 33 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions src/lib/bt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import { get } from 'svelte/store'
import { batteryLevel, btConnected, btEnabled, btServer, currentWeight, recordWeight, wakeLock } from './stores'

let weightCharacteristic: BluetoothRemoteGATTCharacteristic | null = null
let newFirmware = false

async function onWeightUpdate(event: Event) {
if (event.target === null) {
return
}
const value = (event.target as BluetoothRemoteGATTCharacteristic).value?.getInt16(0, false) ?? 0
const dataView = (event.target as BluetoothRemoteGATTCharacteristic).value
const value = (newFirmware ? dataView?.getInt32(0, false) : dataView?.getInt16(0, false)) ?? 0
currentWeight.set(value / 100.0)
await recordWeight()
}
Expand Down Expand Up @@ -56,15 +58,15 @@ export async function connectBt() {
// python firmware
const service = await server?.getPrimaryService(parseInt('0x1815'))
weightCharacteristic = (await service?.getCharacteristic(parseInt('0x2A59'))) ?? null
await weightCharacteristic?.startNotifications()
weightCharacteristic?.addEventListener('characteristicvaluechanged', onWeightUpdate)
newFirmware = false
} catch {
// rust firmware
const service = await server?.getPrimaryService(parseInt('0x181D'))
weightCharacteristic = (await service?.getCharacteristic(parseInt('0x2A9D'))) ?? null
await weightCharacteristic?.startNotifications()
weightCharacteristic?.addEventListener('characteristicvaluechanged', onWeightUpdate)
newFirmware = true
}
await weightCharacteristic?.startNotifications()
weightCharacteristic?.addEventListener('characteristicvaluechanged', onWeightUpdate)

await readBatteryLevel()
if ('wakeLock' in navigator) {
Expand Down

0 comments on commit 1ec6270

Please sign in to comment.