de2gui

package
v0.0.0-...-2aedad7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 18, 2021 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Overview

Package de2gui contains code for providing a graphical facsimile of the Terasic DE2-115 development board.

Index

Constants

This section is empty.

Variables

View Source
var ColorGreenActive color.RGBA = color.RGBA{25, 200, 25, 255}

ColorGreenActive is the color used for green-colored illuminated parts when they are active.

View Source
var ColorGreenInactive color.RGBA = color.RGBA{15, 25, 15, 64}

ColorGreenInactive is the color used for green-colored illuminated parts when they are not active.

View Source
var ColorRedActive color.RGBA = color.RGBA{200, 25, 25, 255}

ColorRedActive is the color used for red-colored illuminated parts when they are active.

View Source
var ColorRedInactive color.RGBA = color.RGBA{25, 15, 15, 64}

ColorRedInactive is the color used for red-colored illuminated parts when they are not active.

View Source
var KeyPushMaxTime uint64 = 250

KeyPushMaxTime is the maximum number of ticks until a key is released after it is pushed

View Source
var KeyPushMinTime uint64 = 10

KeyPushMinTime is the minimum number of ticks until a key is released after it is pushed

Functions

This section is empty.

Types

type UIState

type UIState struct {

	// The Tick value is displayed to the user as the current tick #, and
	// is also used to determine when to run futures
	Tick uint64

	// OnKEY is run when any key is changed (pressed or released)
	OnKEY func(*UIState)

	// OnSW is run with any SW is changed
	OnSW func(*UIState)

	// OnTick is run when any of the tick-related controls is used.
	//
	// The boolean parameter is used as a performance optimization, it will
	// be true if and only if this it the final tick in a range of many
	// ticks which occur at once. For example, it might be best to call
	// functions like SetHex() only when this parameter is true, to avoid
	// spurious UI updates.
	OnTick func(*UIState, bool)

	// OnReset is run when the reset button is used
	OnReset func(*UIState)
	// contains filtered or unexported fields
}

UIState contains all of the GUI widgets, and the data needed to interact with them.

The UI revolves around the assumption that the underlying simulation runs in discrete simulation "ticks". The OnTick callback is called whenever the user does something that triggers one or more ticks to occur. The downstream GUI is expected to update the Tick field appropriately when they handle simulation ticks.

Certain aspects of the UI also deal with events happening in the "future". Namely, when a KEY is pressed, it stays "pressed" for a variable number of ticks (this is to simulate real hardware, where a button will be pressed by a human for many thousands of clock cycles). This is handled by scheduling a key release for the future. Futures run when the Tick field equals their scheduled time to run and a Tick occurs. Futures run before OnTick is called.

func NewUIState

func NewUIState() *UIState

NewUIState initializes a new instance of the DE2GUI's state object along with all of the needed widgets. After calling this, FyneObject() can safely be called.

EtraWidgets, if non-nil, will be inserted into the left panel of the created GUI elements.

func (*UIState) ClearFutures

func (s *UIState) ClearFutures()

ClearFutures removes all functions scheduled to run in the future. You almost certainly want to call this in your OnRest() method.

func (*UIState) ClearKEY

func (s *UIState) ClearKEY()

ClearKEY "un-presses" all KEYs. If you have called ClearFutures, you probably want to call this also, since the futures that would have released any pressed keys will now be deleted.

func (*UIState) ClearSW

func (s *UIState) ClearSW()

ClearSW resets all switches to the "off" state. You might want to call this in your OnRest() method.

func (*UIState) FyneObject

func (s *UIState) FyneObject() fyne.CanvasObject

FyneObject will return a Fyne canvas object which contains all of the widgets and such relating to this instance of the UIState. This should be suitable for use with Window.SetContent. However for more advanced use cases, it can be embedded in a container as needed.

func (*UIState) KEY

func (s *UIState) KEY() uint32

KEY returns the current value of the KEY controls. There are 4 keys. The rightmost key is the least-significant bit. Unused higher order bits are left as zero.

func (*UIState) SW

func (s *UIState) SW() uint32

SW gets the current value of the SW(itch) controls. There are 18 switches. The rightmost switch is assigned to the least-significant bit. Unused higher order bits are left as zero.

func (*UIState) ScheduleFuture

func (s *UIState) ScheduleFuture(when uint64, f func(*UIState))

ScheduleFuture will cause the provided callback to be executed whenever a tick occurs and s.Tick is at least equal to `when`.

func (*UIState) SetHEX

func (s *UIState) SetHEX(i int, state uint8)

SetHEX updates the state of the i-th HEX display. Hex display 0 is the rightmost (least significant)

     0
   -----
  |     |
5 |     | 1
  |  6  |
   -----
  |     |
4 |     | 2
  |  3  |
   -----

Segments are packed into a uint8 as shown in the above diagram. Segments are active-low.

func (*UIState) SetLEDG

func (s *UIState) SetLEDG(state uint32)

SetLEDG sets the LEDG display. There are 9 green LEDs. the least significant bit codes for the rightmost LED. LEDs are active-high. Unused higher order bits are ignored.

func (*UIState) SetLEDR

func (s *UIState) SetLEDR(state uint32)

SetLEDR sets the LEDR display. There are 18 red LEDs. The least significant bit codes for the rightmost LED. LEDs are active-high. Unused higher order bits are ignored.

Directories

Path Synopsis
widgets
hexwidget
Package hexwidget implements a 7-segment style hexadecimal display
Package hexwidget implements a 7-segment style hexadecimal display
ledwidget
Package ledwidget defines a GIU widget that mimics the appearance of the DE2-115 LED groups.
Package ledwidget defines a GIU widget that mimics the appearance of the DE2-115 LED groups.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL