• Ingen resultater fundet

3.Realisation

3.4. Washing machine user interface using audio

3.4.1. A simulator

3.4.1.3. Implementation

enterMenu(): Default

This is the first menu item that the user sees when a card is inserted. It is not really used as an option and has no label. In the getDescription function it is checked if the machine is currently running. If that is the case “Welcome, the machine is running” is used as the description. If the machine is not running “Welcome” is used as the description. It is only available when a card is inserted.

ID: m5 Label: “Change to English” Access requirements: 1 Description:

Options:

getLabel(): Default getDescription(): Default

isAvailable(): Only available if the current language is not English.

enterMenu(): Change the current language to English.

This menu item is used to change the language to English. It is used as an option and has a label that says what it does. It has no options so when this menu item is entered the controller will navigate back to the welcome menu. Before it navigates back the enterMenu function is executed by the model to change the language. This menu item should not be available in the welcome menu item if the current language is already English. This is checked in the isAvailable function.

3.4 Washing machine user interface using audio 85

The “Insert card” button is used to simulate when the card is inserted/removed. The top left button labelled “Normal user” is used to set whether it should be a normal or a service user card that is inserted. The “Next”, “Centre” and “Prev” button is used to simulate the rotary knob. The “Machine is idle” button tells whether the machine is running or not. If it is running the button can be used to tell the controller that the machine has finished. The “Close door” button is used to simulate when the user closes the door in the machine. When the door is closed it says “Door is closed” and does nothing. The “Exit” button just gets out of the menu.

Illustration 35. Image of the simulator menu when the machine is running.

The controller

The controller has an initialization function that makes sure the model and the view is initialized. Other than that it just has an event handler function that takes one of the following events:

enum events { CARD_INSERTED, CARD_REMOVED, NEXT_BUTTON, PREV_BUTTON, ACCEPT_BUTTON, MACHINE_STOPPED, DOOR_CLOSED };

Enumeration with the events that are handled by the controller.

The event handler does as described in the design of the controller. A little extra error handling is done to handle if the view fails to generate the output. If the view fails the controller changes the state to the end node where the user is told to remove the card.

The notification system to notify other machines of the user’s arrival has not been implemented. It could be done by sending out a broadcast message. The boards would then need a server that integrates with the reservation system. If the server then gets the messages and if the arrived user has reserved the machine it can play a sound to tell the user where it is.

The view

The view has an update function that, as described in the design, plays the description of the currently menu item if it has been changed and then it plays the label of the currently selected option. If the text-to-speech module fails the view directly uses the TTSPlay component to play an error message. The PCM data that makes up the error message is hard coded into the view. The controller is then informed that it went wrong via the return value.

The view need to be capable of playing the text in different languages. This is handled the following way: When the text is fetched from the model a pointer to a string is returned. The string contains the text in different languages. To identify the language of the fetched text the string starts with a language code. Then the text in that

language. Then another language code and the text in another language. In this way all the needed languages are placed one after the other. The view then searches for the needed language code and then it can read the text in that language. To separate the language codes and texts a zero is inserted in the string. This means each language code and text can be used as strings without having to copy them to another array and then NULL terminating them. The problem then is to know where all the language-code/text pairs end. This is marked with two succeeding zeros.

"uk\0Program selection\0dk\0Vælg program\0"

String used in the code to hold text in different languages. \0 means a NULL is inserted.

The model

The model is the biggest of the three components. The menu item type is defined like this:

typedef struct menuItemS { uint32_t id;

uint32_t accessRequirements;

uint8_t * labelP;

uint8_t * descriptionP;

dlNodeT * optionsP;

3.4 Washing machine user interface using audio 87

uint8_t * (*getLabel)(struct menuItemS *);

uint8_t * (*getDescription)(struct menuItemS *);

BOOL (*isAvailable)(struct menuItemS *);

void (*enterMenu)(void);

} menuItemT;

Typedef used to define menu items.

A constructor function (SimModelGetNewMenuItem) has been made that will allocate memory for a menu item and initialize it. The id assigned is automatically incremented for each time the function is called. The access requirements are as default set to 1 (all users have access). The function takes the label and description as arguments. The optionsP field is a pointer to a list of options. This is initialized to NULL. The last four fields are pointers to functions. They are initialized to the default functions.

The field optionsP is of the type dlNodeT. dlNodeT is a type used for nodes in a double linked list. It has a pointer to the next node, a pointer to the previous node and a void pointer to the object (menu item) that needs to be stored in the list. A set of functions have been made that can be used to manipulate this type of list. It is chosen to use this kind of list because it can be navigated the same way the user will navigate the options.

Just to make it clear; an option is a node with a pointer to a menu item and optionsP is a pointer to a node in the list of options.

The model component has an initialization function (SimModelInit). It creates all the menu items and makes the connections between them by adding the items to the options-lists. The menu items that do not use the default functions, gets there own special functions assigned. The initialization function also initializes the rest of the state variables. They are all located in a global structure and accessed through get and set functions. For navigating the menu a couple of functions have been made. They make use of some other functions that are only intended to be used internally in the model.

BOOL SimModelSelectNextAvailableOption(void);

BOOL SimModelSelectPrevAvailableOption(void);

BOOL SimModelAcceptSelectedOption(void);

BOOL SimModelReset(void);

BOOL SimModelBack(void);

Functions used by the controller to navigate the menu.