forked from google/periph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_test.go
45 lines (37 loc) · 1.25 KB
/
example_test.go
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
// Copyright 2018 The Periph Authors. All rights reserved.
// Use of this source code is governed under the Apache License, Version 2.0
// that can be found in the LICENSE file.
package periph_test
import (
"fmt"
"log"
"periph.io/x/periph/host"
)
func Example() {
// host.Init() registers all the periph-provided host driver automatically,
// so it is preferable to use than periph.Init().
//
// You can also use periph.io/x/extra/hostextra.Init() for additional drivers
// that depends on cgo and/or third party packages.
state, err := host.Init()
if err != nil {
log.Fatalf("failed to initialize periph: %v", err)
}
// Prints the loaded driver.
fmt.Printf("Using drivers:\n")
for _, driver := range state.Loaded {
fmt.Printf("- %s\n", driver)
}
// Prints the driver that were skipped as irrelevant on the platform.
fmt.Printf("Drivers skipped:\n")
for _, failure := range state.Skipped {
fmt.Printf("- %s: %s\n", failure.D, failure.Err)
}
// Having drivers failing to load may not require process termination. It
// is possible to continue to run in partial failure mode.
fmt.Printf("Drivers failed to load:\n")
for _, failure := range state.Failed {
fmt.Printf("- %s: %v\n", failure.D, failure.Err)
}
// Use pins, buses, devices, etc.
}