Skip to content

Commit

Permalink
feat: add support for new firmware (#34)
Browse files Browse the repository at this point in the history
* feat: add support for new firmware

* chore: bump version
  • Loading branch information
beeb authored Dec 10, 2023
1 parent c6fbd8f commit 5a05210
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "coffee-scale-app",
"version": "2.0.4",
"version": "2.1.0",
"private": true,
"scripts": {
"dev": "vite dev",
Expand Down
14 changes: 7 additions & 7 deletions pnpm-lock.yaml

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

26 changes: 21 additions & 5 deletions src/lib/bt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ export async function connectBt() {
return
}
const device = await navigator.bluetooth.requestDevice({
filters: [{ name: 'mpy-coffee' }, { services: [parseInt('0x1815'), parseInt('0x180F')] }],
filters: [
{ name: 'mpy-coffee' },
{ name: 'coffee-scale' },
{ services: [parseInt('0x180F'), parseInt('0x1815')] }, // python firmware
{ services: [parseInt('0x180F'), parseInt('0x181D')] }, // rust firmware
],
})
device.addEventListener('gattserverdisconnected', () => {
btConnected.set(false)
Expand All @@ -46,10 +51,21 @@ export async function connectBt() {
const server = await device.gatt?.connect()
btConnected.set(true)
btServer.set(server ?? null)
const service = await server?.getPrimaryService(parseInt('0x1815'))
weightCharacteristic = (await service?.getCharacteristic(parseInt('0x2A59'))) ?? null
await weightCharacteristic?.startNotifications()
weightCharacteristic?.addEventListener('characteristicvaluechanged', onWeightUpdate)

try {
// python firmware
const service = await server?.getPrimaryService(parseInt('0x1815'))
weightCharacteristic = (await service?.getCharacteristic(parseInt('0x2A59'))) ?? null
await weightCharacteristic?.startNotifications()
weightCharacteristic?.addEventListener('characteristicvaluechanged', onWeightUpdate)
} catch {
// rust firmware
const service = await server?.getPrimaryService(parseInt('0x181D'))
weightCharacteristic = (await service?.getCharacteristic(parseInt('0x2A9D'))) ?? null
await weightCharacteristic?.startNotifications()
weightCharacteristic?.addEventListener('characteristicvaluechanged', onWeightUpdate)
}

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

0 comments on commit 5a05210

Please sign in to comment.