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
use std::{convert::Infallible, num::NonZeroU32};
use uuid::Uuid;
use crate::{
client::{DeviceBase, HlapiClient, HlapiClientError},
devices::{TankContentInfo, robot::RobotSide},
};
#[derive(Debug, Clone)]
/// The device for the tank operations module
///
/// [OC2 Docs](https://fnuecke.github.io/oc2/manual/en_us/device/tank_operations.html)
pub struct TankOperations {
client: HlapiClient,
uuid: Uuid,
}
impl TankOperations {
/// Tries to take up to the given number of millibuckets from the specified side, defaulting to
/// [`RobotSide::Front`]. Fluids are taken from the world if there is no container to that side.
/// Returns the actual number of millibuckets taken.
pub fn drain(&self, max_count: u32, side: Option<RobotSide>) -> Result<u32, HlapiClientError> {
Ok(self.call("drain", &[&max_count as _, &side as _], &[])?.0)
}
/// Tries to fill the tank to the specified side with the given number of millibuckets,
/// defaulting to [`RobotSide::Front`]. Fluids are drained into the world if there is no tank
/// to that side. Returns the actual number of millibuckets filled.
pub fn fill(&self, count: u32, side: Option<RobotSide>) -> Result<u32, HlapiClientError> {
Ok(self.call("fill", &[&count as _, &side as _], &[])?.0)
}
/// Gets the contents of the given tank in the container to the specified side, defaulting to
/// [`RobotSide::Front`]. Returns [`None`] if the tank is empty.
pub fn get_fluid_in_tank(
&self,
tank: u32,
side: Option<RobotSide>,
) -> Result<Option<TankContentInfo>, HlapiClientError> {
Ok(self
.call("getFluidInTank", &[&tank as _, &side as _], &[])?
.0)
}
/// Gets the number of millibuckets the given tank in the container to the specified side,
/// defaulting to [`RobotSide::Front`], can hold.
pub fn get_fluid_tank_capacity(
&self,
tank: u32,
side: Option<RobotSide>,
) -> Result<u32, HlapiClientError> {
Ok(self
.call("getFluidTankCapacity", &[&tank as _, &side as _], &[])?
.0)
}
/// Gets the number of tanks in the fluid container to the specified side, defaulting to [`RobotSide::Front`].
/// Returns [`None`] if there is no container to that side.
pub fn get_fluid_tank_count(
&self,
side: Option<RobotSide>,
) -> Result<Option<NonZeroU32>, HlapiClientError> {
let raw = self.call("getFluidTankCount", &[&side as _], &[])?.0;
Ok(NonZeroU32::new(raw))
}
/// Moves up to the given number of millibuckets from the container in the selected slot to the
/// robot's internal tank, the actual number of millibuckets moved.
pub fn move_from(&self, max_count: u32) -> Result<u32, HlapiClientError> {
Ok(self.call("moveFrom", &[&max_count as _], &[])?.0)
}
/// Moves up to the given number of millibuckets from the robot's internal tank to the container
/// in the selected slot, returning the actual number of millibuckets moved.
pub fn move_into(&self, max_count: u32) -> Result<u32, HlapiClientError> {
Ok(self.call("moveInto", &[&max_count as _], &[])?.0)
}
}
impl DeviceBase for TankOperations {
const TYPE: &'static str = "tank_operations";
type Event = Infallible;
fn new(client: HlapiClient, uuid: Uuid) -> Result<Self, HlapiClientError> {
Ok(Self { client, uuid })
}
fn uuid_base(&self) -> Uuid {
self.uuid
}
fn client(&self) -> &HlapiClient {
&self.client
}
}