-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLEDroid.b4a
More file actions
170 lines (162 loc) · 4.61 KB
/
Copy pathLEDroid.b4a
File metadata and controls
170 lines (162 loc) · 4.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
Build1=Default,matthewcabor.ledroid
File1=Layout.bal
FileGroup1=Default Group
Group=Default Group
Library1=core
Library2=http
Library3=httputils2
Library4=xml2map
ManifestCode=AddManifestText(~\n~<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="19"/>~\n~<supports-screens android:largeScreens="true" ~\n~ android:normalScreens="true" ~\n~ android:smallScreens="true" ~\n~ android:anyDensity="true"/>)~\n~SetApplicationAttribute(android:icon, "@drawable/icon")~\n~SetApplicationAttribute(android:label, "$LABEL$")
Module1=Starter
NumberOfFiles=1
NumberOfLibraries=4
NumberOfModules=1
Version=13
@EndOfDesignText@
#Region Project Attributes
#ApplicationLabel: LEDroid
#VersionCode: 1
#VersionName: 1.1.0
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
Dim brightness As Int
Dim IPAddress As String = "192.168.1.5"
Dim requestTimer As Timer
End Sub
Sub Globals
Dim EditIPButton As Button
Dim IPAddressText As EditText
Dim IPAddressLabel As Label
Dim PowerButton As Button
Dim IncreaseBrightnessButton As Button
Dim DecreaseBrightnessButton As Button
Dim SetRedButton As Button
Dim SetGreenButton As Button
Dim SetBlueButton As Button
Dim SetCyanButton As Button
Dim SetMagentaButton As Button
Dim SetYellowButton As Button
Dim SetWhiteButton As Button
Dim SetOrangeButton As Button
Dim AboutButton As Button
Dim ParsedData As Map
End Sub
Sub Activity_Create(FirstTime As Boolean)
requestTimer.Initialize("requestTimer", 100)
Activity.LoadLayout("Layout")
Activity.Title = "LEDroid Remote for WLED"
IPAddressText.Text = IPAddress
IPAddressLabel.Text = IPAddress
GetCurrentValues
Log("Width: " & Activity.Width & ", Height: " & Activity.Height)
End Sub
Sub Activity_Resume
GetCurrentValues
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub requestTimer_Tick
requestTimer.Enabled = False ' Fuck this shit, I'm out
End Sub
Sub EditIPButton_Click
IPAddressLabel.Visible = False
IPAddressText.Visible = True
IPAddressText.Enabled = True
End Sub
Sub IPAddressText_TextChanged (OldText As String, NewText As String)
IPAddress = NewText
End Sub
Sub IPAddressText_EnterPressed
IPAddressText.Enabled = False
IPAddressText.Visible = False
IPAddressLabel.Visible = True
IPAddressLabel.Text = IPAddress
GetCurrentValues
End Sub
Sub PowerButton_Click
SendGetRequest("http://" & IPAddress & "/win&T=2")
GetCurrentValues
End Sub
Sub IncreaseBrightnessButton_Click
Sleep(100)
If brightness < 20 Then
brightness = Min(255, brightness + 2)
Else
brightness = Min(255, brightness + 15)
End If
SendGetRequest("http://" & IPAddress & "/win&T=1&A=" & brightness)
End Sub
Sub DecreaseBrightnessButton_Click
Sleep(100)
If brightness < 20 Then
brightness = Max(0, brightness - 2)
Else
brightness = Max(0, brightness - 15)
End If
SendGetRequest("http://" & IPAddress & "/win&T=1&A=" & brightness)
End Sub
Sub SetRedButton_Click
SendGetRequest("http://" & IPAddress & "/win&T=1&R=255&G=0&B=0")
End Sub
Sub SetGreenButton_Click
SendGetRequest("http://" & IPAddress & "/win&T=1&R=0&G=255&B=0")
End Sub
Sub SetBlueButton_Click
SendGetRequest("http://" & IPAddress & "/win&T=1&R=0&G=0&B=255")
End Sub
Sub SetCyanButton_Click
SendGetRequest("http://" & IPAddress & "/win&T=1&R=0&G=255&B=255")
End Sub
Sub SetMagentaButton_Click
SendGetRequest("http://" & IPAddress & "/win&T=1&R=255&G=0&B=255")
End Sub
Sub SetYellowButton_Click
SendGetRequest("http://" & IPAddress & "/win&T=1&R=255&G=255&B=0")
End Sub
Sub SetWhiteButton_Click
SendGetRequest("http://" & IPAddress & "/win&T=1&R=255&G=255&B=255")
End Sub
Sub SetOrangeButton_Click
SendGetRequest("http://" & IPAddress & "/win&T=1&R=255&G=165&B=0")
End Sub
Sub AboutButton_Click
Msgbox("Check out my crappy code at github.com/matthewcabor", "Problems? No, LEDroid.")
End Sub
Sub GetCurrentValues
SendGetRequest("http://" & IPAddress & "/win")
requestTimer.Enabled = True ' Wait for BS
End Sub
Sub SendGetRequest(url As String)
requestTimer.Enabled = False ' Stupid timer
Dim job As HttpJob
job.Initialize("job1", Me)
job.Download(url)
End Sub
Sub JobDone (job As HttpJob)
If job.Success Then
Log("Data: " & job.GetString)
Dim xm As Xml2Map
xm.Initialize
xm.StripNamespaces = True
ParsedData = xm.Parse(job.GetString)
If ParsedData.IsInitialized Then
Try
Dim vs As Map = ParsedData.Get("vs")
brightness = vs.Get("ac")
Catch
Log("Error parsing XML: " & LastException.Message)
End Try
Else
Log("No brightness data received.")
End If
Else
Log("Error: " & job.ErrorMessage)
End If
job.Release
End Sub