Skip to content

Commit 98e78a9

Browse files
author
TeaRex-coder
committed
update ui
1 parent cb6dc21 commit 98e78a9

File tree

3 files changed

+51
-31
lines changed

3 files changed

+51
-31
lines changed

ui/README.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
# User Interface
22

3-
HardwareDDC's goal is to provide and easy and convenient way to adjust monitor settings. Therefore, I prioritized an efficient macro-based UX and have not yet release a GUI.
3+
HardwareDDC's goal is to provide and easy and convenient way to adjust monitor settings. Therefore, I prioritized an efficient macro-based UX and have not yet released a first-party GUI.
44

55
Currently, HardwareDDC is controlled with hotkeys sending API requests.
66

77
## macOS
88

9+
### Lunar
10+
11+
Lunar, _the defacto app for controlling monitors_, can be used as HardwareDDC's interface instead of Hammerspoon for those preferring a GUI.
12+
13+
1. Install [Lunar](https://static.lunar.fyi/releases/Lunar.dmg)
14+
2. Disable all controls aside from _Network (Raspberry Pi)_
15+
3. Reset _Network Control_
16+
17+
### Hammerspoon
18+
919
1. Install [Hammerspoon](https://www.hammerspoon.org)
1020
2. Add [hardware-ddc.lua](./macos/hardware-ddc.lua) to your Hammerspoon config `~/.hammerspoon/init.lua`
1121

@@ -77,17 +87,17 @@ This is coming soon, but you're a Linux user, you can figure it out.
7787
Specify brightness percentage:
7888

7989
```bash
80-
curl -X GET "http://hardwareddc.local/brightness?value=<value 0-100>"
90+
curl -X GET "http://ddcutil.local:3485/1/brightness/<value 0-100>"
8191
```
8292

8393
Get current brightness:
8494

8595
```bash
86-
curl -X GET "http://hardwareddc.local/brightness"
96+
curl -X GET "http://ddcutil.local:3485/1/brightness"
8797
```
8898

8999
Change input source:
90100

91101
```bash
92-
curl -X GET "http://hardwareddc.local/set_source?value=<hexadecimal source code>"
102+
curl -X GET "http://ddcutil.local:3485/1/input_source<hexadecimal source>"
93103
```

ui/macos/hardware-ddc.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
function setSource(value, name)
2-
local url = "http://hardwareddc.local/set_source?value=" .. value
2+
local url = "http://ddcutil.local:3485/1/input_source/" .. value
33
hs.http.asyncGet(url, nil, function(status, body, headers)
44
end)
55
end
@@ -21,7 +21,7 @@ function setHDMI2()
2121
end
2222

2323
function setBrightness(value)
24-
local url = "http://hardwareddc.local/brightness?value=" .. value
24+
local url = "http://ddcutil.local:3485/1/brightness/" .. value
2525
hs.http.asyncGet(url, nil, function(status, body, headers)
2626
end)
2727
end
@@ -47,8 +47,8 @@ function setBrightness100()
4747
end
4848

4949
function getBrightness(callback)
50-
hs.http.asyncGet("http://hardwareddc.local/brightness", nil, function(_, body)
51-
local brightness = hs.json.decode(body).current_brightness
50+
hs.http.asyncGet("http://ddcutil.local:3485/1/brightness", nil, function(status, body)
51+
local brightness = tonumber(body)
5252
callback(brightness)
5353
end)
5454
end

ui/windows/hardware-ddc.ahk

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,36 @@
1-
setSource(value) {
2-
url := "http://hardwareddc.local/set_source?value=" value
3-
Http := ComObjCreate("WinHttp.WinHttpRequest.5.1")
4-
Http.Open("GET", url, false)
5-
Http.Send()
1+
setSource(source) {
2+
url := "http://ddcutil.local:3485/1/input_source/" source
3+
HttpRequest(url)
64
}
75

86
setBrightness(value) {
9-
url := "http://hardwareddc.local/brightness?value=" value
10-
Http := ComObjCreate("WinHttp.WinHttpRequest.5.1")
11-
Http.Open("GET", url, false)
12-
Http.Send()
7+
url := "http://ddcutil.local:3485/1/brightness/" value
8+
HttpRequest(url)
139
}
1410

15-
getBrightness() {
16-
url := "http://hardwareddc.local/brightness"
17-
Http := ComObjCreate("WinHttp.WinHttpRequest.5.1")
18-
Http.Open("GET", url, false)
19-
Http.Send()
20-
response := Http.ResponseText
21-
RegExMatch(response, """current_brightness"":\s*(\d+)", match)
22-
return match1
11+
adjustBrightness(amount) {
12+
currentBrightness := currentBrightness()
13+
if (currentBrightness != -1) {
14+
newBrightness := currentBrightness + amount
15+
if (newBrightness < 0) {
16+
newBrightness := 0
17+
} else if (newBrightness > 100) {
18+
newBrightness := 100
19+
}
20+
setBrightness(newBrightness)
21+
}
2322
}
2423

25-
adjustBrightness(delta) {
26-
currentBrightness := getBrightness()
27-
newBrightness := currentBrightness + delta
28-
newBrightness := Max(0, Min(100, newBrightness))
29-
setBrightness(newBrightness)
24+
currentBrightness() {
25+
url := "http://ddcutil.local:3485/1/brightness"
26+
WebRequest := ComObjCreate("MSXML2.XMLHTTP")
27+
WebRequest.Open("GET", url, false)
28+
WebRequest.Send()
29+
if (WebRequest.Status = 200) {
30+
return WebRequest.ResponseText
31+
} else {
32+
return -1
33+
}
3034
}
3135

3236
increaseBrightness() {
@@ -37,6 +41,12 @@ decreaseBrightness() {
3741
adjustBrightness(-6)
3842
}
3943

44+
HttpRequest(url) {
45+
WebRequest := ComObjCreate("MSXML2.XMLHTTP")
46+
WebRequest.Open("GET", url, false)
47+
WebRequest.Send()
48+
}
49+
4050
^#!1::setSource(0x0f)
4151
^#!2::setSource(0x10)
4252
^#!3::setSource(0x11)
@@ -49,4 +59,4 @@ decreaseBrightness() {
4959
^!5::setBrightness(0)
5060

5161
^f1::decreaseBrightness()
52-
^f2::increaseBrightness()
62+
^f2::increaseBrightness()

0 commit comments

Comments
 (0)