Source code for brainaccess.core.charging_settings
import ctypes
from brainaccess.utils.exceptions import BrainAccessException
[docs]
class ChargingSettings(ctypes.Structure):
"""Charging behavior settings of a headset.
Read with
:meth:`~brainaccess.core.eeg_manager.EEGManager.get_charging_settings` and
change with
:meth:`~brainaccess.core.eeg_manager.EEGManager.set_charging_settings`.
Parameters
----------
enabled_on_while_charging : bool, optional
Keep the headset on while a charger is connected. Default ``False``. For
development only, see the warning below.
sleep_timeout : int, optional
Minutes of inactivity after which the headset goes to sleep, 0 to 255
(default 1). The headset treats 0 as 1.
Raises
------
BrainAccessException
If ``sleep_timeout`` is outside 0 to 255.
Warning
-------
Use ``enabled_on_while_charging`` for development only, never in normal use.
Never record from a person while the headset is connected to a charger. The
setting must be enabled before the charger is plugged in; otherwise the
headset disconnects when charging starts.
Examples
--------
>>> ChargingSettings(enabled_on_while_charging=False, sleep_timeout=15)
ChargingSettings(enabled_on_while_charging=False, sleep_timeout=15)
"""
_fields_ = [
("_enabled_on_while_charging", ctypes.c_bool),
("_sleep_timeout", ctypes.c_uint8),
]
def __init__(
self,
enabled_on_while_charging: bool = False,
sleep_timeout: int = 1,
) -> None:
if not 0 <= int(sleep_timeout) <= 255:
raise BrainAccessException("sleep_timeout must be in 0..255 minutes")
super().__init__(bool(enabled_on_while_charging), int(sleep_timeout))
@property
[docs]
def sleep_timeout(self) -> int:
"""Minutes of inactivity after which the headset goes to sleep (0 to 255).
Raises
------
BrainAccessException
When set to a value outside 0 to 255.
"""
return self._sleep_timeout
@sleep_timeout.setter
def sleep_timeout(self, value: int) -> None:
if not 0 <= int(value) <= 255:
raise BrainAccessException("sleep_timeout must be in 0..255 minutes")
self._sleep_timeout = int(value)
@property
[docs]
def enabled_on_while_charging(self) -> bool:
"""Whether the headset stays on while a charger is connected.
With ``False`` (the default) the headset disconnects and stops
advertising while it charges.
Warning
-------
For development only; see :class:`ChargingSettings`.
"""
return self._enabled_on_while_charging
@enabled_on_while_charging.setter
def enabled_on_while_charging(self, value: bool) -> None:
self._enabled_on_while_charging = bool(value)
def __repr__(self) -> str:
return (
f"{type(self).__name__}("
f"enabled_on_while_charging={self.enabled_on_while_charging}, "
f"sleep_timeout={self.sleep_timeout})"
)