Skip to main content

storz_rs/
device.rs

1use std::fmt;
2
3/// Supported Storz & Bickel device models.
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5pub enum DeviceModel {
6    VolcanoHybrid,
7    Venty,
8    Veazy,
9    Crafty,
10}
11
12impl fmt::Display for DeviceModel {
13    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14        match self {
15            DeviceModel::VolcanoHybrid => write!(f, "Volcano Hybrid"),
16            DeviceModel::Venty => write!(f, "Venty"),
17            DeviceModel::Veazy => write!(f, "Veazy"),
18            DeviceModel::Crafty => write!(f, "Crafty"),
19        }
20    }
21}
22
23/// Heater mode for Venty/Veazy devices.
24#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
25pub enum HeaterMode {
26    /// Heater off
27    Off = 0,
28    /// Normal heating
29    Normal = 1,
30    /// Boost mode
31    Boost = 2,
32    /// Superboost mode
33    SuperBoost = 3,
34}
35
36impl fmt::Display for HeaterMode {
37    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
38        match self {
39            HeaterMode::Off => write!(f, "off"),
40            HeaterMode::Normal => write!(f, "normal"),
41            HeaterMode::Boost => write!(f, "boost"),
42            HeaterMode::SuperBoost => write!(f, "superboost"),
43        }
44    }
45}
46
47impl HeaterMode {
48    /// Parse from raw byte value.
49    pub fn from_u8(val: u8) -> Self {
50        match val {
51            1 => HeaterMode::Normal,
52            2 => HeaterMode::Boost,
53            3 => HeaterMode::SuperBoost,
54            _ => HeaterMode::Off,
55        }
56    }
57}
58
59/// Current state snapshot of a vaporizer device.
60#[derive(Debug, Clone, PartialEq, Default)]
61pub struct DeviceState {
62    /// Current measured temperature in Celsius.
63    pub current_temp: Option<f32>,
64    /// Target temperature in Celsius.
65    pub target_temp: Option<f32>,
66    /// Boost temperature offset in Celsius (Venty/Veazy).
67    pub boost_temp: Option<f32>,
68    /// Superboost temperature offset in Celsius (Venty/Veazy).
69    pub super_boost_temp: Option<f32>,
70    /// Heater mode (Venty/Veazy).
71    pub heater_mode: Option<HeaterMode>,
72    /// Heater is active.
73    pub heater_on: bool,
74    /// Pump is active (Volcano only).
75    pub pump_on: bool,
76    /// Fan is active (Volcano only).
77    pub fan_on: bool,
78    /// Target temperature has been reached.
79    pub setpoint_reached: bool,
80    /// Raw activity flags (Volcano).
81    pub raw_activity: Option<u32>,
82    /// Device settings (Venty/Veazy).
83    pub settings: Option<DeviceSettings>,
84}
85
86impl fmt::Display for DeviceState {
87    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
88        write!(
89            f,
90            "State(heater={}, pump={}, fan={}, current={:?}°C, target={:?}°C)",
91            self.heater_on, self.pump_on, self.fan_on, self.current_temp, self.target_temp
92        )
93    }
94}
95
96/// Device settings (Venty/Veazy).
97#[derive(Debug, Clone, PartialEq, Default)]
98pub struct DeviceSettings {
99    /// Temperature unit: true = Celsius, false = Fahrenheit
100    pub is_celsius: bool,
101    /// Setpoint reached flag
102    pub setpoint_reached: bool,
103    /// Boost visualization enabled
104    pub boost_visualization: bool,
105    /// Charge current optimization
106    pub charge_current_optimization: bool,
107    /// Charge voltage limit enabled
108    pub charge_voltage_limit: bool,
109    /// Permanent Bluetooth enabled
110    pub permanent_bluetooth: bool,
111    /// Vibration enabled
112    pub vibration: bool,
113    /// Auto shutdown timer in seconds
114    pub auto_shutdown_seconds: Option<u16>,
115    /// Battery level 0-100
116    pub battery_level: Option<u8>,
117    /// Is charging
118    pub is_charging: bool,
119}
120
121/// Device information (serial number, firmware, etc.).
122#[derive(Debug, Clone, PartialEq, Default)]
123pub struct DeviceInfo {
124    /// Serial number string.
125    pub serial_number: Option<String>,
126    /// Firmware version string.
127    pub firmware_version: Option<String>,
128    /// BLE firmware version string.
129    pub firmware_ble_version: Option<String>,
130    /// Color index (Venty/Veazy).
131    pub color_index: Option<u8>,
132    /// Total heater runtime in minutes.
133    pub heater_runtime_minutes: Option<u32>,
134    /// Total battery charging time in minutes.
135    pub battery_charging_time_minutes: Option<u32>,
136    /// Hours of heating (Volcano).
137    pub hours_of_heating: Option<u16>,
138    /// Minutes of heating (Volcano).
139    pub minutes_of_heating: Option<u16>,
140}
141
142/// Bitmask flags from the Volcano activity characteristic.
143pub mod volcano_flags {
144    pub const HEATER_ENABLED: u16 = 0x0020;
145    pub const FAN_ENABLED: u16 = 0x0400;
146    pub const AUTO_SHUTDOWN: u16 = 0x0200;
147    pub const PUMP_ENABLED: u16 = 0x2000;
148    pub const DISPLAY_ON_COOLING: u16 = 0x1000;
149    pub const FAHRENHEIT_ENA: u16 = 0x0200;
150}
151
152/// Bitmask flags for the Volcano vibration characteristic.
153pub mod volcano_vibration_flags {
154    pub const VIBRATION: u32 = 0x0400;
155}