2 Main Loop

by Aaron Becker

2.1 Project Functionality

The heart of the smart farming program is the main loop. Here, each of the many functions can be accessed by calling them from the loop. After being welcomed to the program, the system needs to be unlocked. The user is queried to supply a default password and then set the password to the user’s choice. Next, a help screen instructs the user on how to move into the available functions. In between functions, the tractor is in communication with the base, using a protocol similar to Instant Messaging.

In the information age, no one is immune to needing facts, figures, and news. Even years after the advent of radio, telephone, and television, millions find comfort in sending free, quick, personal notes by typing and reading them on a computer. The HyperTerminal and QTerm keypad allow this to work well. This allows the Farmer to get crop data, urgent messages, weed information, weather reports, and even specialized stock quotes, all while farming. Identifiers pre-coded into the buffers show who is speaking. The labels, ”Tractor:” and ”Base:” prevent ambiguity and lend a familiar feeling to the exchange. The HyperTerminal exchange is nicely formatted. The shift key allows extra options to be called using the Qterm keyboard. The program opens in a fun way by showing a large weedy field. An ASCII tractor mows across the field and then corn sprouts, grows, and fills out, finally spelling the project’s name ’Smart Farming’ which then scrolls across the screen. Later, the authors’ names mesh across the screen and pause just long enough to read before the password program opens. The relevant data has been spelled out in an engaging manner and a psychological measure of confidence in the programming has been built. If every thing the user can see is well presented and tightly integrated, then the programming underneath probably is as well. Consumers are a fickle fan base, so companies want a product that not only performs well, but that looks great.

2.2 Project Design

The main loop, the heart of the smart farming program, is entirely programmed in assembly in the file MainSource.asm. Here, each of the many functions can be accessed by calling them from the loop. Lab 8 provided the skeleton for this file. After being welcomed to the program and having the system unlocked, a help screen, a c function, instructs the user on how to move into the available functions.

While the user in not using the functions, the tractor uses the Instant Messaging service to keep in contact with the base. To better adapt Lab 8 to this task, the labels, ”Tractor:” and ”Base:” were added by hard coding them into the first 8 and 5 spaces of the PC and QT buffers. Also added to these buffers was formatting for the HyperTerminal exchange. By always resetting the write pointers to zero, but setting the read pointer to 9 and 6 past the beginning of the array, the program will print who sent the message and will never overwrite these labels. These efforts transform the unwieldy lab 8 protocol into something more refined.

Also added was the ability to call all the functions and utilize the help screen from this main program loop. Since the Qterm keyboard only has 5 keys, and there are many more functions than that, something additional was needed. By adding functionality to the shift key, the available options were doubled. A register holds a value signifying whether the shift key had been pressed, and several branch statements control which C functions can be called.

The relevant data for spraying each field are held in registers r30 and r31. as iCurrentSeedType, which sgnifies what kind of crop is being worked with, and iSprayerFluid, which stores how much sprayer fluid the tank holds. Some of the functions one variable, and sprayer.c needs both variables, so the mains.asm loop puts the required variables into r3 and r4 before calling each function, then takes the result out and reassigns it to the proper registers.

The ASCII animation is an interesting addition. Making ASCII art is not difficult, but takes a great deal of time since everything must fit within the particular screen that will be used. By making full use of the member functions, the cursor can be moved back to the top left-hand corner, which causes less flicker in the screen. By using a variety of loops and assignment operators, a great deal of laborious recopying is eliminated. The QTerm LCD screen is 20 characters wide by 4 rows deep. You can make a message 100 characters wide and 4 deep; then just assign the characters i to i+20 to be printed to the screen. The msleep function is well suited to make animated screen art and once the programmer grows used to the setup, the number of designs available is only limited to the programmers’ imagination.