-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathScale.java
More file actions
70 lines (60 loc) · 2.06 KB
/
Copy pathScale.java
File metadata and controls
70 lines (60 loc) · 2.06 KB
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
package com.nighthacking.scales;
import java.util.function.DoublePredicate;
/**
* @author Stephen Chin <[email protected]>
*/
public interface Scale {
/**
* Connect to the scale
*
* @throws IllegalStateException Thrown if the connection can't be opened.
*/
void connect() throws IllegalStateException;
/**
* Gets the last known weight from the scale in grams. If the weight exceeds
* the scale capacity, Double.MAX_VALUE will be returned. If the weight is
* below zero relative to the last tare, either a negative value or
* -Double.MAX_VALUE will be returned.
*
* @return Weight in grams
*/
double getWeight();
/**
* Returns true if the scale is in a stable state. This will use the hardware
* stability if it is supported, otherwise it will compare multiple readings
* to approximate.
*
* @return True if stable, false if still changing
*/
boolean isStable();
/**
* Block until the condition is met (returns true). The value passed in to the
* predicate condition is the scale weight.
*
* @param condition Predicate lambda expression
*/
void waitFor(DoublePredicate condition);
/**
* Block until the condition is met (returns true). The value passed in to the
* predicate condition is the scale weight once a stable state is reached. If
* the scale supports stable monitoring, it will use that capability,
* otherwise this will approximate stability based on multiple readings. Note
* that only positive scale weights are considered stable, so negative,
* overweight, and zero readings will never trigger this condition.
*
* @param condition Predicate lambda expression
*/
void waitForStable(DoublePredicate condition);
/**
* Zero the scale, or throw an exception if programmatic taring is not
* supported.
*
* @throws UnsupportedOperationException Thrown if the scale doesn't support
* programmatic taring
*/
void tare() throws UnsupportedOperationException;
/**
* Close resources that are in use by the scale implementation.
*/
void close();
}