-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimopt.go
More file actions
61 lines (54 loc) · 1.53 KB
/
Copy pathsimopt.go
File metadata and controls
61 lines (54 loc) · 1.53 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
package lift
import (
"errors"
"fmt"
"time"
)
// SimOption are option functions for simulated lifts.
type SimOption func(*liftSim) error
// NumFloors sets the number of floors in simulated lift.
func NumFloors(floors int) SimOption {
return func(l *liftSim) error {
if floors < 2 || floors > 9 {
return errors.New("number of floors must be between 2 and 9")
}
l.NumFloors = floors
return nil
}
}
// TravelTimeBetweenFloors sets the travel time between each floor.
func TravelTimeBetweenFloors(d time.Duration) SimOption {
return func(l *liftSim) error {
ms := d.Nanoseconds() * 1000 * 1000
l.TravelTimeBetweenFloors = int(ms)
return nil
}
}
// TravelTimePassingFloors sets the time spent within the sensors range when passing a floor.
func TravelTimePassingFloors(d time.Duration) SimOption {
return func(l *liftSim) error {
ms := d.Nanoseconds() * 1000 * 1000
l.TravelTimePassingFloors = int(ms)
return nil
}
}
// BtnDepressedTime sets the duration a button will be considered pressed after the actual
// key event happens.
func BtnDepressedTime(d time.Duration) SimOption {
return func(l *liftSim) error {
ms := d.Nanoseconds() * 1000 * 1000
l.BtnDepressedTime = int(ms)
return nil
}
}
// ComPort sets what port the simulator should listen on. This must be unique per
// instance of simulators. Must be in the range 1024 - 65535.
func ComPort(port int) SimOption {
return func(l *liftSim) error {
if port < 1024 || port > 65535 {
return fmt.Errorf("illegal port: %d", port)
}
l.ComPort = port
return nil
}
}