Skip to content

Commit

Permalink
chore: update dependencies (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
beeb authored Feb 4, 2024
1 parent 3ee80e7 commit 91fef10
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 33 deletions.
12 changes: 6 additions & 6 deletions flake.lock

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

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "coffee-scale-app",
"version": "2.1.3",
"version": "2.2.0",
"license": "MIT",
"private": true,
"scripts": {
Expand All @@ -14,7 +14,7 @@
},
"devDependencies": {
"@biomejs/biome": "^1.5.3",
"@iconify-json/mingcute": "^1.1.15",
"@iconify-json/mingcute": "^1.1.16",
"@macfja/svelte-persistent-store": "^2.4.1",
"@sveltejs/adapter-static": "^3.0.1",
"@sveltejs/kit": "^2.5.0",
Expand All @@ -30,7 +30,7 @@
"tailwindcss": "^3.4.1",
"tslib": "^2.6.2",
"typescript": "^5.3.3",
"unplugin-icons": "^0.18.3",
"unplugin-icons": "^0.18.4",
"vite": "^5.0.12"
},
"type": "module",
Expand Down
49 changes: 25 additions & 24 deletions pnpm-lock.yaml

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

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

let weightCharacteristic: BluetoothRemoteGATTCharacteristic | null = null

// check if the scale is using the new rust firmware which uses a int32 for the weight
let newFirmware = false

async function onWeightUpdate(event: Event) {
if (event.target === null) {
return
}
const dataView = (event.target as BluetoothRemoteGATTCharacteristic).value
// get the value as a int16 or int32 depending on the firmware
const value = (newFirmware ? dataView?.getInt32(0, false) : dataView?.getInt16(0, false)) ?? 0
currentWeight.set(value / 100.0)
await recordWeight()
Expand Down Expand Up @@ -37,6 +40,10 @@ export async function connectBt() {
if (!browser) {
return
}
// Support both the old python firmware (with device name `mpy-coffe`) and the new rust firmware (with device name
// `coffee-scale`.
// The new firmware uses a more appropriate service and characteristic UUIDs, so we can use those to identify the
// firmware version.
const device = await navigator.bluetooth.requestDevice({
filters: [
{ name: 'mpy-coffee' },
Expand All @@ -54,6 +61,7 @@ export async function connectBt() {
btConnected.set(true)
btServer.set(server ?? null)

// Detect firmware version
try {
// python firmware
const service = await server?.getPrimaryService(parseInt('0x1815'))
Expand All @@ -69,6 +77,7 @@ export async function connectBt() {
weightCharacteristic?.addEventListener('characteristicvaluechanged', onWeightUpdate)

await readBatteryLevel()
// Request a wake lock to keep the screen on while the scale is connected
if ('wakeLock' in navigator) {
try {
wakeLock.set(await navigator.wakeLock.request('screen'))
Expand Down

0 comments on commit 91fef10

Please sign in to comment.