Example #1
0
//DisplayMessage shows the given message on the display. The message is split in pages if needed (no scrolling is used)
//In general, only strings that can be mapped onto ASCII can be displayed correctly.
func displayEvent(display *hd44780.HD44780, event *LcdEvent) {
	log.Println("LCD: Displaying message: " + event.message)
	err := display.Clear()
	utils.LogErrorandExit("Cannot clear LCD:", err)

	if event.flash == BEFORE || event.flash == BEFORE_AND_AFTER {
		flashDisplay(display, event.flashRepetitions, 1*time.Second)
	}

	bytes := []byte(event.message)

	frames := int(math.Ceil(float64(len(bytes)) / 32.0))
	// log.Println("Frames: " + strconv.Itoa(frames))
	frametime := int64(math.Ceil(float64(event.duration) / float64(frames)))
	// log.Println("Frame time: " + strconv.Itoa(int(frametime)))

	for i := 0; i < frames; i++ {
		// log.Printf("Displaying frame %v\n", i)
		rightBound := (i + 1) * 32

		if rightBound > len(bytes) {
			rightBound = len(bytes)
		}
		// log.Println("Frame Content: " + string(bytes[i*32:rightBound]))
		displaySingleFrame(display, bytes[i*32:rightBound], time.Duration(frametime))

		if i != (frames-1) || event.clearAfter {
			display.Clear()
		}

	}

	if event.flash == AFTER || event.flash == BEFORE_AND_AFTER {
		flashDisplay(display, event.flashRepetitions, 1*time.Second)
	}

	if event.eventType == EVENT_SHUTDOWN {
		log.Println("LCD: Driver shutting down...")
		display.Close()
	}
}