ahead accessible home energy audio · pdf fileahead accessible home energy audio dashboard ......

96
ECE 480 Design Team 2 AHEAD Accessible Home Energy Audio Dashboard Team members: Ahmad Al-Qudaihi Dennis Wey Joey Grover Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010

Upload: phungkien

Post on 29-Mar-2018

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

0

ECE 480 Design Team 2

AHEAD

Accessible Home Energy Audio Dashboard

Team members:

Ahmad Al-Qudaihi

Dennis Wey

Joey Grover

Jason Grimes

Facilitator: Fathi Salem

Sponsored By:

Final Report April 30, 2010

Page 2: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

1

Executive Summary: The demand of electricity is constantly at a growing rate. The overall demand can be brought

down by giving consumers to have a way to be able to monitor the current cost of electricity. The

informed consumer has been shown to limit their use of electronic devices when the cost of electricity

rises due to peak demand. Team 2 purposes to make a device that would make it easy for consumers to

be able to monitor the cost of electricity and to control their appliances from one device. The other

component of the project will be to develop a device that addresses the needs of people with

disabilities. Since most products that are new to the market do not include accessibility features, team 2

hopes to introduce their AHEAD device with the features that people with disabilities need and create a

new standard in the product development process.

Acknowledgment:

Team 2 would like to thank Stephen Blosser, Fathi Salem, Dr. Goodman, Dr. Shanblatt, and the entire ECE faculty. Their assistance help the team reach their final, successful goal in creating a prototype, the AHEAD module.

Page 3: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

2

Table of Contents

1. Introduction ............................................................................................................................................4

1.1 The AHEAD Module .................................................................................................................4

1.2 Consumers Energy and Smart grid ...........................................................................................4

1.3 X10 Home Automation .............................................................................................................5

2. Design Solutions .....................................................................................................................................6

2.1 Managing Energy Consumption ...............................................................................................6

2.2 Accessibility ..............................................................................................................................6

2.3 Design .......................................................................................................................................7

2.4 Budget ......................................................................................................................................9

2.5 Gantt Chart .............................................................................................................................10

3. Technical Implementation ....................................................................................................................11

3.1 Visual Alerts ...........................................................................................................................11

3.2 Touch Interface ......................................................................................................................12

3.3 Touchscreen Overlay ...............................................................................................................12

3.4 XBee Serial Communications .................................................................................................14

3.5 Audio Amplifier ......................................................................................................................15

3.6 Software Interface ..................................................................................................................16

3.7 Accessibility Features .............................................................................................................18

3.8 Smart Meter Simulation .........................................................................................................20

3.8 Gestures ................................................................................................................................21

4. Testing ..................................................................................................................................................25

4.1 Interface Testing ....................................................................................................................25

4.2 Accessibility ............................................................................................................................25

4.3 Smart Meter ...........................................................................................................................25

4.4 Home Automation ..................................................................................................................27

4.5 Audio Amplifier .....................................................................................................................27

Page 4: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

3

5. Final Cost, Schedule and Conclusion .....................................................................................................29

Appendix i ..................................................................................................................................................30

Appendix ii .................................................................................................................................................35

Appendix iii ................................................................................................................................................36

Appendix iv ................................................................................................................................................78

Page 5: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

4

1. Introduction

As the world becomes more energy efficient, personal responsibility to monitor energy

consumption in the home becomes more important. Reducing our impact on the environment

can be achieved by eliminating wasteful electricity practices, especially those of consumers.

One benefit of implementing smart grids is the ability to assist electricity providers in regulating

demand during peak hours. By controlling how much energy consumers use, power companies

do not need to install new power plants to relieve stress on the current power grid. Also, the

electricity provider needs to interact with consumers in a manner that is universal for all users

including those with disabilities. An energy monitoring device that can be placed in a

consumer’s home needs to have accessibility features such that visual, hearing, and motoric

impaired persons can operate.

1.1 The AHEAD Module

The AHEAD module is a central, universally accessible device that receives and

responds to smart meter signals to provide consumers with the ability to control in-home

devices. Although there have been solutions for the need of home automation, the inclusion of

accessibility features seem to be always missed. The AHEAD module addresses these

shortcomings and be its main focus while providing home automation functionality.

1.2 Consumers Energy and Smart Grid

Consumers Energy was founded in 1886 by William Augustine Foote. Since then they have

grown into one of the top utilities providers in the nation. They deliver electricity and natural gas

to over 6.5 million customers. The push towards a greener world has lead to their under taking

of the new power delivery system called the Smart Grid. The Smart Grid delivers electricity in

Page 6: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

5

an intelligent way. Consumers Energy has the ability to monitor each costumer’s home through

the new utility meter, the Smart Meter. Information about usage, price, and outages will be

available not only to Consumers Energy, but to the customer as well.

Two of the team members went to the Consumers Energy Smart Home in Jackson, MI.

The members observed how the new Smart Grid technology was able to function with

appliances. The house demonstrated existing technologies with human machine interfaces for

accessing the smart grid; however, all were lacking in accessibility options for people with

disabilities.

Around three of the appliances they had on display actually were smart grid ready.

These were devices that could be controlled by the smart grid itself. Consumers Energy said

they had other devices that haven’t been approved as Smart Grid ready in their workshop.

However, the amount of working appliances that are smart grid ready is very limited at this

time.

1.3 X10 Home Automation

The X10 set of devices are an established solution for home automation purposes. The

units along with a controlling interface make up a system that sends signals through existing

power lines in a home. The units only need to connect to a wall outlet. Software provided by

X10 could be used with the devices, or a user could utilize push-button remotes instead. These

systems have been proven to function well at its basic job; however, for someone with

disabilities it is difficult to use. The AHEAD module would be a stand alone system that could

interact with the modules without having a separate computer or the need for other devices.

The interaction between the modules is done through a transceiver that hooks up via

serial communication port. The transceiver then sends a radio signal to a receiver plugged into

an outlet somewhere in the home. The transceiver then packages the data into a Power Line

Carrier (PLC) signal to send to the other units in the home. Through this communication,

appliances within the home can be controlled with the addition of X10 modules.

Page 7: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

6

2. Design Solution

The project the team was faced with was designed from scratch. This made the overall design

open ended, but it required specific aspects as well. The team first came together to brainstorm

different parts of the project along with coming up with some questions to ask their sponsor.

Then after meeting with the sponsor and getting their questions answered they had a more

complete idea of what was to be included in the project. The design needed to be able to

monitor electricity usage, report that information, allow the user to take action regarding home

automation settings, and overall be a universal design.

2.1 Managing Energy Consumption

Our device needs to be able to receive and interpret power consumption information

from a simulated Smart Meter, which is controlled and monitored by the power utility. The

device needs to display this data as a readable text on its screen. This information could

include the amount of power that is consumed by the user’s appliances in the unit of kilowatts

per hour or if the user prefers, the current cost of that power in the unit of dollars per hour and

the estimated bill. Moreover, the device can be set up to automatically control the appliances

state or provide a manual overrides. When one of the automatic modes are activated then the

AHEAD device needs to turn off pre-selected appliances that consume most of the power (such

as a dryer or the water heater) during peak demand periods and turn them on during low

demand periods. However, if the user wanted these devices on they needs to be able to do so

through manual overrides.

2.2 Accessibility

The most critical aspect of this design and the primary purpose of our device needs to

provide easy accessibility to people with disabilities. Our device needs to provide several

methods to achieve this purpose. For people with visual disabilities, the device needs to have

Page 8: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

7

an option of converting what is being displayed on the screen into a voice output via text-to-

speech software. These people have access to the control features of this device through the -

touch screen. This could either be done through a hardware IC or software based. There will be

a built in flashing LED that will notify the people with hearing disabilities of the status. This

device needs to be accessible to people with motoric disabilities through an optional sip and

puff system. An actual sip and puff system seemed to expensive to purchase. So instead the

system may use a switch access style of interface. For the most basic of use, a single switch

scanning method would be used.

2.3 Design

The first method of determining what options had the greatest importance was to

create a design importance matrix. This tool shows where most of the weight of the project will

fall. It can be seen in table 2.1.

Parameter Importance

Information from the utility company 6

Automatic Control 5

Accessibility 7 (most important)

Cost 4

Portability 1 (least important)

Power Consumption 3

Heat 2

Table 2.1 Design Importance Matrix

The results were then put into another powerful tool, a Design Criteria Matrix. Each option was

evaluated to its corresponding importance to give an insight into which options were the right

choices to make. This helped the team hone in to what was to be the final decision in how the

project would be completed. Table 2.2 shows the results the team used.

Page 9: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

8

The first decision was that the platform would be on a netbook rather than an

embedded system. The netbook seemed to make more sense especially when considered with

some of the other aspects that the matrix showed as being important. These included the

software TTS system and touch screen. The team then analyzed the results to form a Function

Analysis System Technique (FAST) Diagram. The FAST Diagram gave the team powerful information

to make a plan to design the AHEAD module. The diagram is located in figure 2.5.

CPU Tactile

Interface Wireless

Communication Visual

Feedback Accessibility Input Device

Audio Playback

Design Criteria W

eigh

t

Embe

dded

Sy

stem

Boa

rd

PC

Touc

h Pa

d

Touc

h Sc

reen

Zigb

ee

RF

Mod

ule

(Sta

nd A

lone

)

w/o

LED

w/ L

ED

w/o

Inpu

t

w/ I

nput

IC

Softw

are

Communication with Utility Company

5 3 3 5 5 5 4 2 4 1 2 2 3

Accessibility 5 2 2 3 5 1 1 3 4 2 5 4 5

Automatic Control 4 5 5 2 2 3 3 1 1 2 2 1 1

Cost 3 4 5 3 2 2 5 1 1 3 3 3 2

Portability 2 4 4 3 3 4 4 5 5 2 2 1 1

Heat 1 4 5 4 4 3 3 5 5 1 1 2 2

Power Consumption 2 3 3 3 4 4 4 5 5 3 2 2 2

Score 75 79 73 82 67 71 57 72 43 61 51 58

Page 10: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

9

Figure 2.5 FAST Diagram

2.4 Budget

The AHEAD module prototype’s initial budget was just around the designated amount.

Through the semester, the basic part list stayed close to the projection. Table 2.1 shows the

rankings of the above parameters based on their importance to the customer.

Part Cost Netbook PC $220 Touch Screen Overlay $85 X10 USB Module $10 X10 Receivers(4) $80 Microcontroller $0 Packaging $30 RF Modules $60 Watt-meter $20

Total: $505 Table 2.1 – The Initial Budget

Page 11: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

10

2.5 Gantt Chart

Figure 2.5 – Gantt Chart

The team was able to keep on schedule with their proposed gantt chart through the

semester. This is one of the reasons for their projects success. The chart can be seen in Figure

2.5.

Page 12: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

11

3. Technical Implementation

The AHEAD module had a basic structure thanks to the Design Matrices and FAST

Diagram. The team then put together a block diagram to give the actually design a structure.

This can be seen in Figure 3.1.

3.1 Software Interface and Design Requirements

Figure 3.1 Block diagram of conceptual design

Hardware

3.1 Visual Alerts

In order to provide visual notifications, we used LED status indicators. We used a red

and green LED, representing unread message notifications and power usage respectively. The

LEDs needed to be able to be pulsed at different rates in order to provide meaningful visual

feedback. The message notification light allows the user to become aware of new alerts quickly

and without having to directly interact with the device to find out. By pulsing the green LED

Page 13: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

12

more rapidly, we could signal higher rates of energy use. This increases the user's awareness of

excessive power usage, and allows them to make informed decisions based on that

information.

The LEDs are controlled by a microcontroller with an RS232 interface to the PC. In order

to conserve space and minimize the amount of parts necessary, we decided to control the LEDs

with the same PIC as the audio amplifier. The C code used to program the LED function can be

found in the appendix.

3.2 Touch Interface

Providing a simple way for users to interact with our device was crucial to the success of

AHEAD. Using a touchscreen allowed us to maximize the amount of visual information we could

show while giving the user a large control interface that is easy to use. In order to implement

this, we used a touchscreen overlay.

3.3 Touchscreen Overlay

The Hoda 8.9" touscreen overlay consists of a transparent resistive touchpad meant to

be placed over the screen. This overlay attaches to the touch-hub controller, which replaces the

internal USB connection between the built-in web-cam in the netbook. This touch-hub

controller provides additional USB ports for reattaching the built-in camera or other

peripherals, though we did not choose to do so. Most importantly, the controller board digitizes

the touch input from the overlay, converting it into a mouse input signal that the operating

system can recognize. The overview of this can be seen in Figure 3.1

Page 14: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

13

Figure 3.1 – Touch Screen Overlay

The installation required us to dismantle the notebook PC and remove the keyboard and

metal heatsink in order to expose the motherboard. We traced the black monitor cable and

unplugged it. After doing so, we removed the screen chassis and unscrewed the LCD mounting

bracket and removed the LCD screen. Once the screen was gone, we were able to access the

built-in camera cable, and removed it. In its place, we inserted the touch-hub controller board.

Following that, we used double-sided tape to attach the touchscreen panel to the LCD

screen we extracted, and lined the edges with the rubber mounting strips provided with the

overlay. By using the screws and nuts that were previously used to hold the monitor housing

together, we were able to utilized the front panel of the screen casing to secure the touch

overlay to the LCD screen. We then placed it into our enclosure, along with a foam layer

between the screen and our metal mounting brackets. This foam layer is needed create the

necessary pressure to prevent it from moving during use.

Finally, after the brackets were in place, we connected the ribbon cable from the

overlay to the touch-hub controller, and attached it to our enclosure.

Page 15: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

14

3.4 XBee Serial Communications

For the simulation of a smart meter, we choose the XBee 802.15.4 OEM RF module to

create a simple serial link between our simulated smart meter and the AHEAD device. XBee RF

modules are useful in transferring low data rates and where low-power consumption is

necessary and has the ability to accept UART data directly from Visual Basic. The XBee 802.15.4

RF modules operate in the unlicensed 2.4 GHz industrial, scientific, and medical (ISM) band.

Meaning the 10-bit RF data packet structure follows the IEEE 802.15.4 specifications. The two

most common methods of interfacing serial data to the RF module are through the serial port

of a PC and by microcontroller. We choose to connect the RF module to a Visual Basic program

via a personal computer for demonstrating the accessibility of the AHEAD device. This allowed

us the ability to change energy prices and send messages on the fly to show how the device

would react to events from the utility provider.

Using a PC to host the UART signal requires that it must first have the RS-232 voltage

converted to TTL/CMOS logic voltages. Figure 3.2 is the circuit design of the RS-232 interface to

the XBee RF module.

DB

9 Serial Port

MA

X232

Xbee

OEM

RFM

odule

Figure 3.3- is the circuit schematic for serial transmission

This design was used in the AHEAD device as well as in the simulated smart meter. Logic level

conversion was achieved by using a MAX232 integrated circuit. Pins 2 (RXD) and 3 (TXD) from

the DB9/RS-232 interface connect to pins 14 (TX) and pins 13 (RX) respectively on the MAX232

Page 16: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

15

for conversion. Capacitors are required on the MAX232 chip and the layout can be seen in the

circuit schematic. All capacitors are 1 µF electrolytic and pin placement are as follows; pins 1/3,

4/5, 2/16 and 6/ground. 5 Volt supply voltage is at pin 16. Take care in the voltage outputs from

the MAX232 to the XBee for the XBee requires CMOS logic with voltage levels between 2.8 and

3.4 VDC. We incorporated a voltage divider between the output of the MAX232 and the input

pin on the XBee. A 10k ohm in parallel with an 18k ohm resistor resulted in the 5 volt output to

3.2 volt input to the XBee.

3.5 Audio Amplifier

Due to the technical nature of this section it has been included into the Appendix

section.

Software

The AHEAD device required a lot of different design requirements that hardware would

be too cumbersome to solve with. The design would require that we implement a user

interface that included accessibility options and home automation control. These being the

main two aspects of the project made the software very complex and large in magnitude.

The accessibility options included three main areas. The first was text-to-speech; this

would add the ability for people with serious problems with, or no sight at all to be able to

operate the device no problem. The AHEAD device needed to provide the audio feedback that

would allow this to occur. Next is the visual alerts system. The visual alerts were for people who

still retain their sight, but may have trouble being able to distinguish when there is new

information present. The last option was switch access for the interface. This is the ability to

interact with the program through either a single, or a few, switch(s) to navigate. This is most

beneficial to people with motoric disabilities.

The entire interface had to be designed around these major aspects of accessibility. This

meant that each button and menu option had to be easy to navigate and have an easy learning

Page 17: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

16

curve. Also, since the main interface was going to be through software by graphical means the

program needed to support touch screen operation.

The home automation process needed to occur through software. The program had to

be able to interface the X10 Transceiver through wireless communication. Also, it had to

monitor the incoming transmissions from a simulated smart meter. These two things needed to

be combined to give the AHEAD device the ability to do home automation.

The programming API we chose was Visual Basic .NET 2003. The Visual Basic .NET code

was relatively easy to understand syntactically and comprehend. However, it was also a very

powerful means of creating windows forms and accomplishing a great deal with a minimal

amount of overhead to get in the way of completing the project.

3.6 Interface

One of the problems with creating applications with Visual Basic .NET is the fact that

they always seem plain and uninviting. The basic components don’t give many options when it

comes to creating a custom interface. An example of this can be seen in Figure 3.4. The typical

gray background and blue title bar wasn’t enough for us.

Figure 3.4 – Visual Basic .NET Form

Page 18: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

17

We wanted to get away from this pitfall so that people who are interested in our project

can see that accessibility options can be part of a sleek design. So we had to look into different

options to find what worked well for the AHEAD Module. The first attempt was to find an

ActiveX componenet that allowed us to utilize some customization options, but this proved

futile. We were then forced to do everything manually, which will be described next. A sample

of what our interface looks like can be seen in Figure 3.5. This is how we chose our interface to

look, and it took some tweaking to get it how we wanted.

Figure 3.5 – Customized Windows Form

The easiest customization was the background. After a little time spent with Adobe

Photoshop, the team was able to put together a background that would look fine tuned for the

project. Once completed, the form properties only needed to be updated to include this

background.

Customized buttons were the hardest part to implement. Again, these needed to be

created in Adobe Photoshop using basic shapes and blending properties. The first attempt was

Page 19: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

18

to just make one button and use it as the background to the standard windows form button.

However this resulted in an undesirable box surrounding the button when text was to be

overlaid on the background. After testing what caused this box, it was determined that the Flat

style had to be set to the Flat option to get rid of the initial box as well as the Fore Color

Property had to be set to Transparent to remove a box. Setting the Fore Color to transparent,

however, made it impossible to write text over the background image for the buttons. There

was nothing that could be done through Visual Basic .NET itself.

The team then used the brute force method of creating each button separately. This

meant that every button the user interacts with was created separately; excluding the close

button which is used more than once. Through Adobe Photoshop, the text was applied to each

of the needed buttons.

Another problem arose when it was determined that the user is going to need some sort

of visual stimulus to let them know what button or object was currently selected. This was

especially important when using the Switch Access option which will be explained later. The

images were then edited to give off a sort of glow from their text descriptions. The two button

samples can be seen in Figure 3.6.

Figure 3.6 – Non-selected Button (Left) and Selected Button (Right)

3.7 Accessibility Features

The accessibility features for the AHEAD device were one of the main points of the software.

There was a separate menu created to turn each of these options on or off. The implementation of the

Text To Speech (TTS) software went from a complicated design to a rather simple solution. The first

attempt was to use the Microsoft API and design a text to speech program from scratch. After we

Page 20: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

19

investigated this option it was determined that it would be too cumbersome to take on and an alternate

solution was sought after. This lead to the discovery of a free program entitled DSpeech. The program

had the ability to monitor the systems Clipboard for changes and would turn the text into speech. The

idea was then to utilize this feature in our design. At each point the program needed to tell the user

something through TTS, the string of text was sent to the clipboard, and thus DSpeech would turn it into

speech. The results were very good for this combination. There was testing of other software that also

monitored the system Clipboard, however, if the contents changed while it was outputting speech it

would miss the new string. Dspeech would notice the change, stop its current output, and move on to

the current output.

The switch access was implemented from scratch in code. The basic of the idea was to keep one

variable in different states to let the program know how many times the switch had been pressed. When

the button was pressed, depending on the state of the variable, th e program would take certain

actions. A timer was implemented as a way to make these actions occur on an interval of 100

microseconds. The zero state was to have the switch access turned off; if the user pressed the switch

during this time it would turn on the switch access and allow the variable to enter the next states. The

main navigating state, state one, just kept moving to the next menu choice in accordance to the timer.

This was done by using the SendKey() function, and sending the TAB key. Since each item that was

desirable to access had a tab index, this was a viable solution. If the switch was hit again, the program

would recognize this as the second stage; it would then stop at the current selection and if the TTS

options was turned on, ask the user if this was what they wanted. If the user didn’t hit the switch again

after three seconds the program would then being navigating through the menu choices again.

However, if the use pressed the switch again indicating this was the correct selection, it would enter the

next phase and use the SendKey() method again to send the ENTER key. Then once the choice was

registered, it would return back to stage one to start navigating again. It was also thought of that an

automatic turn off would be a helpful feature. So after the program hasn’t received any input from the

switch for thirty seconds it will automatically shut off. The code for this can be seen in the Appendix.

3.8 X10 Home Automation

The X10 communication was done through the Firecracker RF unit that attached through a serial

port on the computer. The X10 Firecracker does not send a signal like a normal serial output. Instead of

Page 21: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

20

using the dedicated data lines it uses the RTS and DTR pins on the serial port. This allows a second serial

device to be connected onto the firecracker as long as the second device does not need the RTS and DTR

pins. The Firecracker is powered by keeping either the RTS or DTR line high or logical ‘1’. This was an

important factor in writing the software for this portion. Also, timing is extremely important when

sending the signal and because of this the Sleep() function had to be used in the project. This ensured

that the signal was sent on the correct timing scheme needed. The code for the sending data can be

seen in figure 3.7.

Figure 3.7 – SendBits Function for communicating with the X10 devices.

The home automation was then taken care of by monitoring a signal coming on the same COM

port from the simulated smart meter. Once the program noticed this change it would update the cost,

check the price thresholds and send out the corresponding data to have appliances turn on or off.

Thresholds were taken care of in preset and custom modes. The preset modes were hardcoded

into the program to give ease of access right out of the box. There was also a custom setting that

allowed the user to enter their desired price thresholds in for each appliance. This was done through an

on-screen number pad.

3.9 Smart Meter Simulation

The simulated Smart Meter needed software to send information to the AHEAD module.

It was also written in Visual Basic .NET for ease of integration. The final design sends out data

Page 22: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

21

every one second. This data is a Message Header, the Message, a Cost header, and the Cost.

The header is put into a container with the first character being either an @ symbol meaning

it’s a message, or a # symbol meaning it’s the cost. Then the next characters are the length of

the message, or cost respectively. This is then followed by a ^ symbol for both types of data,

this character represents the end of the header and the beginning of the message. After the

header, the actual message or cost is then sent. The receiving side, the AHEAD module, reads in

one character at a time. If it recognizes there is an @ or # symbol it knows weather its going to

be a message or cost respectively. It then reads in the next characters until it hits the ^ symbol.

The string it gathered in between the symbols is then casted to an integer and used to know

how long the message or cost is and reads in that many characters instantly. The code example

can be seen in the appendix

3.10 Gestures

By using a touchscreen as opposed to another UI control scheme such as a keypad, we

sacrificed tactile feedback. In order to increase usability for visually impaired users, we

implemented software-based gesture recognition. This allows the user to interact with our

device without having to visually identify the physical locations of UI objects in our program.

The algorithm we used involves the following steps:

data acquisition

filtering

vectorization

matching

The first step is simple: recognize the user input to the device. Since our touchscreen

only registers when the screen is depressed, we start data acquisition as soon as the user

presses down. The second step, filtering, is used to remove unintentional movement artifacts.

These artifacts would include small movement of the finger while attempting to click a button,

Page 23: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

22

or unsteady motion of the hand while trying to perform gestures on the screen. Next, we

converted the captured data points into vectors by simply calculating the angle and magnitude

of movement over a single sample period. Finally, the matching algorithm attempts to match

the vector list to a predefined gesture library.

Figure 3.8: Data acquisition and filtering process

Figure 3.9: Vectorization of data points and conversion to cardinal directional vectors

Figure 3.10: Illustration of matching and pare-down process

Page 24: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

23

In our program, we set it to poll for mouse position on mouse click. Since our

touchscreen only has one mode of interaction, equivalent to a single mouse button behind held

down, our program had to distinguish between unintentional slipping of the finger and

deliberate gestures. In order to provide this distinction, we added a minimum distance

threshold in order to trigger gesture recognition which was sufficiently higher than the

maximum amount of translation that would occur during a single click, which corresponds

roughly to the size of the buttons in our interface. Another issue that we needed to solve during

the filtering phase was motion artifacts from unsteady muscle movement. The default windows

mouse polling rate (125 Hz) is high enough that such movement is easily encoded into the

intentional mouse movement we wish to acquire. In order to solve this, we set the acquisition

rate to 25 Hz, or once every 40 milliseconds. By doing so, we can smooth out the incoming data

and reduce the complexity of our calculations.

Once we have filtered the datapoints, we start the vectorization process. This is done by

simply finding the distance between points and filling an array with these points. In order to

simply our matching algorithm even further, we compare the projection of the vectors onto the

X and Y axis, and record the greater value. By doing so, we reduce the range of motion to up,

down, left and right. Finally, we perform the matching phase, which compares the direction of

the vectors to the predefined list of gestures. If no match is found, the vector with the smallest

vector will be removed, and the match process repeats, until a match is found. In order to

prevent false positives, this iteration procedure will stop after the captured data is reduced to

less than 40% of its original size. If a match is found, the program then executes the predefined

function.

Once the algorithm was working, we added it into the program. Currently, the following

gesture library contains the following functions:

Page 25: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

24

Gesture Function

Left Navigate left in menu

Right Navigate right in menu

Up Go back in menu level

Down Confirm choice Table 1 – Touchscreen Gestures

The gesture library is designed to be extensible and can be easily added to. A subroutine

parses a string containing “U”,”D”,”L”, and “R” to up, down, left and right, and executes the

function defined. Although our algorithm can recognize gestures with multiple direction

changes, we felt that it would be more intuitive and useful for disabled users to have a very

simple gesture list, reducing the learning curve required to operate the device. This gesture

functionality is meant to couple with our text-to-speech feature closely, and reads out the

highlighted button as you navigate left and right. These two features combined constitute an

example of universal design; increasing the accessibility of our device to all users regardless of

ability.

Page 26: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

25

4. Testing

The testing phase of the process was usually included when the team was prototyping

the AHEAD module.

4.1 Interface Testing

The interface was tested to ensure proper navigation and execution. Although most of

the functionality was underneath the interface it was important to make sure every aspect

could be accessed. This was done by clicking every button and navigating to every option. The

results showed a few errors with not hiding buttons when a certain option was active, or the

button not doing what it was supposed to do. The code was then corrected at each instance.

4.2 Accessibility

The accessibility options were tested very similarly to the interface. Since these options

were designed around helping those with disabilities navigate and interact with the device,

every option had to be explored again. The text to speech option was going through every

menu making sure it was possible to hear a voice output of every object that was selected. And

in the same time the switch access was tested. As it navigated to every available option it was

easy to test the TTS as well. Simple problems of Tab Index being out of order were found as well

as the phases of the switch access sometimes not corresponding correctly. The code was then

examined by outputting what phase, and what code was being executed into available text

boxes. Only one line had to be switched from changing it to phase zero, when it should have

been phase one.

4.3 Smart Meter

The Smart Meter was tested first on the same computer for ease of programming. The

XBEE units correctly connected to each other and were sending data. The smarter meter

Page 27: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

26

software appeared to be done. However, later in the project’s design phase the software was

then tested again. This time the XBEE units were put on different machines to simulate the

actual set up for the prototype. The units connected to each other correctly, but were unable to

correctly send information. The first problem came when the program tried to cast what it

thought was the header into an integer with the Cint() function. This caused failure when the

receiving unit started reading somewhere other than the start of the buffer. A Try/Catch was

implemented to see if it would ever sync back up, however the data received was always

unusable at this point.

The software was then rewritten as explained in section 3.2.d. This was initially designed

using two machines to avoid the problem that occurred in the first iteration. The messages and

cost were then sent at different rates to find the right settings. This proved the best way to set

up a fast and reliable communication link. The results can be seen in Table 4.1.

Smart Meter Send Timer

AHEAD Receive Timer Results

100ms 100ms AHEAD couldn’t receive current information, buffer overflowed.

100ms 10ms Send buffer still filled up too quickly for the reading to catch up.

3000ms 10ms AHEAD could receive information, but the sender updated information too slowly.

1000ms 10ms Minimal delay between real time Smart Meter updates and AHEAD information received.

Table 4.1 – Wireless timing interval tests

The communication set up was then tested for longevity. The code from Figure 3.6 was

modified to switch the cost and messages every 10 seconds. It was then left alone for a while to

make sure the data was still being transmitted, and if it did get off synch, see if it could get back

Page 28: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

27

on track. The results were positive for the test software, and then the code was implemented

into the AHEAD interface.

The same tests were then repeated to make sure the same results would be yielded. It

was found that with the added complexity of the AHEAD interface software, the best timing

that could be done for the receiving end was twenty-five milliseconds instead of ten. However,

the delay was still minimal and allowed for near real-time updates from the simulated Smart

Meter.

4.4 Home Automation

The AHEAD automation was tested to make sure that when the price increases or a user

made an important change the system would recognize this and respond with appropriate

actions. The communication of the simulated Smart Meter made this testing possible with its

incorporation. The AHEAD was monitored to make sure it read in messages and prices from the

Smart Meter. At first there was system hang experienced when both the X10 Firecracker and

simulated Smart Meter were trying to communicate. This was due to the Sleep() function calls.

This was solved by turning off the Smart Meter communication while the AHEAD module is

sending signals to the X10 units to update their statuses. The AHEAD device was then able to

capture the information and responded to the information correctly.

4.5 Audio Amplifier

We tested both the LM741 Op-Amp Audio Amplifier Circuit and the LM386 Op-Amp

circuit with the oscilloscope. We played the same song in both circuits. Figure 4.3 shows the

differences between LM741 and LM386 circuits. As can be noticed, the output of LM741 is

clipped and more distorted. This is what made us decide on using LM386 as we discussed in

the Appendix iv.

Page 29: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

28

Figure 4.3 – LM471 (Left) and LM386(Right) Results

Figure 4.4 – LM386

Figure 4.5 – Actual LM386 Circuit

Page 30: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

29

5. Final Cost, Schedule and Conclusion

The team was able to complete a working proof of concept with the help of Mr. Blosser

and other faculty. The AHEAD: Accessible Home Energy Automation Dashboard was a success

through Team Two’s effort and determination. The design can be used as a template in which

to create even greater devices. The end product could have a huge impact on the design

process in regards to the inclusion of accessibility features and their importance.

The final cost of the AHEAD module stayed relatively in the estimated budget. The final

cost is the amount it takes to build a prototype of the same functionality as what the team has

produced. The final cost was actually

Page 31: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

30

Appendix i

Technical Roles

Joey Grover

Joey Grover was responsible for the AHEAD software because he was the only Computer

Engineer on the team. The software development included, but was not limited to, the main user

interface, X10 Communication, Smart Meter Simulation software, and accessibility options. Mr. Grover

took input from the team and their sponsor to develop a custom interface that would be the user’s main

interaction. The X10 communication was also given to him to complete. It was his responsibility to make

sure the hardware devices were compatible with Visual Basic .NET code as well. This also led to the

home automation feature of the AHEAD module to be part of his work. The preset and custom

automation modes designed by Mr. Grover are one of the back bone features of the devices

functionality. He ensured that after a user selects a setting for operation the device would take over

and offer a complete automated process. The accessibility options were also a part of Mr. Grover’s

responsibility. This included the Text-To-Speech, switch access, and visual feedback inclusion. He

incorporated existing TTS software to work with the AHEAD module, while he wrote the code for the

visual feedback and switch access from scratch. The single switch access hardware was integrated by

him as well. The visual feedback Visual Basic .NET alerting algorithm that sends information to the

microcontroller at the appropriate times was of his design. He also created the project’s touch screen

gesture first prototype system. The included system still uses the gesture meanings he developed. He

helped with the actually installation of the touchscreen overlay as part of his technical role. Mr. Grover

also stepped in to take care of the Smart Meter Simulation software once problems arose with the

original design. Though it was near the end, Mr. Grover successfully completed a revamped design that

was integrated into the project. The module’s audio amplifier was guided by his supervision after the

initial design fell through. He researched other options that would fit the project, and found the best

Page 32: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

31

alternative for implementation. Along with these specific tasks, Mr. Grover was asked to complete a

wide array of tasks involving the software.

Dennis Wey

Wey's principal role in the AHEAD project was to implement a touch screen interface and design

a system of gesture recognition for the device, facilitating use for visually impaired users and

augmenting the abilities of those without impairment as well.

The initial step in achieving this required Wey to research various touchscreen technology. By

weighing pros and cons such as multi-touch capability, cost and ease of use, Wey decided to use a

touchscreen overlay, mainly since it was less expensive than buying an integrated LCD touchscreen and

widely available. Once the overlay was required, Wey was responsible for taking the netbook PC apart

and installing the overlay for testing purposes, and implementing the gesture recognition feature. In

order to dismantle the PC, Wey attempted to obtain a service manual off of the internet. Following the

instructions, the netbook was carefully taken apart and the touchscreen overlay was installed. Near the

end, Wey aided in modifying the original netbook casing in order to accommodate being placed in the

final enclosure.

The other part of Wey's technical role was designing a gesture recognition system. Initially, Wey

designed the touch algorithm and possible gestures on paper. Then, it was coded and debugged on a

separate machine. By reading the system mouse events available in VB.net, Wey was able to capture

mouse movement data by sampling the data periodically while the mouse button was pressed. Using

ArrayLists, timers and custom cast structures, Wey was able to create a simple yet effective way of

recognizing gestures and allowing for additional gestures to be added as necessary.

Page 33: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

32

In addition to the touchscreen and gestures, Wey was also responsible for the LED notifications.

Using the PIC, Wey programmed it to flash LEDs on command, distinguishing between utility provider

notifications and price level indicators. Working closely with Al-Qudaihi, Wey implemented the LED code

onto the same microcontroller assembly as the audio amplifier, minimizing the amount of COM ports

required by the program and reducing the amount of components in our design. By altering the amount

of for loops between each LED state change, Wey was able to produce the variable flash rates required

to visually encode the price information, with faster rates corresponding with higher usage rates. Using

the same RS232 interface as the audio amplifier, the LED notifications can be controlled via the AHEAD

software.

Ahmad Al-Qudaihi

As Ahmad has strong background in hardware engineering, he was assigned the role of

designing and building an audio amplifier. First step in this process was to build and test the

circuit with a mechanical pot and use a signal from the function generator as an input. The

circuit performed as he expected. The problems occurred after he connected an 8 Ω speaker to

the circuit and used the stereo signal from our device as input. He noticed too much noise at

the output of the speaker, especially at high volume. Ahmad measured the RMS power at the

speaker and it was higher than the rated RMS value. Therefore, he replaced it with a speaker

with a higher wattage rating and enclosed it. The sound became clearer than before. However,

Ahmad faced problems with providing a negative power supply from the PC to power up the

op-amp IC chips. He researched on how to acquire negative voltage from positive voltage.

After analyzing the available solutions, Ahmad concluded that these solutions were not

feasible. He did more research and found a way for the circuit to function with only a positive

Page 34: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

33

power supply. However, after designing, building, and testing it, the new circuit produced more

noise at the output. So, Ahmad looked for and found an IC chip that has the same functionality

as the old circuit design. The team decided to use this IC chip since it did a better job compared

to the old design and has many other advantages as well.

Ahmad was also responsible for programming the microcontroller to communicate with

the digital pot that was implemented in the audio amplifier circuit. This was a challenge for him

because he has much less experience in software engineering and programming than hardware.

This part took him longer than the previous part because, for the microcontroller to

communicate with pot; it has to be set up on a specific mode called the SPI mode. To enable

and initialize the SPI mode, he had to fully understand how the digital pot works and how the

microcontroller functions when it is set up on SPI mode. This was achieved when he

researched, read and understood the data sheets of both devices. One important thing that

was missing in the data sheet was the C code commands that he needed to program the

microcontroller. Eventually, he found a document on the manufacturer’s website that had

examples and explanations of the SPI mode commands, which enabled him to finish the job.

Jason Grimes

Jason Grimes’s technical contribution primarily consisted of providing a method to

simulate a smart meter. This is an important aspect of our project since it is necessary for the

user, regardless of physical limitations to interact with messages from the utility provider. This

method of communication allowed us to create various instances that were not anticipated

events which provided more of a realistic scenario. He designed and implemented the

communication from one personal computer to another using radio transmission. This task also

Page 35: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

34

required having to him to solve problems with the communication to provide the functionality

we desired.

Throughout the semester he was actively involved in the hardware aspect of the

project. This meant reading data sheets and making decisions on what components to use and

how it would affect the project. With having different kinds of components with different

operating voltages, he integrated the components to work together for the prototype. He also

assisted Ahmad in solving issues with operating voltages and distortion problems in the audio

amplifier. He constructed all of the circuits for the AHEAD device and tested each circuit before

being housed into the enclosure. This also meant having to correct any problems that occurred

during the construction process. Jason worked with Mr. Blosser in the design of the enclosure

and assisted him in getting the enclosure finished.

Along with individual tasks, Jason also worked with the team to construct the prototype

by wiring the circuits together and getting it operational. In order to demonstrate our design,

Jason worked with the team to provide a system for technical demonstration to illustrate the

integration into a home environment.

Page 36: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

35

Appendix ii

1. “Department of Energy - Smart Grid.” United States Department of Energy. 2006. United States Government. 1 Feb. 2010. <http://www.oe.energy.gov/smartgrid.htm>.

2. "GE Energy Services; GE Smart Grid Technologies Build Sustainable 21st Century Cities." Energy & Ecology 26 Feb. 2010: Sciences Module, ProQuest. Web. 18 Feb. 2010.

3. Farkas, Suzanne. "Access by design: interview with Pam Cluff, FRAIC, FRIBA, OAA, pioneer in the movement for accessibility by design." WE International. 1 Jan. 1999: Research Library Core, ProQuest. Web. 24 Jan. 2010.

4. Rigg, Sarah A. “AMI technology a foundation of smart grid, helps consumers cut bills”

Mlive.com. 2009 17 Feb 2010. http://www.mlive.com/business/ann-

arbor/index.ssf/2009/03/ami_technology_a_foundation_of.html

5. CM17A Protocol." X10. N.p., n.d. Web. 31 Mar 2010. <ftp://ftp.x10.com/pub/manuals/cm17a_protocol.txt>.

6. Davis, Adam. "CM17A Protocol." Adam Davis. N.p., 25 Jan 2008. Web. 31 Mar 2010. 7. <http://www.ubasics.com/adam/electronics/cm17.shtml>.

8. Maxstream XBee/XBee-PRO Product Manual, v1.xAx - 802.15.4 Protocol, Digi International, Web: April 28, 2010 <http://ftp1.digi.com/support/documentation/manual_xb_oem-rf-modules_802.15.4_v1.xAx.pdf >

9. MAX232, MAX232I DUAL EIA-232 DRIVERS/RECEIVERS, Document SLLS047L, Revised March 2004, Texas Instruments, Web: April 28, 2010 <http://focus.ti.com/lit/ds/symlink/max232.pdf >

10. "EPC 901 Installation Guide". Hoda Technology. Hoda Technologies Taiwan Limited, Nov 2008.

11. Dimo. "Dimo's Tools". March 13, 2010 <http://dimio.altervista.org/eng/>.

Page 37: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

36

Appendix iii

The windows designer code was removed from each form to save on space.

Template.VB

_____________________________________________________________________________ Imports System.IO Imports System.Reflection Public Class Template Inherits System.Windows.Forms.Form Structure Vector Dim Magnitude As Integer Dim Direction As Char End Structure Public gVector As ArrayList Public capturePoints(128) As Point Public capCounter As Integer Public emptyPoint As Point Public test As Boolean 'The template form is used so that all forms could use a universal design. ' 'It also includes the code of the touchscreen gestures. Through vectorizing 'different points, the program can distinguish which way the user swipes. 'This is the main way of interacting for visually impaired people. Private Sub Template_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load KeyPreview = True Dim points As Point Dim i emptyPoint.X = -1 emptyPoint.Y = -1 For i = 0 To UBound(capturePoints) capturePoints(i) = emptyPoint Next gVector = New ArrayList tempTime.Interval = 40 End Sub Private Sub vectorizePoints() Dim xDiff As Integer = 0 Dim yDiff As Integer = 0 Dim item As Vector Dim temp As ArrayList = New ArrayList Dim i As Integer

Page 38: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

37

Dim capLength = CInt(Array.IndexOf(capturePoints, emptyPoint)) For i = 0 To (capLength - 1) If capLength >= i + 2 Then xDiff = capturePoints(i + 1).X - capturePoints(i).X yDiff = capturePoints(i + 1).Y - capturePoints(i).Y If System.Math.Abs(xDiff) > System.Math.Abs(yDiff) Then If xDiff > 0 Then item.Direction = "R" Else item.Direction = "L" End If item.Magnitude = System.Math.Abs(xDiff) If item.Magnitude > 14 Then temp.Add(item) End If ElseIf System.Math.Abs(xDiff) < System.Math.Abs(yDiff) Then If yDiff > 0 Then item.Direction = "D" Else item.Direction = "U" End If item.Magnitude = System.Math.Abs(yDiff) If item.Magnitude > 14 Then temp.Add(item) End If End If End If Next If temp.Count > 0 Then gVector.Add(temp(0)) For i = 1 To (temp.Count - 1) If temp(i).Direction <> gVector(gVector.Count - 1).Direction Or ((temp(i).Magnitude < 0) <> (gVector(gVector.Count - 1).Magnitude < 0)) Then gVector.Add(temp(i)) Else item.Direction = temp(i).Direction item.Magnitude = CInt(gVector(gVector.Count - 1).Magnitude + temp(i).Magnitude) gVector(gVector.Count - 1) = item End If Next End If End Sub Private Sub Template_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown Dim i capCounter = 0 gVector.Clear() For i = 0 To UBound(capturePoints) capturePoints(i) = emptyPoint

Page 39: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

38

Next tempTime.Start() End Sub Private Sub Template_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp tempTime.Stop() Dim v As Vector If capCounter > 1 Then vectorizePoints() End If parseGesture(gVector) capCounter = 0 End Sub Private Sub parseGesture(ByVal inputGesture As ArrayList) Dim foundIndex = 0 'non match Dim searchString As String = "" Dim initialSize As Integer = inputGesture.Count Dim i As Integer Dim v As Vector While (inputGesture.Count > CInt(0.4 * initialSize)) searchString = "" For Each v In inputGesture searchString = searchString + CStr(v.Direction) Next Select Case searchString Case "U" SendKeys.Send("x") 'Me.Close() Exit Sub Case "D" SendKeys.Flush() SendKeys.Send("{ENTER}") Exit Sub Case "L" SendKeys.Flush() SendKeys.Send("+{TAB}") Exit Sub Case "R" SendKeys.Flush() SendKeys.Send("{TAB}") Exit Sub Case Else Dim min = 1025 Dim minIndex = 0 For i = 0 To inputGesture.Count - 1 If inputGesture(i).Magnitude < min Then min = inputGesture(i).Magnitude minIndex = i End If Next If inputGesture.Count <= 0 Then

Page 40: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

39

Else inputGesture.RemoveAt(minIndex) End If End Select End While End Sub Private Sub Template_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown 'This is to make sure that the switch access is always in the right state ' ' If e.KeyCode = Keys.P Then If sss_check = 3 Then sss_check = 4 ElseIf sss_check = 0 Then sss_state = True sss_check = 1 ElseIf sss_check = 1 Then sss_check = 2 End If End If End Sub Private Sub tempTime_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tempTime.Tick Dim LocalMousePosition As Point LocalMousePosition = Me.PointToClient(Cursor.Position) If capCounter < UBound(capturePoints) Then capturePoints(capCounter) = LocalMousePosition capCounter = capCounter + 1 End If End Sub Public Function GetImage(ByVal filename As String) 'This function well allow the program to access the images in the resources 'Images need to have BuildAction = Embedded Resource. 'The function takes in a string that should be equal to the file name 'It is important the file name is exactly how it appears in the Solution Explorer ' **************IT IS CASE SENSATIVE******************* Dim Asm As [Assembly] = [Assembly].GetExecutingAssembly() ' Resources are named using a fully qualified name. Dim strm As Stream = Asm.GetManifestResourceStream(Asm.GetName().Name + "." + filename) Dim img As Image = Image.FromStream(strm) Return img

Page 41: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

40

End Function End Class

Page 42: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

41

AHEAD.VB _____________________________________________________________________________ Public Class AHEAD Inherits WindowsApplication2.Template 'Access to other forms Dim ModeSelect As New ModeSelect Dim Settings As New Settings 'Switch Access Dim tick_count As Integer Dim off_count As Integer 'For X10 - Timer2 Dim CheckState As Integer 'Smart meter communication Dim Readin As String Dim ReadCount As String Dim msgtype As Integer Dim phase As Integer Private Sub AHEAD_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load X10.InitX10() 'Set and start timers 'Note: Timer 3 is started at the end of timer 2's run phase If Timer2.Enabled Then Timer2.Stop() End If CheckState = 0 Timer1.Interval = 100 Timer2.Interval = 1000 Timer3.Interval = 25 Timer1.Start() tick_count = 0 Timer2.Start() off_count = 0 'Accessability tts_state = False 'Initilize all accesability features off sss_state = False vis_state = False sss_check = 0 Price = 0.45

Page 43: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

42

PriceLbl.Text = FormatCurrency(Price, 2) 'Smart Meter Readin = " " ReadCount = " " msgtype = 0 phase = 0 green(1) End Sub #Region "Button Focus" 'The button focus area is where two actions take place. '------------------------------------------------------- 'The first is the switching of background images. Since the interface 'was designed so that it would not feel like a basic windows form, custom 'button images were used. And the way .NET set it up, each button had to 'be done individually. ' 'Second, this is where the program is told to announce what button 'currently as focus for TTS use. Private Sub CurrBtn_GotFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CurrBtn.GotFocus Speak("Current Status") CurrBtn.Image = GetImage("CurrentStatusSelect.png") End Sub Private Sub CurrBtn_LostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CurrBtn.LostFocus CurrBtn.Image = GetImage("CurrentStatus.png") End Sub Private Sub ModeBtn_GotFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ModeBtn.GotFocus Speak("Mode Select") ModeBtn.Image = GetImage("ModeSelectSelect.png") End Sub Private Sub ModeBtn_LostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ModeBtn.LostFocus ModeBtn.Image = GetImage("ModeSelect.png") End Sub Private Sub SettingsBtn_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles SettingsBtn.GotFocus Speak("Settings") SettingsBtn.Image = GetImage("SettingsSelect.png") End Sub Private Sub SettingsBtn_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles SettingsBtn.LostFocus SettingsBtn.Image = GetImage("Settings.png") End Sub Private Sub OvrBtn_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles OvrBtn.GotFocus

Page 44: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

43

Speak("Appliance Overrides") OvrBtn.Image = GetImage("OverridesSelect.png") End Sub Private Sub OvrBtn_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles OvrBtn.LostFocus OvrBtn.Image = GetImage("Overrides.png") End Sub Private Sub clsBtn_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles clsBtn.GotFocus clsBtn.Image = GetImage("CloseSelect.png") Speak("Close?") End Sub Private Sub clsBtn_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles clsBtn.LostFocus clsBtn.Image = GetImage("Close.png") End Sub #End Region #Region "Override focus and key down events" Private Sub whChk_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles whChk.GotFocus whChk.BackColor = System.Drawing.Color.Firebrick Speak("Override water heater setting?") End Sub Private Sub whChk_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles whChk.LostFocus whChk.BackColor = System.Drawing.Color.Transparent End Sub Private Sub dChk_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles dChk.GotFocus dChk.BackColor = System.Drawing.Color.Firebrick Speak("Override dryer setting?") End Sub Private Sub dChk_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles dChk.LostFocus dChk.BackColor = System.Drawing.Color.Transparent End Sub Private Sub fChk_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles fChk.GotFocus fChk.BackColor = System.Drawing.Color.Firebrick Speak("Override freezer setting?") End Sub Private Sub fChk_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles fChk.LostFocus fChk.BackColor = System.Drawing.Color.Transparent End Sub Private Sub lChk_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles lChk.GotFocus lChk.BackColor = System.Drawing.Color.Firebrick Speak("Override lights setting?")

Page 45: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

44

End Sub Private Sub lChk_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles lChk.LostFocus lChk.BackColor = System.Drawing.Color.Transparent End Sub Private Sub whChk_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles whChk.KeyDown If e.KeyCode = Keys.Enter Then whChk.Checked = Not (whChk.Checked) Speak("Water Heater Override is turned " & State(whChk.Checked)) End If End Sub Private Sub fChk_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles fChk.KeyDown If e.KeyCode = Keys.Enter Then fChk.Checked = Not (fChk.Checked) Speak("Freezer Override is turned " & State(fChk.Checked)) End If End Sub Private Sub lChk_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles lChk.KeyDown If e.KeyCode = Keys.Enter Then lChk.Checked = Not (lChk.Checked) Speak("Lights Override is turned " & State(lChk.Checked)) End If End Sub Private Sub dChk_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dChk.KeyDown If e.KeyCode = Keys.Enter Then dChk.Checked = Not (dChk.Checked) Speak("Dryer Override is turned " & State(dChk.Checked)) End If End Sub #End Region #Region "Button Clicks" Private Sub CurrBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CurrBtn.Click Speak("The current price is " & PriceLbl.Text & ". The current usage is " & Usage() & "killowatts per hour. " & "Current messag is " & msg.Text) End Sub Private Sub ModeBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ModeBtn.Click ModeSelect.ShowDialog() End Sub

Page 46: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

45

Private Sub SettingsBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SettingsBtn.Click Settings.ShowDialog() End Sub Private Sub OvrBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles OvrBtn.Click whChk.Visible = True dChk.Visible = True fChk.Visible = True lChk.Visible = True CurrBtn.Visible = False ModeBtn.Visible = False SettingsBtn.Visible = False OvrBtn.Visible = False clsBtn.Visible = True End Sub Private Sub clsBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clsBtn.Click whChk.Visible = False dChk.Visible = False fChk.Visible = False lChk.Visible = False CurrBtn.Visible = True ModeBtn.Visible = True SettingsBtn.Visible = True OvrBtn.Visible = True clsBtn.Visible = False WaterHeaterOver = (whChk.Checked) FreezerOver = (fChk.Checked) DryerOver = (dChk.Checked) LightsOver = (lChk.Checked) If Not (WaterHeaterOver()) Then whLbl.Text = State(WaterHeaterOn) Else whLbl.Text = "Override On" End If If Not (DryerOver()) Then dLbl.Text = State(DryerOn) Else dLbl.Text = "Override On" End If If Not (FreezerOver()) Then fLbl.Text = State(FreezerOn) Else fLbl.Text = "Override On" End If If Not (LightsOver()) Then lLbl.Text = State(LightsOn)

Page 47: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

46

Else lLbl.Text = "Override On" End If 'Run the price check timer in case of overrides If Timer2.Enabled Then Timer2.Stop() End If CheckState = 0 Timer2.Start() End Sub #End Region Private Sub PriceLbl_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles PriceLbl.TextChanged 'Checks if the price has changed by monitoring the pricelbl 'Takes action if it has If Timer2.Enabled Then Timer2.Stop() End If CheckState = 0 Timer2.Start() End Sub #Region "Timers" Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick ' ' 'This timer and code correspond to the switch access option ' ' tick_count += 1 off_count += 1 Dim clip As IDataObject Dim currentclip As String If sss_state Then If off_count >= 300 Then 'This provides an automatic shut off feature. After 60000ms or 60s the sss_state = False 'switch access will turn off by itself. But can be restarted in the same way sss_check = 0 'as in the begining, by pressing the switch or through the Settings menu tick_count = 0 off_count = 0 ElseIf sss_check = 2 Then 'If the switch as been hit once sss_check = 3 'enter pahse two clip = Clipboard.GetDataObject 'These two lines get what is on the clipboard

Page 48: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

47

currentclip = clip.GetData(DataFormats.Text) ' and returns it into a string so that it ' can be used to send another request to the clipboard tick_count = -10 Speak("Did you want" & currentclip & "?") ' Question mark gives voice upward inflection off_count = 0 ElseIf sss_check = 4 Then ' User has entered that this is the correct pick SendKeys.Flush() ' therefore the code will enter this section SendKeys.Send("{Enter}") tick_count = -5 off_count = 0 sss_check = 1 ElseIf tick_count >= 20 Then sss_check = 1 tick_count = 0 SendKeys.Flush() SendKeys.Send("{TAB}") End If End If End Sub Private Sub Timer2_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer2.Tick 'This section will the current price to see if any appliances need to be turned off 'The reason not all are checked at once is to ensure the RF data is transmitted correctly 'and no overlap occurs in transmissions If Timer3.Enabled Then Timer3.Stop() End If msg.Text = CheckState Select Case CheckState Case 0 WaterHeaterOn = PriceCheck(Price, WaterHeaterThresh, WaterHeaterOver, "A1") If Not (WaterHeaterOver()) Then whLbl.Text = State(WaterHeaterOn) Else whLbl.Text = "Override On" End If Case 1

Page 49: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

48

DryerOn = PriceCheck(Price, DryerThresh, DryerOver, "A2") If Not (DryerOver()) Then dLbl.Text = State(DryerOn) Else dLbl.Text = "Override On" End If Case 2 FreezerOn = PriceCheck(Price, FreezerThresh, FreezerOver, "A3") If Not (FreezerOver()) Then fLbl.Text = State(FreezerOn) Else fLbl.Text = "Override On" End If Case 3 LightsOn = PriceCheck(Price, LightsThresh, LightsOver, "A4") If Not (LightsOver()) Then lLbl.Text = State(LightsOn) Else lLbl.Text = "Override On" End If UseLbl.Text = Usage() & " Kw/h" Timer2.Stop() msg.Text = WaterHeaterOn & "..." & DryerOn & "..." & FreezerOn & "..." & LightsOn Timer3.Start() End Select CheckState += 1 End Sub Private Sub Timer3_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer3.Tick Try 'Just to prevent system hang COM5.Read(1) 'Reads in one character Readin = COM5.InputStreamString Select Case Readin 'Determine if the character is the start/end of the header or something to read in Case "^" 'This is the end character of the header. At this point the amount to read in is determined If msgtype = 1 And phase = 1 Then 'If this is a message COM5.Read(CInt(ReadCount)) msg.Text = COM5.InputStreamString msg.AutoSize = True ReadCount = " " 'Reset the used variables phase = 0 red() ElseIf msgtype = 2 And phase = 1 Then 'If this is a message COM5.Read(CInt(ReadCount)) Price = COM5.InputStreamString PriceLbl.Text = FormatCurrency(Price, 2)

Page 50: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

49

ReadCount = " " 'Reset the used variables phase = 0 End If Case "@" 'Detect its a message header msgtype = 1 Case "#" 'Detect its a cost header msgtype = 2 Case Else 'Detect it is part of the header phase = 1 ReadCount = ReadCount & Readin End Select Readin = " " Catch End Try End Sub #End Region End Class

Page 51: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

50

ModeSelct.VB _____________________________________________________________________________ Public Class ModeSelect Inherits WindowsApplication2.Template Dim CheckState As Integer Dim AcceptState As Integer Private Sub ModeSelect_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Timer2.Interval = 750 Timer2.Start() CheckState = 0 AcceptState = 0 Label2.Focus() Speak("Mode Select Menu") End Sub Private Sub ModeSelect_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown 'For touchscreen gestures If e.KeyCode = Keys.X Then Me.Close() End If End Sub #Region "Button Focus" 'The button focus area is where two actions take place. '------------------------------------------------------- 'The first is the switching of background images. Since the interface 'was designed so that it would not feel like a basic windows form, custom 'button images were used. And the way .NET set it up, each button had to 'be done individually. ' 'Second, this is where the program is told to announce what button 'currently as focus for TTS use. Private Sub LuxuryBtn_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles LuxuryBtn.GotFocus LuxuryBtn.Image = GetImage("LuxurySelect.png") Speak("Luxury") End Sub Private Sub LuxuryBtn_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles LuxuryBtn.LostFocus LuxuryBtn.Image = GetImage("Luxury.png") End Sub

Page 52: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

51

Private Sub FrugalBtn_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles FrugalBtn.GotFocus FrugalBtn.Image = GetImage("FrugalSelect.png") Speak("Frugal") End Sub Private Sub FrugalBtn_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles FrugalBtn.LostFocus FrugalBtn.Image = GetImage("Frugal.png") End Sub Private Sub MiserBtn_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles MiserBtn.GotFocus MiserBtn.Image = GetImage("MiserSelect.png") Speak("Miser") End Sub Private Sub MiserBtn_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles MiserBtn.LostFocus MiserBtn.Image = GetImage("Miser.png") End Sub Private Sub PstBtn_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles pstBtn.GotFocus pstBtn.Image = GetImage("PresetSelect.png") Speak("Preset") End Sub Private Sub PstBtn_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles pstBtn.LostFocus pstBtn.Image = GetImage("Preset.png") End Sub Private Sub cstmBtn_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles cstmBtn.GotFocus cstmBtn.Image = GetImage("CustomSelect.png") Speak("Custom") End Sub Private Sub cstmBtn_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles cstmBtn.LostFocus cstmBtn.Image = GetImage("Custom.png") End Sub Private Sub clsBtn_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles clsBtn.GotFocus clsBtn.Image = GetImage("CloseSelect.png") Speak("Close") End Sub Private Sub clsBtn_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles clsBtn.LostFocus clsBtn.Image = GetImage("Close.png") End Sub Private Sub clspBtn_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles clspBtn.GotFocus clspBtn.Image = GetImage("CloseSelect.png") Speak("Close") End Sub

Page 53: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

52

Private Sub clspBtn_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles clspBtn.LostFocus clspBtn.Image = GetImage("Close.png") End Sub Private Sub oneBtn_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles oneBtn.GotFocus oneBtn.Image = GetImage("oneselect.png") Speak("One") End Sub Private Sub oneBtn_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles oneBtn.LostFocus oneBtn.Image = GetImage("one.png") End Sub Private Sub twoBtn_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles twoBtn.GotFocus twoBtn.Image = GetImage("twoselect.png") Speak("Two") End Sub Private Sub twoBtn_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles twoBtn.LostFocus twoBtn.Image = GetImage("two.png") End Sub Private Sub threeBtn_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles threeBtn.GotFocus threeBtn.Image = GetImage("threeselect.png") Speak("Three") End Sub Private Sub threeBtn_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles threeBtn.LostFocus threeBtn.Image = GetImage("three.png") End Sub Private Sub fourBtn_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles fourBtn.GotFocus fourBtn.Image = GetImage("fourselect.png") Speak("four") End Sub Private Sub fourBtn_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles fourBtn.LostFocus fourBtn.Image = GetImage("four.png") End Sub Private Sub fiveBtn_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles fiveBtn.GotFocus fiveBtn.Image = GetImage("fiveselect.png") Speak("five") End Sub Private Sub fiveBtn_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles fiveBtn.LostFocus fiveBtn.Image = GetImage("five.png") End Sub Private Sub sixBtn_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles sixBtn.GotFocus sixBtn.Image = GetImage("sixselect.png")

Page 54: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

53

Speak("six") End Sub Private Sub sixBtn_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles sixBtn.LostFocus sixBtn.Image = GetImage("six.png") End Sub Private Sub sevenBtn_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles sevenBtn.GotFocus sevenBtn.Image = GetImage("sevenselect.png") Speak("seven") End Sub Private Sub sevenBtn_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles sevenBtn.LostFocus sevenBtn.Image = GetImage("seven.png") End Sub Private Sub eightBtn_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles eightBtn.GotFocus eightBtn.Image = GetImage("eightselect.png") Speak("eight") End Sub Private Sub eightBtn_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles eightBtn.LostFocus eightBtn.Image = GetImage("eight.png") End Sub Private Sub nineBtn_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles nineBtn.GotFocus nineBtn.Image = GetImage("nineselect.png") Speak("nine") End Sub Private Sub nineBtn_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles nineBtn.LostFocus nineBtn.Image = GetImage("nine.png") End Sub Private Sub zeroBtn_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles zeroBtn.GotFocus zeroBtn.Image = GetImage("zeroselect.png") Speak("zero") End Sub Private Sub zeroBtn_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles zeroBtn.LostFocus zeroBtn.Image = GetImage("zero.png") End Sub Private Sub acptBtn_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles acptBtn.GotFocus acptBtn.Image = GetImage("AcceptSelect.png") Speak("Accept?") End Sub Private Sub acptBtn_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles acptBtn.LostFocus acptBtn.Image = GetImage("Accept.png") End Sub

Page 55: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

54

Private Sub decBtn_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles decBtn.GotFocus decBtn.Image = GetImage("decselect.png") Speak("Decimal") End Sub Private Sub decBtn_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles decBtn.LostFocus decBtn.Image = GetImage("dec.png") End Sub #End Region #Region "Button Clicks" 'This function makes it easy to change thresholds of the appliances. Private Function Threshold(ByVal wh As Double, ByVal d As Double, ByVal f As Double, ByVal l As Double) Mode.WaterHeaterThresh = wh Mode.DryerThresh = d Mode.FreezerThresh = f Mode.LightsThresh = l End Function 'The next three sub routines are all for using the preset modes. 'All three are hard coded into the program 'However, a custom mode is availble for the user to edit. Private Sub LuxuryBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LuxuryBtn.Click Threshold(1, 1, 1, 1) green(1) CModeLbl.Text = "Luxury" whLbl.Text = FormatCurrency(Mode.WaterHeaterThresh, 2) dLbl.Text = FormatCurrency(Mode.DryerThresh, 2) fLbl.Text = FormatCurrency(Mode.FreezerThresh, 2) lLbl.Text = FormatCurrency(Mode.LightsThresh, 2) If Timer2.Enabled Then Timer2.Stop() End If CheckState = 0 Timer2.Start() End Sub Private Sub FrugalBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles FrugalBtn.Click green(2) Threshold(0.45, 0.4, 0.55, 0.6) CModeLbl.Text = "Frugal" whLbl.Text = FormatCurrency(Mode.WaterHeaterThresh, 2) dLbl.Text = FormatCurrency(Mode.DryerThresh, 2) fLbl.Text = FormatCurrency(Mode.FreezerThresh, 2) lLbl.Text = FormatCurrency(Mode.LightsThresh, 2) If Timer2.Enabled Then

Page 56: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

55

Timer2.Stop() End If CheckState = 0 Timer2.Start() End Sub Private Sub MiserBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MiserBtn.Click green(3) Threshold(0.25, 0.25, 0.35, 0.4) CModeLbl.Text = "Miser" whLbl.Text = FormatCurrency(Mode.WaterHeaterThresh, 2) dLbl.Text = FormatCurrency(Mode.DryerThresh, 2) fLbl.Text = FormatCurrency(Mode.FreezerThresh, 2) lLbl.Text = FormatCurrency(Mode.LightsThresh, 2) If Timer2.Enabled Then Timer2.Stop() End If CheckState = 0 Timer2.Start() End Sub #Region "Custom Numberpad" 'This section is for the numberpad that comes up for entering custom threshold prices. 'Each button adds a number to the end of a string, much like that of a calculator screen, 'and once the user hits the accept key, the threshold is then set. At the same time, it 'is also convertered to a currency string and displayed. Private Function KeypadPress(ByVal state As Integer, ByVal number As String) Select Case state Case 0 whLbl.Text = NumberPress(whLbl.Text, number) Case 1 dLbl.Text = NumberPress(dLbl.Text, number) Case 2 fLbl.Text = NumberPress(fLbl.Text, number) Case 3 lLbl.Text = NumberPress(lLbl.Text, number) End Select End Function Private Sub oneBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles oneBtn.Click KeypadPress(AcceptState, "1") Speak("Number one was pressed") End Sub Private Sub twoBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles twoBtn.Click KeypadPress(AcceptState, "2") Speak("Number two was pressed")

Page 57: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

56

End Sub Private Sub threeBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles threeBtn.Click KeypadPress(AcceptState, "3") Speak("Number three was pressed") End Sub Private Sub fourBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles fourBtn.Click KeypadPress(AcceptState, "4") Speak("Number four was pressed") End Sub Private Sub fiveBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles fiveBtn.Click KeypadPress(AcceptState, "5") Speak("Number five was pressed") End Sub Private Sub sixBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles sixBtn.Click KeypadPress(AcceptState, "6") Speak("Number six was pressed") End Sub Private Sub sevenBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles sevenBtn.Click KeypadPress(AcceptState, "7") Speak("Number seven was pressed") End Sub Private Sub eightBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles eightBtn.Click KeypadPress(AcceptState, "8") Speak("Number 8 was pressed") End Sub Private Sub nineBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nineBtn.Click KeypadPress(AcceptState, "9") Speak("Number 9 was pressed") End Sub Private Sub zeroBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles zeroBtn.Click KeypadPress(AcceptState, "0") Speak("Number 0 was pressed") End Sub Private Sub decBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles decBtn.Click KeypadPress(AcceptState, ".") Speak("Decimal was pressed") End Sub #End Region

Page 58: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

57

#End Region Private Sub Timer2_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer2.Tick Select Case CheckState Case 0 WaterHeaterOn = PriceCheck(Price, WaterHeaterThresh, WaterHeaterOver, "A1") Case 1 DryerOn = PriceCheck(Price, DryerThresh, DryerOver, "A2") Case 2 FreezerOn = PriceCheck(Price, FreezerThresh, FreezerOver, "A3") Case 3 LightsOn = PriceCheck(Price, LightsThresh, LightsOver, "A4") Timer2.Stop() End Select CheckState += 1 End Sub Private Sub pstBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pstBtn.Click 'Open preset mode interface cstmBtn.Visible = False clsBtn.Visible = False MiserBtn.Visible = True LuxuryBtn.Visible = True FrugalBtn.Visible = True clspBtn.Visible = True pstBtn.Visible = False End Sub Private Sub clspBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clspBtn.Click 'Close preset mode interface MiserBtn.Visible = False LuxuryBtn.Visible = False FrugalBtn.Visible = False clspBtn.Visible = False pstBtn.Visible = True cstmBtn.Visible = True clsBtn.Visible = True End Sub Private Sub cstmBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cstmBtn.Click 'Open custom mode edit interface pstBtn.Visible = False cstmBtn.Visible = False clsBtn.Visible = False oneBtn.Visible = True twoBtn.Visible = True

Page 59: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

58

threeBtn.Visible = True fourBtn.Visible = True fiveBtn.Visible = True sixBtn.Visible = True sevenBtn.Visible = True eightBtn.Visible = True nineBtn.Visible = True zeroBtn.Visible = True decBtn.Visible = True acptBtn.Visible = True whLbl.Text = 0 CModeLbl.Text = "Custom" whLbl.BackColor = System.Drawing.Color.Firebrick SendKeys.Send("{TAB}") End Sub Private Sub acptBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles acptBtn.Click Speak("Accept was pressed.") 'This case select is keep track of which appliance threshold is to be set 'When the accept button is pressed the program will store what ever value was 'Inputed by the user as the new threshold. Select Case AcceptState Case 0 whLbl.BackColor = System.Drawing.Color.Transparent Mode.WaterHeaterThresh = CDbl(DecCheck(whLbl.Text)) whLbl.Text = FormatCurrency(whLbl.Text, 2) dLbl.BackColor = System.Drawing.Color.Firebrick dLbl.Text = 0 AcceptState += 1 Case 1 dLbl.BackColor = System.Drawing.Color.Transparent Mode.DryerThresh = DecCheck(dLbl.Text) dLbl.Text = FormatCurrency(dLbl.Text, 2) fLbl.BackColor = System.Drawing.Color.Firebrick fLbl.Text = 0 AcceptState += 1 Case 2 fLbl.BackColor = System.Drawing.Color.Transparent Mode.FreezerThresh = DecCheck(fLbl.Text) fLbl.Text = FormatCurrency(fLbl.Text, 2) lLbl.BackColor = System.Drawing.Color.Firebrick lLbl.Text = 0 AcceptState += 1 Case 3 Mode.LightsThresh = DecCheck(lLbl.Text) lLbl.Text = FormatCurrency(lLbl.Text, 2) lLbl.BackColor = System.Drawing.Color.Transparent AcceptState = 0 'Return everything to normal oneBtn.Visible = False twoBtn.Visible = False threeBtn.Visible = False

Page 60: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

59

fourBtn.Visible = False fiveBtn.Visible = False sixBtn.Visible = False sevenBtn.Visible = False eightBtn.Visible = False nineBtn.Visible = False zeroBtn.Visible = False acptBtn.Visible = False decBtn.Visible = False pstBtn.Visible = True cstmBtn.Visible = True clsBtn.Visible = True If Timer2.Enabled Then Timer2.Stop() End If CheckState = 0 Timer2.Start() End Select End Sub Private Sub clsBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clsBtn.Click Me.Close() End Sub Public Function DecCheck(ByVal value As String) If value = "." Then Return "0" Else Return value End If End Function End Class

Page 61: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

60

Settings.VB _____________________________________________________________________________

Public Class Settings Inherits WindowsApplication2.Template Dim VolumeRs232 As New Rs232 Dim volume As Integer Private Sub Settings_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Label6.Focus() Speak("Settings Menu") 'InitVlmRs232() saLbl.Text = State(sss_state) ttsLbl.Text = State(tts_state) visLbl.Text = State(vis_state) vlmLbl.Text = VolumeLevel() End Sub #Region "Button Focus" 'The button focus area is where two actions take place. '------------------------------------------------------- 'The first is the switching of background images. Since the interface 'was designed so that it would not feel like a basic windows form, custom 'button images were used. And the way .NET set it up, each button had to 'be done individually. ' 'Second, this is where the program is told to announce what button 'currently as focus for TTS use. Private Sub switchBtn_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles switchBtn.GotFocus Speak("Switch Access") switchBtn.Image = GetImage("SwitchSelect.png") End Sub Private Sub switchBtn_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles switchBtn.LostFocus switchBtn.Image = GetImage("Switch.png") End Sub Private Sub ttsBtn_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles ttsBtn.GotFocus Speak("Text to speech") ttsBtn.Image = GetImage("TTSSelect.png") End Sub Private Sub ttsBtn_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles ttsBtn.LostFocus ttsBtn.Image = GetImage("TTS.png") End Sub

Page 62: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

61

Private Sub visBtn_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles visBtn.GotFocus Speak("Visual Alerts") visBtn.Image = GetImage("VisualSelect.png") End Sub Private Sub visBtn_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles visBtn.LostFocus visBtn.Image = GetImage("Visual.png") End Sub Private Sub vlmBtn_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles vlmBtn.GotFocus Speak("Volume") vlmBtn.Image = GetImage("VolumeSelect.png") End Sub Private Sub vlmBtn_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles vlmBtn.LostFocus vlmBtn.Image = GetImage("Volume.png") End Sub Private Sub upBtn_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles upBtn.GotFocus upBtn.Image = GetImage("UPSelect.png") Speak("Volume level up?") End Sub Private Sub upBtn_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles upBtn.LostFocus upBtn.Image = GetImage("UP.png") End Sub Private Sub downBtn_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles downBtn.GotFocus downBtn.Image = GetImage("DownSelect.png") Speak("Volume level down?") End Sub Private Sub downBtn_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles downBtn.LostFocus downBtn.Image = GetImage("Down.png") End Sub Private Sub clsBtn_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles clsBtn.GotFocus clsBtn.Image = GetImage("CloseSelect.png") Speak("Close?") End Sub Private Sub clsBtn_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles clsBtn.LostFocus clsBtn.Image = GetImage("Close.png") End Sub Private Sub accBtn_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles accBtn.GotFocus accBtn.Image = GetImage("AccessibilitySelect.png") Speak("Accessibility") End Sub

Page 63: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

62

Private Sub accBtn_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles accBtn.LostFocus accBtn.Image = GetImage("Accessibility.png") End Sub Private Sub clsBtn2_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles clsbtn2.GotFocus clsbtn2.Image = GetImage("CloseSelect.png") Speak("Close?") End Sub Private Sub clsBtn2_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles clsbtn2.LostFocus clsbtn2.Image = GetImage("Close.png") End Sub #End Region #Region "Button Clicks" Private Sub vlmBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles vlmBtn.Click vlmBtn.Visible = False ttsBtn.Visible = False visBtn.Visible = False switchBtn.Visible = False accBtn.Visible = False clsbtn2.Visible = False upBtn.Visible = True downBtn.Visible = True clsBtn.Visible = True vlmCLbl.Visible = True End Sub Private Sub clsBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles clsBtn.Click upBtn.Visible = False downBtn.Visible = False clsBtn.Visible = False vlmCLbl.Visible = False ttsBtn.Visible = False visBtn.Visible = False switchBtn.Visible = False accLbl.Visible = False vlmBtn.Visible = True accBtn.Visible = True clsbtn2.Visible = True

Page 64: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

63

End Sub Private Sub accBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles accBtn.Click accBtn.Visible = False clsbtn2.Visible = False vlmBtn.Visible = False upBtn.Visible = False downBtn.Visible = False accLbl.Visible = True clsBtn.Visible = True ttsBtn.Visible = True visBtn.Visible = True switchBtn.Visible = True accLbl.Focus() Speak("Accessability Menu") End Sub Private Sub switchBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles switchBtn.Click sss_state = Not (sss_state) saLbl.Text = State(sss_state) visLbl.Text = State(vis_state) ttsLbl.Text = State(tts_state) If Not (sss_state) Then sss_check = 0 End If Speak("Switch access is now " & saLbl.Text) End Sub Private Sub ttsBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ttsBtn.Click tts_state = Not (tts_state) saLbl.Text = State(sss_state) visLbl.Text = State(vis_state) ttsLbl.Text = State(tts_state) Speak("Text to speech is now " & ttsLbl.Text) End Sub Private Sub visBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles visBtn.Click vis_state = Not (vis_state) saLbl.Text = State(sss_state) visLbl.Text = State(vis_state) ttsLbl.Text = State(tts_state) Speak("Visual alerts are now " & visLbl.Text) End Sub #End Region Private Sub clsbtn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clsbtn2.Click Me.Close()

Page 65: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

64

End Sub Private Sub upBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles upBtn.Click VlmUp() vlmLbl.Text = VolumeLevel() Speak("Volume up was pressed") End Sub Private Sub downBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles downBtn.Click VlmDwn() vlmLbl.Text = VolumeLevel() Speak("Volume down was pressed") End Sub Private Sub Settings_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing VolumeRs232.Close() End Sub Private Sub Settings_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown If e.KeyCode = Keys.X Then Me.Close() End If End Sub End Class

Page 66: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

65

Mode.VB _____________________________________________________________________________ Module Mode 'Mode_Variables Public Price As Double 'These hold the threshold at where the appliances will turn off Private miLightsThresh As Double = 1.0 Private miWaterHeaterThresh As Double = 1.0 Private miDryerThresh As Double = 1.0 Private miFreezerThresh As Double = 1.0 'These are the Override boolean Private miLightsOver As Boolean = False Private miWaterHeaterOver As Boolean = False Private miDryerOver As Boolean = False Private miFreezerOver As Boolean = False 'These are the current states of each appliance as to weather they are on or not Private miLightsOn As Boolean = True Private miWaterHeaterOn As Boolean = True Private miDryerOn As Boolean = True Private miFreezerOn As Boolean = True #Region "Thresholds" 'These are the threshold properies that will return what the threshold is 'Or it will allow for them to be changed Public Property WaterHeaterThresh() As Double Get Return miWaterHeaterThresh End Get Set(ByVal Value As Double) miWaterHeaterThresh = Value End Set End Property Public Property DryerThresh() As Double Get Return miDryerThresh End Get Set(ByVal Value As Double) miDryerThresh = Value End Set End Property Public Property LightsThresh() As Double Get Return miLightsThresh End Get

Page 67: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

66

Set(ByVal Value As Double) miLightsThresh = Value End Set End Property Public Property FreezerThresh() As Double Get Return miFreezerThresh End Get Set(ByVal Value As Double) miFreezerThresh = Value End Set End Property #End Region #Region "Overrides" 'These are boolean values that state weather 'An appliance has an override or not Public Property WaterHeaterOver() As Boolean Get Return miWaterHeaterOver End Get Set(ByVal Value As Boolean) miWaterHeaterOver = Value If Value Then miWaterHeaterOn = True End If End Set End Property Public Property DryerOver() As Boolean Get Return miDryerOver End Get Set(ByVal Value As Boolean) miDryerOver = Value If Value Then miDryerOn = True End If End Set End Property Public Property LightsOver() As Boolean Get Return miLightsOver End Get Set(ByVal Value As Boolean) miLightsOver = Value If Value Then miLightsOn = True End If End Set End Property Public Property FreezerOver() As Boolean Get

Page 68: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

67

Return miFreezerOver End Get Set(ByVal Value As Boolean) miFreezerOver = Value If Value Then miFreezerOn = True End If End Set End Property #End Region #Region "Appliance On?" 'Checks to find if the appliances are on or off Public Property WaterHeaterOn() As Boolean Get Return miWaterHeaterOn End Get Set(ByVal Value As Boolean) miWaterHeaterOn = Value End Set End Property Public Property DryerOn() As Boolean Get Return miDryerOn End Get Set(ByVal Value As Boolean) miDryerOn = Value End Set End Property Public Property LightsOn() As Boolean Get Return miLightsOn End Get Set(ByVal Value As Boolean) miLightsOn = Value End Set End Property Public Property FreezerOn() As Boolean Get Return miFreezerOn End Get Set(ByVal Value As Boolean) miFreezerOn = Value End Set End Property #End Region Public Function Usage() 'This is the hardcoded function for the current watt usage in the home 'It will return the value in Killowatts Dim watts As Integer = 0

Page 69: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

68

If miLightsOn Then watts += 450 End If If miDryerOn Then watts += 3300 End If If miFreezerOn Then watts += 160 End If If miWaterHeaterOn Then watts += 3800 End If Return (watts / 1000) End Function Public Function NumberPress(ByVal text As String, ByVal number As String) 'This is called when one of the numbers on the 'onscreen keypad are pressed Dim i As Integer If number = "." Then 'Want to make sure that only one decimal point is entered For i = 0 To text.Length - 1 If text.Chars(i) = "." Then If text.Length = 1 Then Return "0." Else Return text End If End If Next End If If text = "0" Then text = number Else text = text & number End If Return text End Function End Module

Page 70: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

69

Settingmod.VB _____________________________________________________________________________ Module SetingMod Private sss As Boolean Private tts As Boolean Private vis As Boolean Public sssCheck As Integer Private volume As Integer = 100 Dim VlmRs232 As New Rs232 #Region "Setting States" 'These properties set wheater an Accesability option is on or off 'Also returns state Public Property sss_state() As Boolean Get Return sss End Get Set(ByVal Value As Boolean) sss = Value End Set End Property Public Property tts_state() As Boolean Get Return tts End Get Set(ByVal Value As Boolean) tts = Value End Set End Property Public Property vis_state() As Boolean Get Return vis End Get Set(ByVal Value As Boolean) vis = Value End Set End Property Public Property volume_state() As Integer Get Return volume End Get Set(ByVal Value As Integer) volume = Value End Set End Property Public Property VolumeLevel() As Integer Get Return volume

Page 71: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

70

End Get Set(ByVal Value As Integer) volume = Value End Set End Property #End Region Public Property sss_check() 'This is for the current phase of the switch access Get Return sssCheck End Get Set(ByVal Value) If Value = 1 And sssCheck = 0 Then sss_state = True End If sssCheck = Value End Set End Property Public Function InitVlmRs232() 'This is the COM port for the volume control and Visual Alerts With VlmRs232 .Port = 6 .BaudRate = 2400 .DataBit = 8 .StopBit = Rs232.DataStopBit.StopBit_1 .Parity = Rs232.DataParity.Parity_None .Timeout = 10000 .Dtr = True .Rts = True End With VlmRs232.Open() End Function Public Function Speak(ByVal Value As String) 'This function checks if the TTS option is on 'If so, it sends the string to the clipboard 'And DSpeech well turn it into speech. If tts Then Try Clipboard.SetDataObject(Value) Catch End Try End If End Function Public Function State(ByVal Value As Boolean) 'A function to turn a boolean value into 'an on or off state If Value Then Return "On" Else Return "Off" End If End Function

Page 72: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

71

'These two functions send the volume information through the COM port Public Function VlmDwn() volume += 25 If volume >= 255 Then volume = 255 End If VlmRs232.Write("j") VlmRs232.Write(Chr(volume)) End Function Public Function VlmUp() volume -= 25 If volume <= 0 Then volume = 0 End If VlmRs232.Write("j") VlmRs232.Write(Chr(volume)) End Function Public Function red() VlmRs232.Write("r") End Function Public Function green(ByVal speed As Integer) If speed = 0 Then VlmRs232.Write("g") ElseIf speed = 1 Then VlmRs232.Write("h") ElseIf speed = 2 Then VlmRs232.Write("i") ElseIf speed = 3 Then VlmRs232.Write("k") End If End Function End Module

Page 73: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

72

X10.VB _____________________________________________________________________________

Module X10 Public COM5 As New Rs232 Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) 'Firecracker Header and Footer, these never change Private Header As String = "1101010110101010" Private Footer As String = "10101101" 'Unit A1 to A4 units Private A1On As String = "0110000000000000" Private A1off As String = "0110000000100000" Private A2On As String = "0110000000010000" Private A2Off As String = "0110000000110000" Private A3On As String = "0110000000001000" Private A3Off As String = "0110000000101000" Private A4On As String = "0110000000011000" Private A4Off As String = "0110000000111000" Public Function InitX10() With COM5 .Port = 5 .BaudRate = 9600 .DataBit = 8 .StopBit = Rs232.DataStopBit.StopBit_1 .Parity = Rs232.DataParity.Parity_None .Timeout = 10000 .Dtr = True .Rts = True End With COM5.Open() Sleep(50) COM5.Rts = False COM5.Dtr = False Sleep(50) COM5.Rts = True COM5.Dtr = True Sleep(50) End Function Public Function Close() COM5.Close() End Function Public Function SendBits(ByVal Transmission As String) 'This sends the bits through the RTS and DTR pints 'The sleep function is very important for timing Dim i As Long Dim SendBit As Integer

Page 74: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

73

For i = 1 To Len(Transmission) SendBit = Val(Mid$(Transmission, i, 1)) If SendBit = 1 Then COM5.Dtr = False Sleep(0.5) COM5.Dtr = True Else COM5.Rts = False Sleep(0.5) COM5.Rts = True End If Next i End Function Public Function PriceCheck(ByVal CPrice As Double, ByVal AThresh As Double, ByVal State As Boolean, ByVal Unit As String) 'CPrice is the current price and AThresh is the threshold price of the appliance to be checked 'Unit refers to which X10 unit that should be turned on or off If (CPrice >= AThresh) And Not (State) Then Select Case Unit Case "A1" SendBits(Header) SendBits(A1off) SendBits(Footer) Return False Case "A2" SendBits(Header) SendBits(A2Off) SendBits(Footer) Return False Case "A3" SendBits(Header) SendBits(A3Off) SendBits(Footer) Return False Case "A4" SendBits(Header) SendBits(A4Off) SendBits(Footer) Return False End Select ElseIf (CPrice < AThresh) Or State Then Select Case Unit Case "A1" SendBits(Header) SendBits(A1On) SendBits(Footer) Return True Case "A2" SendBits(Header) SendBits(A2On) SendBits(Footer) Return True Case "A3" SendBits(Header)

Page 75: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

74

SendBits(A3On) SendBits(Footer) Return True Case "A4" SendBits(Header) SendBits(A4On) SendBits(Footer) Return True End Select Else Return State End If End Function End Module

Page 76: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

75

Microcontroller Code _____________________________________________________________________________

#include <p18cxxx.h> #include <usart.h> #include <spi.h> #pragma config LVP=OFF #pragma config WDT=OFF #define SPI_CS LATCbits.LATC2 // Setting RC2 (pin#17)of the PIC to be // SPI chip select select void rx_handler (void); //Declare the ISR function long int count; long int count2; int red; int green; void main() { //initialize LED state variables red = 0; green = 12; OpenUSART (USART_TX_INT_OFF & USART_RX_INT_ON & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW, 63); RCONbits.IPEN = 1; /* Enable interrupt priority */ IPR1bits.RCIP = 1; /* Make receive interrupt high priority */ INTCONbits.GIEH = 1; /* Enable all high priority interrupts */ ADCON1 =0x00; //set VREF+ to VDD and VREF- to GND (VSS) TRISD = 0x04; PORTDbits.RD0 = 0; //initialize Red LED to off PORTDbits.RD1 = 0; //do the same for Green LED TRISC=0b11000000; //setting PORTC port pins to be outputs SPI_CS = 1; // chip select=1 OpenSPI(SPI_FOSC_64,MODE_00,SMPEND); // Initializing SSP while(1) { for(count = 1; count < 12; count++){ for(count2 = 1; count2 < 20000; count2++); //wait if(green==12){ //green set to off PORTDbits.RD1=0; } else if((count % (green+1)) ==0){ //take modulus to change rate

Page 77: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

76

PORTDbits.RD1=!PORTDbits.RD1; } if(red){ if(count==1)PORTDbits.RD0=1; else PORTDbits.RD0=0; } } } } #pragma code rx_interrupt = 0x8 //Let the compiler know the location of the ISR void rx_int (void) { _asm goto rx_handler _endasm } #pragma code #pragma interrupt rx_handler //Let the compiler know that this function is the ISR void rx_handler (void) { unsigned char c; unsigned char d; c = getcUSART(); //get a single character off the USART line while(BusyUSART()); if (c=='r') //toggle red LED { red = !red; } if (c=='g') //turn off green LED { green = 12; } if (c=='h') //green LED slow { green = 1; } if (c=='i') //green LED medium { green = 4; } if (c=='k') //green LED fast { green = 8; } if (c=='j') { for(count = 1; count < 10000; count++); d = getcUSART(); while(BusyUSART());

Page 78: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

77

SPI_CS = 0; //chip select=0 WriteSPI(0x11); // writing the command byte to the pot WriteSPI(d); // writing the data byte to the pot. SPI_CS = 1; } PIR1bits.RCIF = 0; //reset the ISR flag. }

Page 79: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

78

Figure 1. LM741 Op-Amp Audio Amplifier

Appendix iv

1-Audio Amplifier:

For the purpose of text-to speech feature, an audio amplifier circuit was built to produce clear,

reasonably high sound output.

1.1 The LM741 Op-Amp Audio Amplifier:

The first design we considered is the LM741 op-amp audio amplifier circuit shown in figure 1.

This amplifier consists of two amplifying stages, a differential amplifier and a non inverting amplifier.

Page 80: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

79

1.1.1 Differential Amplifier:

The sound output of the PC is a stereo signal; it consists of two channels, right and left. Theses

two channels act as the two inputs to the differential amplifier as shown in the figure 2. In general, the

output of this differential amplifier is:

rlm V

RRR

RRRV

RRV

3

43

4

1

2

1

2

1

11 (1)

Where:

mV is the output voltage of the differential amplifier

lV is the left channel input voltage to the differential amplifier

rV is the right channel input voltage to the differential amplifier

The values of the resistors 1R , 2R , 3R , and 4R were picked such that:

KK

KK

RR

RR

5.13.183

8.1220

3

4

1

2 (2)

This reduces equation (1) to:

lrlrm VVVVRRV 2.122

1

2 (3)

Page 81: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

80

In words, the differential amplifier takes the left and right channel from the PC and converts

them to a mono signal by subtracting the common signals between the two channels. This cancels out

the noise from the two channels and allows the use of one speaker instead of two for the right and left

channels, which therefore, reduces the size and the weight of the final product.

R1

R4

R2

LM741Audio Signal

-5 V

+5 V

Vr

R3

Vl

Vm

Figure 2: Differential Amplifier Figure 3: LM741 OP-Amp

1.1.2 Non Inverting Amplifier with Power Booster:

The actual sound amplification occurs at the second stage amplifier shown in figure 3. The

mono output of the differential amplifier is fed into the non inverting amplifier, and the output of this

stage is:

iispea VVRR

V .1115

6ker

(4)

Where:

Page 82: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

81

kerspeaV is the output voltage across the speaker

iV is the input voltage to the non inverting amplifier

Figure 4: Non Inverting Amplifier with Power Booster

A 10 KΩ digital potentiometer was added at the input of the non inverting amplifier. This allows

the user to change iV , which in turn changes the sound level of the speaker (i.e. kerspeaV ) as desired

according to equation (4). More details about the implementation of this digital pot are provided in

section 1.3.

Some IC chips have small DC voltage at their output, which may cause thumping the speaker.

Therefore, the capacitor C was added to block this DC voltage. The value of this capacitor was picked

such that the reactance of the capacitor is less than the resistance of the 10 KΩ pot at the lowest audible

frequency (about 20 Hz):

Page 83: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

82

FK

C

KfC

KZ c

8.010202

1

102

110

Nearest standard value is 1 µF

The op-amps can only provide up to 20 mA of current. This means that the maximum voltage

that we can have across the speaker is mVm 160820 , which is barley audible. Therefore, the

TIP31A and TIP32A power transistors were added at the output of the non inverting amplifier. This

increases the maximum current to Am 02.1)20(51 and kerspeaV to a maximum

of V16.88)02.1( .

1.1.3 Issues with the LM741 Circuit Design:

One big issue that we faced when we used this design is that the LM741 is a dual supply IC chip;

positive and negative voltages must be provided to power up the chip. In our project, only a +5 V was

available (from the USB port). To solve this issue, the following solutions were considered:

DC to DC Inverter:

The first solution that we considered was to use an inverter, which takes the +5 V that the USB

port provides and converts it to a -5 V. We believed that this would work at first, but after looking at

some of the inverters available, we concluded that this is not a good solution. This is because most

inverters are kind of expensive. More importantly, they do not provide enough current to drive the

speaker. Dimension Engineering’s Negatron DC to DC converter, which costs $20, is one example.

Page 84: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

83

When we input +12 V to this converter, it outputs -5 V at 500 mA max, which is what we need to drive

the speaker at max volume. However, when the input voltage is +5, which is the case in our project, the

converter outputs -5 V at 180 mA max. This is much less than what the speaker need to draw at max

volume.

Lithium Batteries:

The second solution that we considered is using a 9 V lithium Batteries, which can provide up to

1.2 A. A -5 V can be acquired by connecting the positive terminal of the battery to the ground and use

the negative terminal of the battery as the negative power supply, and then use a step down voltage

regulator to acquire the -5 V that we need. However, this approach is not feasible since we are using an

extra and very expensive power source (Energizer’s 9 V lithium battery costs about $85), not to mention

the need to replace the battery when it runs out of charge.

Single Supply Design for Dual Supply Op-Amps:

After doing more research, we found out that a single supply can be used to power up the op-

amps. This can be achieved by connecting the positive power supply to the positive power pin of the

op-amps and the ground to the negative power pin. A virtual ground, halfway between the positive

supply voltage and ground, is the reference for the input and output voltages.

The circuit in the figure 1 was modified to achieve this goal. The half supply reference ground

was created by connecting two equal resistors (22 KΩ) in series across the +5 V power supply, as shown

in the figure 4. The new capacitors were added to block the DC offset that resulted from lifting the

ground reference (the derivations are similar to that in section above). The 10 Ω resistors were added at

the output of the transistors to prevent large discharge currents from the 220 µF from flowing back into

the transistors when the supply is turned off.

Page 85: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

84

Figure 4: Single Supply Design

We faced some problems using this design. The dynamic range of the op-amps was reduced

from 6 Vp-p to 1 Vp-p as illustrated in figure 5. This limits the input and output voltages severely. It also

reduces the signal-to-noise ratio (SNR). Note: The reason that a -2 V was subtracted from each end of

the range is because certain transistors saturation and junction drops appear between the power supply

voltage and the output voltage. The magnitudes of these drops are about 2 V below the magnitudes of

the power supply levels.

Figure 5: Affect on Dynamic range when using Single Supply Design

Page 86: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

85

1.2 LM386 Audio Amplifier IC Chip:

Figure 6: LM386

The LM386 circuit shown in figure 6 functions similarly to the LM741 op-amp circuit. The only

difference is that it takes only one input and does not do the stereo-to-mono conversion. This is not a

problem for us since one channel would still give us the results that we want.

Figure 7: LM386 Audio Amplifier

We decided to use this circuit in our final design because of the advantages it has over the

LM741 circuit. The most significant advantage is that the LM386 is a single supply IC chip; only a positive

voltage is needed to power up the chip. Moreover, the size of the LM868 circuit is less than the half size

of the LM741 circuit, and is therefore less expensive. Lastly, this circuit produces less noise than the

previous design (i.e. it has higher SNR).

Page 87: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

86

1.3 Microchip MCP41010 Digital Pot:

For the purpose of volume control, the Microchip MCP41010 10 K Ω potentiometer was added to

adjust the input voltage of the amplifier. There are many advantages of the digital pot that made us

decide on using it rather than the mechanical pot:

i. The mechanical pot has moving parts while the digital one does not have any moving parts. This

makes it less sensitive to environmental effects such as changes in temperature, humidity and to

shock and vibration.

ii. The digital pot is more robust. It has a longer life than a mechanical pot.

iii. It offers off-hands programmability. The user would be able to control the volume through the

touch screen.

1.3.1 MCP41010 Pin Descriptions:

Figure 6: MCP41010

Pin # Name Function/Description

1 CS This is the SPI port chip select pin. It is used to execute a new command

after it is loaded into the device.

2 SCK This is the SPI port clock. It used to clock in data into the device. The

maximum clock frequency that the device can have is 10 MHz.

3 SI This is the SPI port input pin. It is used to load data into the device.

4 VSS Ground.

Page 88: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

87

5 PA0 The pot terminal A connection.

6 PW0 The pot wiper connection.

7 PB0 The pot terminal B connection.

8 VDD Power supply. It must fall between 2.7 V and 5.5 V.

Table 1: MCP41010 Pin Descriptions

1.3.2 Resistance of MCP41010:

The input voltage of the amplifier can be adjusted by changing the resistance between terminal

A and the wiper and between terminal B and the wiper of the pot. This can be done by setting the

position of the wiper to any of the 256 possible positions as illustrated in equations (5) through (8):

Figure 5: Model of the MCP41010

WnAB

nWA RDRDR

256

)256()()( (5)

WnAB

nWB RDRDR 256

))(()( (6)

Page 89: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

88

Where:

A is the A terminal of the pot (PA0 pin)

W is the wiper Terminal (PW0 pin)

B is the B terminal (PB0 pin)

WAR is the resistance between terminal A and the wiper

WBR is the resistance between terminal B and the wiper

ABR is the overall resistance for the pot (10 KΩ for MCP41010)

WR is the resistance of the wiper (typically, 52 Ω for MCP41010)

nD is the wiper setting, a value between 0 and 255

When the device is connected to the amplifier, WR can be neglected, since the input impedance

of the amplifier is very high. Therefore, the above equations can be reduced to:

256)256()(

)( nABnWA

DRDR (7)

256))(()( nAB

nWBDRDR (8)

1. 3.3 Interfacing to Microchip PIC18F4520 Microcontroller:

Page 90: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

89

When the pot is powered up, the wiper is reset to mid-scale position ( nD =128). To change the

position of the wiper, a microcontroller was used to communicate with the pot via Serial Peripheral

Interface Bus (SPI).

5.1 PIC18F4520 Pins Used:

Figure 6: PIC18F4520 microcontroller

Pin # Name Description

17 RC2 It is used to control commands executions on the pot.

18 SCK This is the SPI clock output. It is used to clock data out of the PIC and into

the pot. The frequency of the clock output is the same as the frequency of

the external clock oscillator (i.e. 10 MHz).

24 SDO This is the SPI data output. It is used to output the data from the PIC.

Table 2: PIC18F4520 pins used for communications with MCP41010

Page 91: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

90

1.3.3.1 Connections:

PIC

18F4

520

MC

P41

010

LM38

6

Figure 7: Connection between PIC and MCP41010 and LM386

1.3.3.2 Enabling the SPI mode on PIC18F4520:

Before we started writing the code for the communication with pot, we had to enable the SPI

mode on the PIC. This was done by including the spi.h library at the beginning of the code. In this

library, the SSPCON1 control register on the PIC is pre-defined and bit 5 of this register is pre-set to 1.

This enabled serial port and configured SCK, SDO as serial pins. This library also includes all the

definitions for the functions and the variables that we used to communicate with the pot via SPI

interface.

1.3.3.3 Initializing the Serial Synchronous Serial Port (SSP) Module:

The following pre-defined function was used to initialize SSP module for SPI communications:

Page 92: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

91

void OpenSPI(unsigned char sync_mode,

unsigned char bus_mode,

unsigned char smp_phase );

where sync_mode is one of the following defined values:

SPI_FOSC_4 SPI Master mode, clock = FOSC/4 (or Tcy)

SPI_FOSC_16 SPI Master mode, clock = FOSC/16 (or 4* Tcy)

SPI_FOSC_64 SPI Master mode, clock = FOSC/64 (or 16*Tcy)

SPI_FOSC_TMR2 SPI Master mode, clock = TMR2 output/2

SLV_SSON SPI Slave mode, /SS pin control enabled

SLV_SSOFF SPI Slave mode, /SS pin control disabled

bus_mode is one of the following defined values:

MODE_00 Setting for SPI bus Mode 0,0

MODE_01 Setting for SPI bus Mode 0,1

MODE_10 Setting for SPI bus Mode 1,0

MODE_11 Setting for SPI bus Mode 1,1

And smp_phase is one of the following defined values:

Page 93: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

92

SMPEND Input data sample at end of data out

SMPMID Input data sample at middle of data out

sync_mode:

In this project, the PIC plays the master role since it controls the SCK that clocks data into the

slave, the pot. Moreover, the input clock in the pot must be synchronous with the output clock from the

PIC such that there are 16 clock cycles in the pot before we execute the command (i.e. set CS =1).

Therefore, SPI_FOSC_64 is the value that we chose for sync_mode.

bus_mode:

The first digit of the mode is the clock polarity select (CKP) bit; 0 means that the idle state for

clock is a high level and 1 is a low level. The second digit is SPI clock select (CKE) bit; 1 means that

Transmission occurs on transition from active to idle clock state. In other words, the SDO data is valid

before there is a clock edge on SCK. When it is set to 0, the opposite occurs. This is illustrated in the

figure 7.

When, communicating with the pot, the data must be clocked in on the rising edge of the clock.

Therefore, the bus_mode was set to 0,0.

Page 94: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

93

Figure 7: SCK waveforms

smp_phase:

The setting of this value is only important when the PIC is receiving data. In our case, the PIC is

only transmitting data. Therefore, any of the two available values would not affect the operation of the

pot.

1.3.3.4 Data Directionality:

The next step after configuring the pins in table 2 as serial ports pins was to set them as output

pins. These pins are part of PORTC port on the PIC and their data direction could be set by changing the

bits of the TRISC data direction register on the PIC. We Cleared bits 2, 3, and 5 to configure RC2, SDK

and SDO respectively as outputs.

1.3.3.5 Writing Data to MCP41010:

Page 95: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

94

To execute any command, a 16-bit Data has to be sent from SDO of the PIC to SI of the pot. The

8 most significant bits of the data are called the command byte. It contains two command bits (4,5) and

two potentiometer select bits (0,1) as shown in figure 8. If the two command bits are identical (0,0 or

1,1), No command will be executed. If bit 5 and 4 are set to 0 and 1 respectively, a new wiper setting

will be written to the pot. Lastly, setting bit 5 and 4 to 1 and 0 respectively will set the pot on Shutdown

mode.

The potentiometer bits, 0 and 1, determine which channel (If there are two) will the command

be executed on; bit 0 is channel 1 and bit 1 is channel 2. Since MCP41010 is a single channel pot, bit 0 of

the command byte was set to 1, and bit 4 and 5 were set to 1 and 0 respectively in order to execute the

command. The rest of the bits are “don’t care” bits.

The 8 least significant bits of the transmitted data are called the data byte. It is used to change

the wiper setting when a binary (or hex) code corresponding to the decimal value of nD is sent to the

pot. For example, If nD =255, then the data byte= FF (in hex) or 11111111 (in binary).

Figure 8. Instruction sequence for MCP41XXX

The following pre-defined function was used to write data into the pot:

unsigned char WriteSPI( unsigned char data_out );

Page 96: AHEAD Accessible Home Energy Audio · PDF fileAHEAD Accessible Home Energy Audio Dashboard ... Jason Grimes Facilitator: Fathi Salem Sponsored By: Final Report April 30, 2010 . 1

95

Where data_out is the data to be written into the pot.

One problem we had with this function is that data_out can only be an 8-bit value, and as

stated above, a 16-bit data had to be written to the pot. This problem was easily solved by writing the

function twice. Data are transferred from the PIC starting with the most significant bit and ending with

the least significant bit. Therefore, In the first WriteSPI function, data_out = command byte, and

in the second one, data_out =data byte.

1.3.3.6 Chip select:

As shown in figure 8, the CS must be set low (by sending a 0 from the RC2 pin) before the data

is clocked into the pot. To execute the command, the CS is set high (by sending a 1 from RC2). It is

important to note that the number of clock rising edges must be 16 while CS is low, otherwise the

command will be aborted. This was taken care of when sync_mode was set to SPI_FOSC_64.