# Copyright (C) MatrixEditor 2023## This program is free software: you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation, either version 3 of the License, or# (at your option) any later version.## This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with this program. If not, see <https://www.gnu.org/licenses/>.importenumfromtypingimportListfromcaterpillar.modelimportstructfromcaterpillar.shortcutsimportctx,F,this,LittleEndianfromcaterpillar.fieldsimportuint8,Enum,uint32from.advertiseimportProtocolVersionfrom.modelimportcharacteristic,DeviceState,Pressurefrom.modelimportCH_BRUSHING_MODE,CH_BRUSHING_TIMEfrom.modelimportCH_QUADRANT,CH_DEVICE_ID,CH_DEVICE_INFOfrom.modelimportCH_BRUSH_MODESclassBrushType(enum.IntEnum):__struct__=uint8UNKNOWN=153EXPERIMENTAL=255D36_EXPERIMENTAL=63D36_X_MODE=0D36_6_MODE=1D36_5_MODE=2D21_EXPERIMENTAL=127D21_X_MODE=64D21_4_MODE=65D21_3_MODE=66D21_3_MODE_WHITENING=69D21_2A_MODE=67D21_2B_MODE=68D21_1_MODE=70D706_X_MODE=112D706_6_MODE=113D706_5_MODE=114D706_X_MODE_CHINA=117D706_6_MODE_CHINA=118D706_5_MODE_CHINA=119D701_X_MODE=32D701_6_MODE=33D701_5_MODE=34D700_5_MODE=39D700_4_MODE=40D700_6_MODE=41D601_X_MODE=80D601_5_MODE=81D601_4_MODE=82D601_3A_MODE=83D601_2A_MODE=84D601_2B_MODE=85D601_3B_MODE=86D601_1_MODE=87SONOS_X_MODE=48SONOS=49# SONOS IOSONOS_BIG_TI=50# SONOS IO (BIG TI)SONOS_G4=52# SONOS GALAXY (IO 4)SONOS_G5=53# SONOS GALAXY (IO 5)SONOS_EPLATFORM=54classBrushStatus(enum.IntEnum):__struct__=uint8UNKNOWN=0xFFNOT_CONNECTED=0PRE_RUN=1IDLE=2CHARGING=3RUN=4# the following codes were taken from# https://github.com/wise86-android/OralBlue_python/blob/master/OralBlue/BrushState.pySETUP=0x05FLIGHT_MENU=0x06FINAL_TEST=0x71PCB_TEST=0x72SLEEP=0x73TRANSPORT=0x74classMode(enum.IntEnum):__struct__=uint8UNKNOWN=0xFFOFF=0DAILY_CLEAN=1SENSITIVE=2MASSAGE=3WHITENING=4DEEP_CLEAN=5TONGUE_CLEAN=6PRO_CLEAN=7classV006Mode(enum.IntEnum):__struct__=uint8UNKNOWN=0xFFV006_CLEAN=0V006_SOFT=1V006_MASSAGE=2V006_POLISH=3V006_TURBO=4V006_SOFT_PLUS=5V006_TONGUE=6V006_OFF=7V006_SETTINGS=8classQuadrant(enum.IntEnum):__struct__=uint8UNKNOWN=0xFEFIRST_QUADRANT=0SECOND_QUADRANT=1THIRD_QUADRANT=2FOURTH_QUADRANT=3FIFTH_QUADRANT=4SIXTH_QUADRANT=5SEVENTH_QUADRANT=6EIGHTH_QUADRANT=7LAST_QUADRANT=0xFFNO_QUADRANTS_DEFINED=0xF0@characteristic(CH_BRUSHING_TIME,"brushing_time")@struct(kw_only=False)classBrushingTime:minutes:uint8seconds:uint8def_brush_mode_fn(value,context):ifvalue>=6orvalue==0:returnF(Enum(V006Mode,uint8))returnF(Enum(Mode,uint8))@characteristic(CH_BRUSHING_MODE,"brushing_mode")@struct(kw_only=False)classBrushingMode:mode:F(ctx._root.protocol)>>_brush_mode_fn@characteristic(CH_QUADRANT,"toothbrush_quadrant")@struct(kw_only=False)classToothbrushQuadrant:quadrant:Quadrantnum_quadrants:uint8@characteristic(CH_BRUSH_MODES,"brush_modes")@struct(kw_only=False)classBrushModes:modes:uint8[8]defget_modes(self)->List[Mode]:returnlist(map(Mode,self.modes))@characteristic(CH_DEVICE_INFO,"brush_info")@struct(kw_only=False)classBrushInfo:type:BrushTypeprotocol:ProtocolVersionversion:uint8@characteristic(CH_DEVICE_ID,"brush_id")@struct(kw_only=False,order=LittleEndian)classBrushID:id:uint32def_brush_status_fn(value:ProtocolVersion,context):ifvalue<=5:# An advertisement before V006 contains# the current pressure state.returnEnum(Pressure.State,uint8)returnEnum(BrushStatus,uint8)
[docs]@structclassBrushAdvertisement:"""Bluetooth Low Energy advertise sent from oral-b devices."""#: The used protocol version. Note that the packet structure#: may change according to the version configurationprotocol:ProtocolVersion#: the device type (this value conforms to a model identifier#: and is not the model name)type:BrushType#: the current firmware versionversion:uint8#: Describes the current state of the device.state:DeviceState.State#: In packets using protocol version below V006, this value#: describes the current pressure measurement. Otherwise,#: another device status is set.status:F(this.protocol)>>_brush_status_fn#: Defines the current brushing time in minutesbrush_time_min:uint8#: Defines the current brushing time in secondsbrush_time_sec:uint8#: Specifies the currently used brushing mode. The used enumeration#: varies based on the current protocol version.brush_mode:F(this.protocol)>>_brush_mode_fn#: This field displays the current brushing progress (no real#: use-case?)brush_progress:uint8#: describes, which quadrant is currently processed (only during#: a brushing session)quadrant_completion:Quadrant#: This fields specifies either the amount of quadrants or (only in#: V008) a device substate.total_quadrants:uint8