-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathSWUpdateGUI_ipaddress.lua
executable file
·162 lines (135 loc) · 3.75 KB
/
SWUpdateGUI_ipaddress.lua
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
#!/usr/bin/env lua
-- (C) Copyright 2018
-- Stefano Babic, DENX Software Engineering, [email protected].
--
-- SPDX-License-Identifier: GPL-2.0-or-later
--
ui = require "tek.ui"
local Button = ui.Button
local VerboseCheckMark = ui.CheckMark:newClass { _NAME = "_vbcheckmark" }
local VerboseRadioButton = ui.RadioButton:newClass { _NAME = "_vbradiobutton" }
-------------------------------------------------------------------------------
-- Create IPAddress class:
-------------------------------------------------------------------------------
IPAddress = ui.Group:newClass { _NAME = "_ipaddress"}
NetAddress = ui.Group:newClass { _NAME = "_netaddress"}
function IPAddress.getAddress(class,self)
return self.address
end
function IPAddress.new(class, self)
self = self or { }
self.Class = "ipaddress"
Orientation = "vertical"
grp = ui.Group.new(class, self)
self.buttons = {}
for i = 1, 4 do
button = ui.Button:new(addr)
self.buttons[i] = ui.Button:new {
incaddr = function(self, step)
val = tonumber(self.Text) + step
if (val > 255) then
val = val % 256
end
self:setValue("Text", tostring(val))
end,
onClick = function(self)
self:incaddr(1)
--val = tonumber(self.Text) + 1
--if (val > 255) then
-- val = 1
--end
--self:setValue("Text", tostring(val))
end,
onHold = function(self)
self:incaddr(10)
end
}
self.buttons[i].Text= "1"
grp:addMember(self.buttons[i])
end
return grp
end
function IPAddress:setip(address)
local count = 1
self.address = address
local chunks = {address:match("(%d+)%.(%d+)%.(%d+)%.(%d+)")}
if not (#chunks == 4) then
return
end
for ipx in address:gmatch("([^.]+),?") do
self.buttons[count]:setValue("Text", ipx)
count = count + 1
if (count > 4) then
break
end
end
end
function IPAddress:getip()
addr = ""
for i = 1,4 do
local tmp = self.buttons[i].Text
if (i == 1) then
addr = tmp
else
addr = addr .. "." .. tmp
end
end
return addr
end
function IPAddress:enable(enable)
for i = 1, 4 do
self.buttons[i]:setValue("Disabled", not enable)
end
end
function NetAddress.new(class, self, defaultip, defaultnetmask)
self = self or { }
self.Class = "netaddress"
self.defaultip = defaultip
self.defaultnetmask = defaultnetmask
self.grp = ui.Group.new(class, self)
self.dhcp = ui.CheckMark:new
{
Text = "dhcp",
Id = "dhcp",
Selected = true,
onSelect = function(self)
ui.RadioButton.onSelect(self)
self.parent:enable(self.Selected)
end
}
self.dhcp.parent = self
self.grp:setValue("Orientation", "vertical")
self.grp:addMember(self.dhcp)
self.ip = IPAddress:new { Legend = "IP Address"}
self.grp:addMember(self.ip)
self.grp:addMember(ui.Spacer:new { })
self.netmask = IPAddress:new { Legend = "Netmask"}
self.grp:addMember(self.netmask)
return self.grp
end
function NetAddress:enable(dhcp)
self.dhcp:setValue("Selected", dhcp)
self.ip:enable(not dhcp)
self.netmask:enable(not dhcp)
end
function NetAddress:justaddress()
self.dhcp:setValue("Disabled", true)
self.ip:enable(true)
self.netmask:enable(false)
end
function NetAddress:deactivate()
self.dhcp:setValue("Disabled", true)
self.ip:enable(false)
self.netmask:enable(false)
end
function NetAddress:setip(endhcp, ip, netmask, gateway)
self.dhcp:setValue("Disabled", false)
self.dhcp:setValue("Selected", endhcp)
self.ip:enable(self.ip, not endhcp)
self.netmask:enable(self.netmask, not endhcp)
self.ip:setip(ip)
self.netmask:setip(netmask)
end
function NetAddress:getip()
return self.dhcp.Selected, self.ip:getip(), self.netmask:getip()
end