Repository navigation
Expand file tree
/
Copy pathtypes.ts
More file actions
182 lines (166 loc) · 5.63 KB
/
Copy pathtypes.ts
File metadata and controls
182 lines (166 loc) · 5.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// Oral-B BLE protocol — shared types. Framework-agnostic; safe to lift into any project.
/** A completed brushing session decoded from the DATA history characteristic. */
export interface Session {
/** Device time (seconds since 2000-01-01Z). Stable per session — used as the storage key. */
timestamp: number;
/** Session start as a JS Date. */
startTime: Date;
/** Session length in seconds. */
duration: number;
/** Internal event counter. */
eventCount: number;
/** Raw brushing-mode byte. */
modeCode: number;
/** Resolved mode name (e.g. "daily-clean"). */
mode: ModeName;
/** Seconds spent pressing too hard. */
timeUnderPressure: number;
/** Count of over-pressure warnings. */
pressureWarnings: number;
/** Battery % at session end. */
finalBatteryState: number;
/** Present when the record encodes a charge time instead of packed metadata. */
lastFullCharge?: Date;
/** Configured target time (seconds), when present. */
totalTargetTime?: number;
/** Sector metadata (0-7), when present. */
sector?: number;
/** Device-assigned session id, when present. */
sessionID?: number;
/** Device-assigned user id, when present. */
userID?: number;
// --- iO (V007) rich metrics; all optional, absent on older gen. ---
/** Seconds spent in the high-pressure zone (iO). Mirrors timeUnderPressure. */
highPressureTime?: number;
/** Seconds spent in the low-pressure zone (iO). */
lowPressureTime?: number;
/** Average brushing force in Newtons (iO). */
avgPressure?: number;
/** Peak brushing force in Newtons (iO). */
maxPressure?: number;
/** Count of high-pressure events (iO). */
highPressureEvents?: number;
/** Count of low-pressure events (iO). */
lowPressureEvents?: number;
/** Count of motor on/off events (iO). */
onEvents?: number;
/** Number of configured sectors for this session (iO). */
sectorCount?: number;
/**
* Which physical brush this session came from (the Web Bluetooth origin-scoped device id).
* App-level, stamped at persist time — enables multiple devices in one app later. Undefined
* on legacy rows until the next sync backfills them (key is still `timestamp` for now; a
* composite `[deviceId, timestamp]` key is the migration step when real multi-device lands).
*
* NB for future "who brushed" attribution: `userID` above already distinguishes household
* members on a shared iO base (the device tags each session with a user slot) — so a person
* is (deviceId, userID). See docs/HANDOFF.md backlog.
*/
deviceId?: string;
/** App-level marker (not from the device): this is generated demo data, purge-on-real-sync. */
sample?: boolean;
}
export interface DeviceStateInfo {
state: string;
stateCode: number;
transportMode: boolean;
deactivateTimer: boolean;
}
export type RefillState = 'on' | 'reset' | 'snooze' | 'interval' | 'off' | 'stage' | 'unknown';
/** Brush-head replacement status, read from the iO's RefillReminder characteristic (ff2d). */
export interface BrushHead {
/** Raw reminder-state byte. */
stateCode: number;
state: RefillState;
/** Days until replacement is recommended (device-tracked countdown). */
daysLeft: number;
/** Brushing time (seconds) left before replacement. */
brushingSecondsLeft: number;
/** Days elapsed since the reminder fired (0 until due). */
daysSinceReminder: number;
/** Brushing seconds elapsed since the reminder fired. */
secondsSinceReminder: number;
}
export interface PressureInfo {
highPressure: boolean;
motorSpeedReduced: boolean;
raw: number;
/** iO only: continuous force reading (uint16). Absent on older 1-byte pressure. */
value?: number;
/** iO only: device-reported pressure zone (0/1 = ok, 2 = too hard). */
zone?: number;
}
export interface ButtonInfo {
powerButton: boolean;
modeButton: boolean;
}
export interface ModeInfo {
code: number;
name: ModeName;
}
export interface DeviceInfo {
modelId: number;
protocolVersion?: number;
firmwareVersion?: number;
battery?: number;
name?: string;
/** Web Bluetooth origin-scoped device id — stable per browser, used to attribute sessions. */
deviceId?: string;
}
/**
* Live brush state merged from notify characteristics during an active connection.
* Any field may be undefined if its characteristic is absent on this model.
*/
export interface LiveState {
device?: DeviceStateInfo;
/** Elapsed seconds this session. */
time?: number;
mode?: ModeInfo;
/** Current sector/quadrant index. */
sector?: number;
pressure?: PressureInfo;
button?: ButtonInfo;
battery?: number;
smiley?: number;
/** Wall-clock ms of the last update (client side). */
updatedAt: number;
}
/** One characteristic found during a GATT discovery walk. */
export interface DiscoveredCharacteristic {
uuid: string;
/** e.g. ['read','notify']. */
properties: string[];
/** Hex of the read value, if the characteristic was readable. */
valueHex?: string;
/** Error message if a read was attempted and failed. */
readError?: string;
}
/** One service (and its characteristics) found during discovery. */
export interface DiscoveredService {
uuid: string;
/** True if this matches a UUID we already understand. */
known: boolean;
characteristics: DiscoveredCharacteristic[];
}
/** A raw notification frame, surfaced for reverse-engineering. */
export interface RawFrame {
uuid: string;
hex: string;
at: number;
}
export type ModeName =
| 'off'
| 'daily-clean'
| 'sensitive'
| 'massage'
| 'whitening'
| 'deep-clean'
| 'tongue-cleaning'
| 'turbo'
// iO-specific modes:
| 'intense'
| 'super-sensitive'
| 'smart-adapt'
| 'gentle-white'
| 'settings'
| 'unknown';