-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
42 lines (36 loc) · 1.3 KB
/
main.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
package main
import (
"os"
"os/signal"
"syscall"
sr "github.com/mikaponics/mikapod-soil-reader/internal/app"
)
// DEVELOPERS NOTE:
// - Don't forget to run the following in the console:
// export MIKAPOD_SOIL_READER_DEVICE_PATH=/dev/cu.usbmodem1D132101
// - Please replace the device path value with your devices value!
/**
* Application used to interface with the hardware instruments (ex: humidity,
* temperature, etc) and continously save the latest data.
*/
func main() {
arduinoDevicePath := os.Getenv("MIKAPOD_SOIL_READER_DEVICE_PATH")
app := sr.InitMikapodSoilReader(arduinoDevicePath)
// DEVELOPERS CODE:
// The following code will create an anonymous goroutine which will have a
// blocking chan `sigs`. This blocking chan will only unblock when the
// golang app receives a termination command; therfore the anyomous
// goroutine will run and terminate our running application.
//
// Special Thanks:
// (1) https://gobyexample.com/signals
// (2) https://guzalexander.com/2017/05/31/gracefully-exit-server-in-go.html
//
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-sigs // Block execution until signal from terminal gets triggered here.
app.StopMainRuntimeLoop()
}()
app.RunMainRuntimeLoop()
}