Skip to content

Commit 9faf031

Browse files
authored
Added script and readme
1 parent c7da543 commit 9faf031

File tree

2 files changed

+154
-0
lines changed

2 files changed

+154
-0
lines changed

AccelBacklight.lua

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
-- AccelBacklight.lua
2+
3+
-- Helper functions to run when var changed in form
4+
--------------------------------------------------
5+
local function accelAngleChanged(value)
6+
accelAngle = value
7+
system.pSave("accelAngle",accelAngle)
8+
end
9+
10+
local function idleModeChanged(value)
11+
local switchCaseTable = {
12+
[1] = 0,
13+
[2] = 1,
14+
[3] = 2,
15+
[4] = 3
16+
}
17+
idleMode = switchCaseTable[value]
18+
system.pSave("idleMode",idleMode)
19+
end
20+
21+
local function ActiveModeChanged(value)
22+
local switchCaseTable = {
23+
[1] = 0,
24+
[2] = 1,
25+
[3] = 2,
26+
[4] = 3
27+
}
28+
activeMode = switchCaseTable[value]
29+
system.pSave("activeMode",activeMode)
30+
end
31+
32+
local function printToCmdChanged(value)
33+
printToCmd = value
34+
system.pSave("printToCmd",printToCmd)
35+
end
36+
--------------------------------------------------
37+
38+
-- Form to set vars
39+
local function initForm()
40+
local backlightModeSwitchCaseTable = {
41+
[0] = 1,
42+
[1] = 2,
43+
[2] = 3,
44+
[3] = 4
45+
}
46+
47+
form.addRow(2)
48+
form.addLabel({label="Activation Angle"})
49+
form.addIntbox(accelAngle, -90, 90, 40, 0, 5, accelAngleChanged)
50+
51+
form.addRow(2)
52+
form.addLabel({label="Idle Backlight Mode"})
53+
form.addSelectbox({"Always Off", "10s", "60s", "Always On"}, backlightModeSwitchCaseTable[idleMode], true, idleModeChanged, {})
54+
55+
form.addRow(2)
56+
form.addLabel({label="Active Backlight Mode"})
57+
form.addSelectbox({"Always Off", "10s", "60s", "Always On"}, backlightModeSwitchCaseTable[activeMode], true, ActiveModeChanged, {})
58+
59+
form.addRow(2)
60+
form.addLabel({label="Print to Console"})
61+
form.addSelectbox({"No", "Yes"}, printToCmd, true, printToCmdChanged, {})
62+
63+
collectgarbage()
64+
end
65+
66+
-- Helper function to print only when printToCmd is set to 1
67+
local function printCmd(text)
68+
if (printToCmd == 2) then
69+
print(text)
70+
end
71+
end
72+
73+
-- Loop function is called in regular intervals
74+
local function loop()
75+
if (system.getIMU()["p"] > accelAngle) then
76+
if (lastMode == activeMode) then
77+
return
78+
end
79+
dt = system.getDateTime()
80+
printCmd("Turning ON backlight - " .. (string.format("Time: %d-%02d-%02d, %d:%02d:%02d", dt.year, dt.mon, dt.day, dt.hour, dt.min, dt.sec)))
81+
system.setProperty("BacklightMode", activeMode)
82+
lastMode = activeMode
83+
else
84+
if (lastMode == idleMode) then
85+
return
86+
end
87+
dt = system.getDateTime()
88+
printCmd("Turning OFF backlight - " .. (string.format("Time: %d-%02d-%02d, %d:%02d:%02d", dt.year, dt.mon, dt.day, dt.hour, dt.min, dt.sec)))
89+
system.setProperty("BacklightMode", idleMode)
90+
lastMode = idleMode
91+
end
92+
end
93+
94+
95+
-- Application initialization.
96+
local function init(code)
97+
accelAngle = system.pLoad("accelAngle")
98+
if (accelAngle == nil) then
99+
accelAngle = 40
100+
system.pSave("accelAngle", accelAngle)
101+
end
102+
103+
idleMode = system.pLoad("idleMode")
104+
if (idleMode == nil) then
105+
idleMode = 0
106+
system.pSave("idleMode", idleMode)
107+
end
108+
109+
activeMode = system.pLoad("activeMode")
110+
if (activeMode == nil) then
111+
activeMode = 3
112+
system.pSave("activeMode", activeMode)
113+
end
114+
115+
printToCmd = system.pLoad("printToCmd")
116+
if (printToCmd == nil) then
117+
printToCmd = 1
118+
system.pSave("printToCmd", printToCmd)
119+
end
120+
121+
lastMode = system.getProperty("BacklightMode")
122+
123+
system.registerForm(1, MENU_APPS, "Accel. Backlight Config", initForm, nil, printForm)
124+
125+
dt = system.getDateTime()
126+
print("Application initialized - " .. (string.format("Time: %d-%02d-%02d, %d:%02d:%02d", dt.year, dt.mon, dt.day, dt.hour, dt.min, dt.sec)))
127+
collectgarbage()
128+
end
129+
130+
-- Application interface
131+
return {init = init, loop = loop, author = "matm616", version = "1.0", name = "AccelBacklight"}

readme.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# AccelBacklight
2+
Using the built in accelerometer on some Jeti TXs, such as the DS-12, this script allows you to turn on the backlight just by tilting the TX.
3+
4+
## Requirements
5+
- Jeti TX
6+
- Aceelerometer module
7+
- Space for another user application
8+
9+
## Installation
10+
1. Download `AccelBacklight.lua` from this repo and move it into `/Apps/` on the radio's SD card
11+
2. Go to `Main Menu` > `Applications` > `User Applications` then add the downloaded script
12+
13+
## Configuration
14+
There are 4 configurable settings that can be adjusted under `Main Menu` > `Applications` > `Accel. Backlight Config`
15+
- Activation Angle
16+
The angle at which the backlight should switch from "idle" to "active" (Turn on)
17+
- Idle Backlight Mode
18+
The mode the backlight should be on when less than the "Activation Angle"
19+
- Active Backlight Mode
20+
The mode the backlight should be on when more than the "Activation Angle"
21+
- Print to Console
22+
Whether to print to console whenever the switching form idle to active and vice versa along with a time stamp.
23+
Really just there for testing

0 commit comments

Comments
 (0)