Ana səhifə

Leopard II manual Table of Contents


Yüklə 3.21 Mb.
səhifə4/16
tarix24.06.2016
ölçüsü3.21 Mb.
1   2   3   4   5   6   7   8   9   ...   16

1.6Writing your First Program


This chapter has been inserted as a transition between the installation guide and the programming guide sections of the manual to give first time users the opportunity to familiarize themselves with the process of creating a working Leopard II application by showing the step by step creation of a project. The goal is not to provide a how-to guide on programming logic itself but simply to illustrate the typical steps involved in creating a project from start to finish. This is analogous to the first exercise often given to students learning a new computer language where the goal is to simply create a program that prints or displays “Hello World”.




1.6.1Creating a Project

Since this is a Home Automation controller, saying “Hello” to the world will consist in creating a screen with a text label and two buttons, used to turn an X-10 controlled light On and Off. We will begin by starting up the C-Max program and looking at the main screen (see fig. 5). This is the program editor window and is the main startup screen. The first step is to create a project, so click on the Project menu at the top left and on the pull down menu, select New Project. You will see a file browsing window like the one in fig. 9




Fig. 9


It is a good idea to keep each project in it’s own directory, so click on the new folder icon (the small file folder with a sparkle on it) and create a folder for your project. Then go into that folder and enter the file name you want to use for this project. In the example shown in fig. 9, both the folder and the project have been named “first project”. Clicking on Open will create the project and the window will close.
Now, anytime you want to save your work in progress, just click on Project on the main window and then click on Save Project to save all the files related to the project currently opened.


1.6.2The System Map

C-Max is the editor for several ADI controller models and expansion modules so it is necessary to tell it what our particular configuration will be. That way, the program editor will offer the right options when several possibilities exist. This project only assumes that we are using the Leopard II by itself so this is the only item that really needs to be configured in the System Map. Click on Project and then on System Map. You will see a window similar to fig. 10:





Fig. 10 Fig. 11

This window shows a list of the modules and the small “+” signs show that these items can be open in tree-like fashion to define other items. The first item at the top defines the master controller and shows Ocelot by default. The Ocelot is another ADI controller similar to the Leopard II but without a touch screen. Since we want to be able to use the touch screen functionality of the Leopard II, right click on Ocelot and choose Leopard in the small list of choices shown. Your screen should now look like fig. 11. You may now close the System Map window by clicking on the “x” in the upper right hand corner.




1.6.3The Touch screen Layout

Now that the editor “knows” our configuration, we may begin to create the actual application. We could begin with either the program text or the screen layout. Since we need to know the button’s screen object number (which is assigned as the button is created) when referring to it in the program, it will be easier to start with the screen and take note of the object numbers for our program. From the main screen, click on Project and then Touch Screen Setup. You will see a window like the one in fig. 12:




Fig. 12
Let’s start by putting a text heading on the screen. Click on Screen Text on the right hand side (there is no frame around this choice). You will see a small text window in the upper left corner of the touch screen area. Right click on it and choose Enter Text. An editing window will appear on the screen (fig. 13)

Fig. 13

Enter the text you wish to see as a window heading. In our example, “My First Project” has been entered. The Large font radio button has also been selected. For this project, you can ignore the Variable list box. When you click on OK you will see your text object with the new text and large size in the upper left of the screen area. Click and drag it towards the upper center of the screen. Note that moving the mouse pointer over it will show that it is object #1.


Now we want to add the two buttons to control our X-10 light. In the button area, click on the one identified as “single”. It will appear in the upper left of the touch screen. Again, right click on the object and choose Enter Caption. You will see an editing box (fig 14).


Fig. 14

This will be the ON button so enter “ON” as the caption and choose the Large font. Ignore the other options and click on OK. The button will now show it’s caption. Drag the button under the previously created heading. At this point your screen should look something like fig 15:





Fig. 15


Float your mouse cursor over the button you have just created and note that it is object #2. Create the OFF button by repeating the procedure just explained and give it an “OFF” caption. It’s object number will be 2. Under the screen area, notice the four radio buttons and the slider/edit box. You may select Beep on Touch to hear a low volume beep every time the screen is touched (since there is no tactile feedback). Show Date and Time will display the date and time in the upper right corner of the screen if selected. Finally, use the slider or edit box to enter a time delay (in seconds) after which the screen backlighting will turn off unless it is touched again.

Our screen definition is now finished and should look like fig. 16:




Fig. 16


Since this screen definition is part of a project, there is no need to save it separately, so just close the window by clicking on the “x” in the upper right. Click on OK when you see the confirmation window that warns you about closing the screen editor window without first saving. You will be brought back to the main window. This would be a good time to save our work in progress so click on Project then Save Project.


1.6.4Writing the Program Code

Now we reach the point where we write the actual program code for our project. Under the Program Text heading, double click on line #1. You will get the control wizard screen as shown in fig. 17. Select the IF instruction type and then Touch Button Pressed instruction (use the vertical scroll bar to find this instruction.). The window will update its available controls to show the ones that apply to a Touch Button. Leave the Module choice as being Leopard since this is our only module. Since we noted that the ON button was object #2 in the touchscreen editor, select Touch Object #2 in the Button list box. Once all these selections have been made click on the large Enter Touch Button button at the bottom of the control wizard and you will see your newly created program line in the main window.




Fig. 17 Fig. 18

Now double click on line 2 and create the corresponding action statement. Once again you will get the control wizard screen as shown in fig. 18. Select the THEN instruction type and then the X10 Quick ON/OFF instruction (use the vertical scroll bar to find this instruction.). The window will update its available controls to show the ones that apply to an X10 Quick ON/OFF instruction. Choose an X10 house code/ unit code combination that corresponds to a light, lamp or whatever device that you want to try your first program with. Then click on the Turn ON radio button. Once these selections have been made click on the large Enter Program Line button at the bottom of the control wizard and you will again see your newly created program line in the main window.
Using the same technique learned with the first two lines, now create the next two lines that will allow us to turn the device OFF. Just double click on the line you want to create or edit and make the appropriate choices. The difference between the first pair of lines and the second pair is that you will now be looking for button #3 being pressed and the resulting action will be to trigger an X10 Turn OFF command. Make sure you select the same X10 house and unit codes as in the first two lines!

Now we need to do some screen control to make our simple program work correctly. Remember when you were doing the touch screen layout? The tab at the top showed that you were editing screen #1 (see fig. 16). You can have up to 24 screens each containing any combination of buttons, text objects or status lights (see the reference section of the manual to learn how to use these). Displaying one screen or another is done under program control and can be in any way you like, like pressing a button, receiving an X10 command, by time of day, etc. Since our simple program only has one screen, we want it to be displayed at all times. When the Leopard II if first powered up or a new program is loaded into it, it displays a blank screen and the special variable that specifies the desired screen # is

set to 255. We thus want a program segment that looks for the screen variable not being equal to 1 and if so, set it to 1. Edit the next to lines to test and act upon variable #63 (called the screen variable) to do just that. Your control wizard windows should look like figures 19 and 20 for the IF and THEN statements.







Fig. 19 Fig. 20

We’re almost done! We have the test and action statements to turn the device ON, another test and action statement pair to turn it OFF, and a program segment to make sure we’re displaying screen #1. All we need now is an END statement. Double click on the next line and in the control wizard, select the END command type. There are no other options to this command so you can now close the command wizard by clicking on the “x” in the upper right hand corner. You will see an End Program line on the main screen. Your program is now complete and should look a lot like the one shown in fig. 21 with the possible exception that the house and unit codes for the X10 device will be the ones you chose. Note that you can also add comments for each line as shown in fig. 21. To do this, just click the line you want to comment on under the Comments heading and enter your comments. Now, this would be a good time to save your project, so click on Project then Save Project.

Fig. 21

The only thing left to do at this point is to get the screen definition and program code into the Leopard II and actually try it. To do this, click on Project then Download Project. You will see a project downloading window like the one in fig. 22. Using the check boxes, select the Download Program and Download Touch Screen options. This project does not use icons so there is no need to select the icons download. There will be no harm done if you download icons but the download will take more time if you do so.



Fig. 22
Click on Begin Download. The controller access window will appear and show the progress of the operation (see fig. 23). Watch the status window messages and the progress bar to see the touch screen objects and then the program get downloaded (you will see the progress bar for each of these operations). When complete, a small window will appear (fig. 24) indicating that the controller is being restarted.

Fig. 23


Fig. 24


Watch your Leopard II screen now. You will see it “reboot” and after a delay lasting a few seconds you should see the screen layout you created! Try pressing the ON and OFF buttons to control your X10 device. Congratulations, you have completed your first Leopard II project. Of course, your actual application will be much more complex but the basic steps involved in creating it will be very similar to the ones just covered.
The next manual section deals with the programming model used for the program logic. It is strongly suggested that you read it carefully and make sure you understand the general principles used to create an application.
1   2   3   4   5   6   7   8   9   ...   16


Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©atelim.com 2016
rəhbərliyinə müraciət