"Implement an application that monitors the temperature and changes the color of the LEDs on the SPOT based on the following thresholds:
Temperature >= 80: red
Temperature 60-79: green
Temperature"[1]
Analysis:
This task is a simple SPOT application that contains two parts: continuously getting current temperature and indicating actual degrees by different LEDs' colors. It's very easy to catch the temperature by invoking the method getADCTemperature:"Convience Function to get internal temperature sensor on the ADC from the EDemoBoard[2]". Then I need to blink the SPOT in different colors according to given rules. In order to change LEDs colors, I can use the method SetColor or SetRGB that exist in com.sun.spot.sensorboard.peripheral.ITriColorLED. In general, I can get familiar with some basic SPOT libraries by implementing this task.
Implementation:
I realize this task first in an easy way to learn these basic APIs. I attached the main part of my simple code that can also satisfy the requirements of Task 2:
--------------------------------------Code--------------------------------------------
protected void startApp() throws MIDletStateChangeException {
IBoard=EDemoBoard.getInstance();
//initialize all LEDs
ITriColorLED[] led = IBoard..getLEDs();
for(int i=0 ; i < color="#008000">// endless loop
try{
//get current temperature
double dDegree=IBoard.getADCTemperature().getFahrenheit();
//choose correct color according to current fahreheit degree
LEDColor clr1;
if(dDegree>=80){
clr1=LEDColor.RED;
}
else if(dDegree>=60 && dDegree<80){ clr1="LEDColor.GREEN;" clr1="LEDColor.BLUE;" color="#008000">//change LEDs' color
for(int i=0 ; i < style="font-weight: bold;">Performance and Testing:
I deployed my code to one free-range SPOT and it worked. It blinked in a red color in the afternoon when the degree is greater than 90. And I tested it in the morning when the degree is only 69, it correctly flashed in a green color. In order to make it easy to test my source code, I change the color-change scale and make the value of thresholds much closer. For example, when the basic temperature is 89.5, I execute the follow rules:
Temperature >=90: Red
Temperature 89-90: Green
Temperature <89: style="font-weight: bold;">Advanced Performance:
I combined the project AirText to this task to display current temperature. When I shook the SPOT from left to right, I could see the Fahrenheit degree in a given color.
Difficulty and Challenge:
This task is comparatively easy so that I didn't encounter any big issues or challenges. But I ever got in some big trouble that cost a couple of hours to deal with when I ran this task on the SPOT.I simply describe two problems here and will also generalize all problems and relevant solutions in another individual post.
1)Applications do NOT run on the SPOT.
I used the command "Clean and Build Project" to compile my project by Netbeans 5.5.But I didn't see the expected result after I finish deploying my project to the SPOT.The SPOT didn't make any response even though I just used very simple code. The same situation happened when I ran the demo BounceDemo-OnSPOT.But if I planted the demo AirText to it, it worked. So I found the first reason causing this wrong situation. I used "ant enableota" to open OTA mode and forgot to turn it off. After I executed "ant disableota", the SPOT can run the demo BounceDemo-OnSPOT.
The second reason is difficult to find out because basically we often ignored it.When we use Netbeans IDE to create SPOT project, it will generate the default class "StartApplication". In general, we changed its name to different one but we don't know to modify the file MANIFEST.MF related to generating the jar file. The content of MANIFEST.MF is like below:
MIDlet-Name: TemperatureMonitor
MIDlet-Version: 1.0.0
MIDlet-Vendor: Sun Microsystems Inc
MIDlet-1: src/org/sunspotworld/StartApplication, , org.sunspotworld.src/org/sunspotworld/StartApplication
MicroEdition-Profile: IMP-1.0
MicroEdition-Configuration: CLDC-1.1
We need to change the fourth line to:
MIDlet-1: ,, org.sunspotworld.TemperatureMonitor
org.sunspotworld : Package Name
TemperatureMonitor : Main Class Name
In one word, you should check the OTA mode and the main class name in MANIFEST.MF first if you encounter the same problem as mine.
2)Applications die and can NOT reset the SPOT.
Due to the first problem, the SPOT cannot find main class to run. When I booted the SPOT, its indication Light just constantly flashed like being in the stalemate. Worse of all, the computer cannot find it when I tried to deploy the other correct project to it. I always receive the same warning messages such as the following ones:
SPOT Client starting...
Port COM6 unavailable...
Available ports: COM3
retrying...
Port COM6 unavailable...
Available ports: COM3
retrying...
Port COM6 unavailable...
Available ports: COM3
retrying...
Available ports: COM3
Error: Spot not found on port: COM6 not found
I also used the command "ant -Dport=COM6 slots" according to Sun Spot User's Guide, it didn't work. Even I tried all solutions that I got from the internet, my computer still didn't detect this SPOT. It was unexpectedly recovered after I carelessly rebooted my computer.
So please try the following two solutions to solve the same problem:
To execute the command "ant -Dport=COMn slots" in the local directory of your project;
COMn : the port connected to your SPOT
To reboot your computer;
Time Distribution:
Task | Description | Deadline | End Date | Total Time (hrs) |
2 | Temperature Monitor | 06/13/2008 | 06/12/2008 | 10.9 |
Sub Task | Time | |||
Create the framework of this project | 0.5 | |||
Implement the two interfaces and main class | 2.5 | |||
To create simple code to realize the requirement of this task | 0.2 | |||
Solve two problems: 1) Applications do NOT run on the SPOT. 2) Applications die and can NOT reset the SPOT. | 4.2 | |||
Combine AirText project to this task | 0.5 | |||
Miscellaneous Task (updating the blog, documents and so on) | 3 |
[1]Quoted from the section "Task 2" of Class Requirement Document
Written by Professor Sami Rollins
[2]http://www.sunspotworld.com/docs/Orange/javadoc/com/sun/
spot/sensorboard/EDemoBoard.html#getADCTemperature()
No comments:
Post a Comment