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
use std::io::{Error, ErrorKind};
pub struct SetPower {
pub power: bool,
}
pub struct ResetUptime {
pub uptime: i32,
}
pub struct CalibrateThermometer {
pub temperature: i32,
}
pub struct Subsystem;
impl Subsystem {
pub fn new() -> Subsystem {
println!("getting new subsystem data");
extern_lib::k_init_device();
Subsystem {}
}
pub fn power(&self) -> Result<bool, Error> {
println!("getting power");
Ok(true)
}
pub fn set_power(&self, _power: bool) -> Result<SetPower, Error> {
println!("Setting power state");
if _power {
Ok(SetPower { power: true })
} else {
Err(Error::new(
ErrorKind::PermissionDenied,
"I'm sorry Dave, I afraid I can't do that",
))
}
}
pub fn uptime(&self) -> Result<i32, Error> {
println!("getting uptime");
Ok(111001)
}
pub fn reset_uptime(&self) -> Result<ResetUptime, Error> {
println!("Resetting uptime");
Ok(ResetUptime { uptime: 0 })
}
pub fn temperature(&self) -> Result<i32, Error> {
println!("getting temperature");
Err(Error::new(
ErrorKind::TimedOut,
"Failed to retrieve temperature",
))
}
pub fn calibrate_thermometer(&self) -> Result<CalibrateThermometer, Error> {
println!("calibrating thermometer");
Ok(CalibrateThermometer { temperature: 98 })
}
}
impl Drop for Subsystem {
fn drop(&mut self) {
println!("Destructing subsystem");
extern_lib::k_terminate_device();
}
}