|
1 | 1 | //! Device struct and methods |
2 | | -use core::ops::DerefMut; |
3 | | - |
4 | 2 | use embassy_sync::mutex::Mutex; |
5 | 3 |
|
6 | | -use super::{DeviceId, Error, action}; |
| 4 | +use super::{DeviceId, Error}; |
7 | 5 | use crate::power::policy::policy::EventReceiver; |
8 | 6 | use crate::power::policy::{ConsumerPowerCapability, ProviderPowerCapability}; |
9 | 7 | use crate::sync::Lockable; |
@@ -52,7 +50,7 @@ impl State { |
52 | 50 | /// Internal device state for power policy |
53 | 51 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
54 | 52 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
55 | | -struct InternalState { |
| 53 | +pub struct InternalState { |
56 | 54 | /// Current state of the device |
57 | 55 | pub state: State, |
58 | 56 | /// Current consumer capability |
@@ -131,7 +129,7 @@ where |
131 | 129 | /// Device ID |
132 | 130 | id: DeviceId, |
133 | 131 | /// Current state of the device |
134 | | - state: Mutex<GlobalRawMutex, InternalState>, |
| 132 | + pub state: Mutex<GlobalRawMutex, InternalState>, |
135 | 133 | /// Reference to hardware |
136 | 134 | pub device: &'a C, |
137 | 135 | /// Event receiver |
@@ -194,40 +192,6 @@ where |
194 | 192 | pub async fn is_provider(&self) -> bool { |
195 | 193 | self.state().await.kind() == StateKind::ConnectedProvider |
196 | 194 | } |
197 | | - |
198 | | - /// Internal function to set device state |
199 | | - pub(super) async fn set_state(&self, new_state: State) { |
200 | | - let mut lock = self.state.lock().await; |
201 | | - let state = lock.deref_mut(); |
202 | | - state.state = new_state; |
203 | | - } |
204 | | - |
205 | | - /// Try to provide access to the policy actions for the given state |
206 | | - /// Implemented here for lifetime reasons |
207 | | - pub(super) async fn try_policy_action<S: action::Kind>( |
208 | | - &self, |
209 | | - ) -> Result<action::policy::Policy<'_, C, R, S>, Error> { |
210 | | - let state = self.state().await.kind(); |
211 | | - if S::kind() != state { |
212 | | - return Err(Error::InvalidState(S::kind(), state)); |
213 | | - } |
214 | | - Ok(action::policy::Policy::new(self)) |
215 | | - } |
216 | | - |
217 | | - /// Provide access to the current policy actions |
218 | | - /// Implemented here for lifetime reasons |
219 | | - pub(super) async fn policy_action(&self) -> action::policy::AnyState<'_, C, R> { |
220 | | - match self.state().await.kind() { |
221 | | - StateKind::Detached => action::policy::AnyState::Detached(action::policy::Policy::new(self)), |
222 | | - StateKind::Idle => action::policy::AnyState::Idle(action::policy::Policy::new(self)), |
223 | | - StateKind::ConnectedProvider => { |
224 | | - action::policy::AnyState::ConnectedProvider(action::policy::Policy::new(self)) |
225 | | - } |
226 | | - StateKind::ConnectedConsumer => { |
227 | | - action::policy::AnyState::ConnectedConsumer(action::policy::Policy::new(self)) |
228 | | - } |
229 | | - } |
230 | | - } |
231 | 195 | } |
232 | 196 |
|
233 | 197 | impl<C: Lockable, R: EventReceiver> intrusive_list::NodeContainer for Device<'static, C, R> |
|
0 commit comments