-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample_test.go
More file actions
117 lines (99 loc) · 2 KB
/
example_test.go
File metadata and controls
117 lines (99 loc) · 2 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
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
117
package rtc_test
import (
"fmt"
"time"
"github.com/cleroux/rtc"
)
func ExampleNewTicker() {
ticker, err := rtc.NewTicker("/dev/rtc", 2)
if err != nil {
panic(err)
}
defer ticker.Stop()
for tick := range ticker.C {
fmt.Printf("Tick. Frame:%d Time:%v Delta:%v Missed:%d\n", tick.Frame, tick.Time, tick.Delta, tick.Missed)
}
}
func ExampleNewTimer() {
timer, err := rtc.NewTimer("/dev/rtc", time.Minute)
if err != nil {
panic(err)
}
defer timer.Stop()
alarm := <-timer.C
fmt.Printf("Alarm. Time:%v\n", alarm.Time)
}
func ExampleRTC() {
clock, err := rtc.NewRTC("/dev/rtc")
if err != nil {
panic(err)
}
defer clock.Close()
t, err := clock.GetTime()
if err != nil {
panic(err)
}
fmt.Printf("Current RTC Time: %v\n", t)
}
func ExampleGetClocks() {
clocks, err := rtc.GetClocks()
if err != nil {
panic(err)
}
for _, clock := range clocks {
fmt.Printf("Clock found: %s\n", clock)
}
}
func ExampleGetTime() {
t, err := rtc.GetTime("/dev/rtc")
if err != nil {
panic(err)
}
fmt.Printf("Current time: %v\n", t)
}
func ExampleSetTime() {
if err := rtc.SetTime("/dev/rtc", time.Now()); err != nil {
panic(err)
}
}
func ExampleGetEpoch() {
epoch, err := rtc.GetEpoch("/dev/rtc")
if err != nil {
panic(err)
}
fmt.Printf("Current epoch: %d\n", epoch)
}
func ExampleSetEpoch() {
if err := rtc.SetEpoch("/dev/rtc", 99); err != nil {
panic(err)
}
}
func ExampleGetAlarm() {
t, err := rtc.GetAlarm("/dev/rtc")
if err != nil {
panic(err)
}
fmt.Printf("Current alarm time: %v\n", t)
}
func ExampleSetAlarm() {
if err := rtc.SetAlarm("/dev/rtc", time.Now().Add(time.Minute)); err != nil {
panic(err)
}
}
func ExampleSetAlarmInterrupt() {
if err := rtc.SetAlarmInterrupt("/dev/rtc", true); err != nil {
panic(err)
}
}
func ExampleGetFrequency() {
frequency, err := rtc.GetFrequency("/dev/rtc")
if err != nil {
panic(err)
}
fmt.Printf("Frequency: %d\n", frequency)
}
func ExampleSetFrequency() {
if err := rtc.SetFrequency("/dev/rtc", 64); err != nil {
panic(err)
}
}