WHEATSYSTEM 1.0.0 FUNCTIONS

This page was generated from https://github.com/ostracod/wheatsystem-spec at 10/5/2022, 5:09 PM EDT.

Each WheatSystem application may expose one or more functions to be called externally. This document describes the functions which are part of the WheatSystem specification.

APPLICATION FUNCTIONS

Any WheatSystem application may implement the functions init and kill. These functions help the system manage the lifecycle of applications.

init()

Triggered by the application system immediately after an application launches. If an application does not implement init, the application will remain inactive after launch.

kill()

Requests for the receiving application to terminate. The application should clean up any volatile resources.

TERMINAL DRIVER FUNCTIONS

A terminal driver is an application which can display text on a terminal and receive keystroke input. A terminal driver must implement the functions listenTerm, termSize, and wrtTerm. The standard system terminal driver is optional for WheatSystem distributions. If available, the standard system terminal driver has the file name wsTerm.

listenTerm()

Causes the calling application to become an observer of the receiving terminal driver. When the terminal driver registers a typed key, it will invoke the termInput function of its observer. Each terminal driver may have at most one observer. If another application invokes listenTerm, it will become the new observer.

termSize(
    s16 widthDest,
    s16 heightDest
)

Retrieves the dimensions of the terminal controlled by the receiving terminal driver. The dimensions are measured in number of characters.

wrtTerm(
    s16 x,
    s16 y,
    s32 text
)

Displays text on the terminal of the receiving terminal driver. Text will wrap around to the next line after it reaches the end of the screen.

termInput(
    s8 key
)

Invoked by a terminal driver to notify the receiving observer when a key has been typed.

Terminal key codes for visible characters have ASCII values. Other key codes include the following:

SERIAL DRIVER FUNCTIONS

A serial driver is an application which can send and receive data over serial ports. A serial driver must implement the functions startSerial, stopSerial, and wrtSerial. The standard system serial driver is optional for WheatSystem distributions. If available, the standard system serial driver has the file name wsSerial.

startSerial(
    s8 port,
    s32 baudRate
)

Causes the receiving serial driver to open the given serial port, and assigns the calling application as an observer. When the port receives input data, the serial driver will will invoke the serialInput function on the port's observer.

stopSerial(
    s8 port
)

Causes the receiving serial driver to close the given serial port. The port will no longer send or receive data.

wrtSerial(
    s8 port,
    s32 buff
)

Causes the receiving serial driver to output data over the given serial port.

serialInput(
    s8 port,
    s8 value
)

Invoked by a serial driver to notify the receiving observer when a serial byte has been ingested.

GPIO DRIVER FUNCTIONS

A GPIO driver is an application which can read and write signals through general-purpose I/O pins. A GPIO driver must implement the functions setGpioMode, readGpio, and wrtGpio. The standard system GPIO driver is optional for WheatSystem distributions. If available, the standard system GPIO driver has the file name wsGpio.

setGpioMode(
    s16 pin,
    s8 mode
)

Sets the I/O mode of the given GPIO pin.

Available I/O modes include the following:

readGpio(
    s32 dest,
    s16 pin
)

Reads a digital or analog value from the given GPIO pin.

wrtGpio(
    s16 pin,
    s32 value
)

Writes a digital or analog value to the given GPIO pin.

WHEATSHELL FUNCTIONS

WheatShell is an application which can display windows to the user and accept user input. The shell must implement the following functions:

WheatShell is optional for WheatSystem distributions. If available, the shell has the file name wsShell.

A function implemented by the shell will throw permErr if all of the conditions below are true:

newWindow(
    s32 dest,
    s32 title
)

Creates a new window which allows interaction with the user. All WheatShell implementations can display text in windows, while graphics are only supported on certain platforms. The caller of newWindow is considered to be the owner of the window. If title is null, the title of the window will be the file name of the caller. If the user presses a key while the window is focused, the shell will call windowKeyPressed on the window owner. If the window changes focus, the shell will call windowFocusChanged on the window owner. If the user requests to close the window, the shell will call reqDelWindow on the window owner.

reqDelWindow(
    s32 window
)

Invoked by the shell to notify the receiving window owner when the user has requested to close the given window. If the window owner does not implement reqDelWindow, the shell will delete the window immediately.

delWindow(
    s32 window
)

Deletes the given window.

displayWindowMessage(
    s8 dest,
    s32 window,
    s32 message
)

Displays a message in the given window, and waits for the user to dismiss the message. If the message is too long to fit in the window, the user can scroll up and down to view the whole message. dest will be set to 1 if the user pressed the escape key, and 0 for all other keys.

promptWindowOption(
    s16 dest,
    s32 window,
    s32 message,
    s32 options
)

Displays a list of options in the given window, and waits for the user to select an option. If message is null, then no message will be displayed above the options. If the user presses the escape key, dest will be set to -1.

promptWindowText(
    s32 dest,
    s32 window,
    s32 message,
    s32 startText
)

Prompts the user to enter a line of text in the given window. Newlines are not supported in the text entry. If message is null, then no message will be displayed above the text entry. If startText is null, then the initial contents of the text entry will be empty. If the user presses the escape key, dest will be set to null.

clrWindow(
    s32 window
)

Erases any text or graphics which are displayed in the given window.

windowTermSize(
    s16 widthDest,
    s16 heightDest,
    s32 window
)

Retrieves the width and height of the given window.

readWindowTerm(
    s32 dest,
    s32 window,
    s16 x,
    s16 y,
    s32 length
)

Reads text which has been drawn using wrtWindowTerm in the given window. The character position to read will wrap around to the next line after it reaches the end of the window.

wrtWindowTerm(
    s32 window,
    s16 x,
    s16 y,
    s32 text
)

Displays text in the given window. Text will wrap around to the next line after it reaches the end of the window.

windowKeyPressed(
    s32 window,
    s8 key
)

Invoked by the shell to notify the receiving window owner when the user has pressed a key. This function uses the same key codes as the function termInput. The system menu key will not be passed through windowKeyPressed, and is instead used to display a menu in the shell. Note that the shell will not call windowKeyPressed while displayWindowMessage, promptWindowOption, or promptWindowText are running.

windowFocusChanged(
    s32 window,
    s8 hasFocus
)

Invoked by the shell to notify the receiving window owner when the window has changed focus. A focused window is visible to the user and registers key presses.