The files contained in this repository can be downloaded to your computer using a svn client.
On Linux you simply type the command displayed below.
This URL has Read-Only access.
root / trunk / DomotiGa / FControl.class @ 25
History | View | Annotate | Download (3 kB)
| 1 | ' Gambas class file |
|---|---|
| 2 | |
| 3 | ' Description: |
| 4 | ' FControl.class |
| 5 | ' Device control page. |
| 6 | |
| 7 | ' Development Status: |
| 8 | ' Not implemented fully. |
| 9 | |
| 10 | ' DomotiGa - an open source home automation program. |
| 11 | ' Copyright(C) 2008 Ron Klinkien |
| 12 | |
| 13 | ' Read file called COPYING for license details. |
| 14 | |
| 15 | PUBLIC SUB Form_Open() |
| 16 | |
| 17 | RefreshPage() |
| 18 | |
| 19 | END |
| 20 | |
| 21 | '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 22 | ' create dynamic buttons for switchable and dimable devices only |
| 23 | '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 24 | PUBLIC SUB RefreshPage() |
| 25 | |
| 26 | DIM rDevice AS Result |
| 27 | DIM sValue, sIcon AS String |
| 28 | DIM hButton AS Button |
| 29 | DIM iY, iYy AS Integer = 40 |
| 30 | DIM oIcon AS Object |
| 31 | |
| 32 | TRY rDevice = Main.hDB.Exec("SELECT onicon, officon, address, switchable, dimable, id, value, name FROM devices")
|
| 33 | IF (rDevice.Count > 0) THEN |
| 34 | FOR EACH rDevice |
| 35 | IF rDevice!dimable THEN |
| 36 | hButton = NEW Button(FControl) AS "MinusButton" |
| 37 | WITH hButton |
| 38 | .X = 220 |
| 39 | .Y = iYy |
| 40 | .Text = "-" |
| 41 | .Height = 35 |
| 42 | .Width = 25 |
| 43 | .Tag = rDevice!address |
| 44 | END WITH |
| 45 | hButton = NEW Button(FControl) AS "DimButton" |
| 46 | WITH hButton |
| 47 | .X = 220 + 26 |
| 48 | .Y = iYy |
| 49 | .Text = rDevice!name |
| 50 | .Height = 35 |
| 51 | .Width = 110 |
| 52 | .Tag = rDevice!address |
| 53 | .Font = Font["Sans Serif, 7, Normal"] |
| 54 | END WITH |
| 55 | hButton = NEW Button(FControl) AS "PlusButton" |
| 56 | WITH hButton |
| 57 | .X = 220 + 26 + 111 |
| 58 | .Y = iYy |
| 59 | .Text = "+" |
| 60 | .Height = 35 |
| 61 | .Width = 25 |
| 62 | .Tag = rDevice!address |
| 63 | END WITH |
| 64 | iYy += 48 |
| 65 | END IF |
| 66 | |
| 67 | IF rDevice!switchable THEN |
| 68 | sValue = UCase(rDevice!value) |
| 69 | IF UCase$(rDevice!value) = "ON" OR UCase$(rDevice!value) = "OPEN" OR UCase$(rDevice!value) = "MOTION" THEN |
| 70 | hButton = NEW Button(FControl) AS "SwitchButton_Off" |
| 71 | TRY oIcon = Picture["icons/" & rDevice!onicon] |
| 72 | ELSE |
| 73 | hButton = NEW Button(FControl) AS "SwitchButton_On" |
| 74 | TRY oIcon = Picture["icons/" & rDevice!officon] |
| 75 | END IF |
| 76 | |
| 77 | WITH hButton |
| 78 | .X = 40 |
| 79 | .Y = iY |
| 80 | .Text = rDevice!name |
| 81 | .Height = 35 |
| 82 | .Width = 130 |
| 83 | .Tag = rDevice!name |
| 84 | .Picture = oIcon |
| 85 | IF Len(rDevice!name) > 12 THEN .Font = Font["Sans Serif, 7, Normal"] |
| 86 | END WITH |
| 87 | iY += 48 |
| 88 | END IF |
| 89 | NEXT |
| 90 | END IF |
| 91 | |
| 92 | END |
| 93 | |
| 94 | PUBLIC SUB SwitchButton_Off_Click() |
| 95 | |
| 96 | Devices.SetDevice(LAST.tag, "Off") |
| 97 | RefreshPage() |
| 98 | |
| 99 | END |
| 100 | |
| 101 | PUBLIC SUB SwitchButton_On_Click() |
| 102 | |
| 103 | Devices.SetDevice(LAST.tag, "On") |
| 104 | RefreshPage() |
| 105 | |
| 106 | END |
| 107 | |
| 108 | PUBLIC SUB DimButton_Click() |
| 109 | |
| 110 | Message(LAST.tag & " was clicked!") |
| 111 | RefreshPage() |
| 112 | |
| 113 | END |
| 114 | |
| 115 | PUBLIC SUB MinusButton_Click() |
| 116 | |
| 117 | Main.hCTX35.sCommandToSend = LAST.tag & " DIM" |
| 118 | ' Message("Dim for " & LAST.tag & " was clicked!")
|
| 119 | RefreshPage() |
| 120 | |
| 121 | END |
| 122 | |
| 123 | PUBLIC SUB PlusButton_Click() |
| 124 | |
| 125 | Main.hCTX35.sCommandToSend = LAST.tag & " BRIGHT" |
| 126 | ' Message("Bright for " & LAST.tag & " was clicked!")
|
| 127 | RefreshPage() |
| 128 | |
| 129 | END |
