Example #1
0
func main() {

	// setup
	mux := http.NewServeMux()
	//mux.Handle("/",http.FileServer(http.Dir("data")))
	mux.HandleFunc("/", indexHandler)
	mux.HandleFunc("/index", indexHandler)
	mux.HandleFunc("/new", newHandler)
	mux.HandleFunc("/start", startHandler)
	mux.HandleFunc("/pause", pauseHandler)
	mux.HandleFunc("/resume", resumeHandler)
	mux.HandleFunc("/stop", stopHandler)
	//mux.HandleFunc("/download",getRequest)
	mux.HandleFunc("/"+dataPath+dataFileName, getRequest) // /data/output.csv

	theAcq.initiate()
	theOshi.initiate()

	// starting the web service...
	// http.Handle("/data", http.FileServer(http.Dir("./data")))
	log.Println("Listennig on http://localhost:8080/")
	log.Fatal(http.ListenAndServe(":8080", mux))

	log.Println("Closed http://localhost:8080/")
	// close the GPIO pins
	defer theAcq.serialPort.Close()
	hwio.CloseAll()
}
Example #2
0
func main() {

	// setup

	// Set up 'button' as an input
	button1, e := hwio.GetPinWithMode(buttonPin1, hwio.INPUT)
	if e != nil {
		panic(e)
	}
	button2, e := hwio.GetPinWithMode(buttonPin2, hwio.INPUT)
	if e != nil {
		panic(e)
	}
	button3, e := hwio.GetPinWithMode(buttonPin3, hwio.INPUT)
	if e != nil {
		panic(e)
	}

	// Set up 'led' as an output
	led, e := hwio.GetPinWithMode(ledPin, hwio.OUTPUT)
	if e != nil {
		panic(e)
	}

	//e:= hwio.Led("OK", true)
	fmt.Printf("Beginning.....\n")
	t0 = time.Now()
	go readButton("Uno", button1, led)
	go readButton("Dos", button2, led)
	go readButton("Tres", button3, led)

	// wait
	fmt.Print("Enter to finish: ")
	var input string
	fmt.Scanln(&input)

	defer hwio.CloseAll()
}
Example #3
0
func main() {

	// setup

	// open file (create if not exists!)
	if len(os.Args) != 2 {

		fmt.Printf("Usage: %s fileBaseName\n", os.Args[0])
		os.Exit(1)
	}

	t := time.Now()
	thisOutputFileName := fmt.Sprintf("%s_%d%02d%02d%02d%02d%02d.csv", os.Args[1], t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second())
	thisOutputFile, e := os.Create(thisOutputFileName)
	if e != nil {
		panic(e)
	}
	fmt.Printf("File: %s\n", thisOutputFileName)

	outputFile = thisOutputFile

	// Set up 'trakers' as inputs
	trackerA, e := hwio.GetPinWithMode(trackerAPin, hwio.INPUT)
	if e != nil {
		panic(e)
	}
	trackerB, e := hwio.GetPinWithMode(trackerBPin, hwio.INPUT)
	if e != nil {
		panic(e)
	}
	trackerC, e := hwio.GetPinWithMode(trackerCPin, hwio.INPUT)
	if e != nil {
		panic(e)
	}
	trackerD, e := hwio.GetPinWithMode(trackerDPin, hwio.INPUT)
	if e != nil {
		panic(e)
	}

	// Set up 'buttons' as inputs
	buttonA, e := hwio.GetPinWithMode(buttonAPin, hwio.INPUT)
	if e != nil {
		panic(e)
	}
	buttonB, e := hwio.GetPinWithMode(buttonBPin, hwio.INPUT)
	if e != nil {
		panic(e)
	}

	// Set up 'leds' as outputs
	statusLed, e := hwio.GetPinWithMode(statusLedPin, hwio.OUTPUT)
	if e != nil {
		panic(e)
	}
	thisActionLed, e := hwio.GetPinWithMode(actionLedPin, hwio.OUTPUT)
	if e != nil {
		panic(e)
	}
	actionLed = thisActionLed

	fmt.Printf("Push button A to start, B to finish...\n")

	// read the button A change to init the data readdings
	waitTillButtonPushed(buttonA)
	hwio.DigitalWrite(statusLed, hwio.HIGH)
	t0 = time.Now()
	fmt.Printf("Beginning.....\n")

	// launch the trackers

	go readTracker("A", trackerA)
	go readTracker("B", trackerB)
	go readTracker("C", trackerC)
	go readTracker("D", trackerD)

	// wait till button B is pushed
	waitTillButtonPushed(buttonB)
	hwio.DigitalWrite(statusLed, hwio.LOW)
	fmt.Printf("Finnishing.....\n")

	//fmt.Print("Enter to finish: ")
	//var input string
	//fmt.Scanln(&input)

	// close the GPIO pins
	defer hwio.CloseAll()

	defer thisOutputFile.Close() //close the file when main finished

}