• Aucun résultat trouvé

Use LCD Menus and Modes

Dans le document LINUX APPLIANCE DESIGN (Page 178-181)

If your appliance has an LCD display, you can add menus and status to your front panel UI. A menu, in this context, is a linear list of items to select.

These items might be commands, configuration settings, or pathways into sub-menus. The interface will need to have buttons that allow users to navigate the list and to select desired items. Common navigation buttons include next item, previous item, select this item, and previous menu. The best way to avoid building a menu system that is a maze of twisty passages, all alike is to map out the menu system with a state transition diagram. Try to keep your transition diagram orthogonal so that directions like up, down, left, and right have meaning. Many LCD menu systems treat the LCD display as a window that sees part of the state transition diagram. An LCD assembly from Matrix Orbital that is made for this kind of menu structure is shown in Figure 10-4.

Figure 10-4: A typical front panel with menu navigation buttons

You can save on cost and front panel space by eliminating the Up and Left buttons and having the Down and Right buttons wrap from the last menu option back to the first. Of course, some type of Enter button would still be required.

Most LCD-based UIs operate in one of two modes: They display status if no buttons are pressed, and they display a menu when a button is pressed.

For example, some printers have a one-line LCD display that reports Ready if there is no activity, shows Printing if it is receiving or printing, and enters a configuration menu if any button is pressed. Laddie has three modes: one to display status, one to display log messages, and one to display a menu for configurations changes and clearing alarms.

Be Quick!

The rule of thumb is that the front panel UI should be functional within two seconds of turning on the appliance. This section discusses some common techniques that can help you meet this goal.

Boot Linux Faster

There is quite a bit that can be done to improve the boot time for Linux.

One technique avoids a boot entirely by doing a suspend and resume, instead. A suspend copies the memory and state of the computer to a file or disk partition. A resume reloads the previously saved memory. To set up a suspend and resume on your system, build your kernel with software suspend enabled, and get your appliance into the state that you want your users to see after power on. Issue the suspend command (this may be hibernate, swsusp, or a write into /proc, depending on your system) to save the system state to the swap partition. Properly handled, the suspend image on the swap parti-tion can actually be the software that ships on your appliance. There are configurable scripts that can run on suspend and resume, and you can modify these scripts to restart network connections and to reset the clock.

See http://www.suspend2.net for more details. Be sure to read the HOWTO section on Keep image mode.

Software suspend does not improve the load time for the kernel itself, but there are several techniques that do. For example, you can build your kernel with module support disabled and with only the minimum number of device drivers that you need. This reduces the time needed to load modules and should remove the need for an initial RAM disk (initrd). You might be able to avoid loading the kernel entirely if you can execute it directly from ROM or flash memory. This technique is called execute in place (XIP). Using the kernel option quiet to disable printk messages during boot can save several hundred milliseconds. These and many other techniques are explained on the Consumer Electronics Linux Forum website at http://

www.celinuxforum.org.

After the kernel starts, the first program to run is usually /sbin/init, which executes the script /etc/rc.d/rc.sysinit. The rc.sysinit file sets up vital services and starts the other init scripts. On a consumer appliance you should

probably replace the entire set of init scripts with one or two custom scripts.

This can be a lot of work, but the time savings can be tremendous. A good way to start is to boot your system with the kernel option init=/bin/sh and manually bring up your appliance one command at a time. Try to get the button and LED UIs running as quickly as possible, deferring the non–front panel programs until the end of the initialization. Start programs in the back-ground if you can, but be careful not to backback-ground a program if it must complete before another program you need can start. The InitNG package by Jimmy Wennlund is a popular init script alternative that is optimized for a faster boot.

If the above techniques are not sufficient to get your front panel working quickly, you may want to add a microcontroller to your design.

Use a Microcontroller

You can use a microcontroller to handle the buttons, LEDs, and LCD in your UI. Microcontrollers are single-chip computers with on-board RAM, ROM, CPU, and I/O. Common microcontrollers include the Microchip PIC and the Atmel AVR.1 These controllers are a great way to display messages on an LCD immediately after boot and to make the buttons and keypad responsive immediately. Let’s consider a DVD player as an example. After power-on, the user will usually open the disc drawer, insert a disc, close the drawer, and press Play. If the drawer mechanism is tied directly to your Linux system, the user must wait for Linux to boot before starting the above process. If, on the other hand, you have a microcontroller handling the drawer mechanism and Open button, you can immediately display Ready on the LCD and make the button usable. By the time the user has opened the drawer, loaded the disc, and pressed Play, the Linux part of the DVD player will probably be done booting. Of course, once Linux is running, it will want to control the drawer mechanism directly by treating the microcontroller as one of its peripherals.

Use the Main CPU as a Microcontroller

Adding a microcontroller increases the cost, power requirement, and printed circuit board space of an appliance. An alternative is to carve out a piece of the main CPU to use as a microcontroller while Linux is starting. You can modify the bootloader to set up a timer interrupt and use the interrupt handler to provide a front panel UI. You’ll need to modify Linux so that it does not touch the timer or interrupt handler while booting. Once Linux is running, it can take over the timer and interrupt, making the front panel hardware just another device that it manages. This technique describes a form of virtual machine (VM); as they become more popular, you may find that a VM provides all the hooks necessary to be used as an I/O controller.

Don’t Shut Down

A common technique to make an appliance more responsive is to never shut it down. Instead, you can build your appliance to enter a low power state

1 You can program the Atmel AVR using C on a Linux workstation. See http://

www.avrfreaks.org for more information.

when the user presses the Off button. A low power state might include having a slower CPU clock and removing power to as many peripherals as possible.

However, you should be aware that this approach has fallen into disfavor as more and more consumers demand that Off means zero power consumption.

Give Feedback

If you can’t be quick, at least try to give the user an idea of what the system is doing. Don’t be afraid to modify the Linux kernel to send simplified boot status messages to the LCD. Telling the user what is happening can help him or her tolerate the 10- to 20-second boot time of Linux.

Giving feedback should not be limited to just the boot process. Give the user constant feedback by bringing the Ethernet activity LED to the front panel or having the LCD display rotate through various appliance statistics.

Be sure to indicate error conditions clearly and unambiguously.

Dans le document LINUX APPLIANCE DESIGN (Page 178-181)