11 ms·
HDMI offers so many protocols I didn’t know of. Before finding a way to use DDC on Apple Silicon [1] for Lunar (https://lunar.fyi https://lunar.fyi), I contemp
by alin23 4y ago
HDMI offers so many protocols I didn’t know of.
Before finding a way to use DDC on Apple Silicon [1] for Lunar (https://lunar.fyi https://lunar.fyi), I contemplated creating a universal DDC/CI device that can change brightness, contrast, volume, input and colors of a monitor, by either receiving commands through HTTP, or acting as an Adaptive Brightness standalone device.
In my mind, it would have been an HDMI dongle with an ESP32 that gets power through the 5V line of the HDMI port, and which has an ambient light sensor to adapt brightness by itself.
In the end, I found the I2C APIs on M1 so this was not so sorely needed anymore, but given the limitations of the M1 Display Coprocessor, I still think it might be a good idea. I just have no idea where would I start with hardware distribution and mass production, this domain seems so intangible from the software development side.
[1] https://alinpanaitiu.com/blog/journey-to-ddc-on-m1-macs/ https://alinpanaitiu.com/blog/journey-to-ddc-on-m1-macs/
- alana314 4y agoI found Lunar through your blogs and love both!
- alin23 4y agoThanks! Happy to hear that it’s so useful!
- bliblablub4 4y agoHave you considered using HTTPS?
- alin23 4y agoI’m not sure I understand, what should I use HTTPS for?
- ajolly 4y agoOh man, I want lunar.fyi for windows, especially auto brightness, for multiple monitors based on ambient light.
- gregmac 4y agoIt doesn't have ambient light sensing, but I use Twinkle Tray [1] for controlling multiple monitors at once. It has a time schedule feature, and my hacky-but-functional setup is to have it reduce the brightness a bit every 30 minutes between 5:30 and 9pm -- on my setup it goes 80% to 20%. I have it reset back to 80% before I start using it in the morning. [1] https://github.com/xanderfrangos/twinkle-tray https://github.com/xanderfrangos/twinkle-tray
- alin23 4y agoWell, unfortunately that will never happen because the app would need a full rewrite using DirectX and WinAPI. Fortunately there’s an open source alternative called TwinkleTray: https://github.com/xanderfrangos/twinkle-tray https://github.com/xanderfrangos/twinkle-tray Someone determined enough could add adaptive brightness to it. You can even use Lunar’s wireless ambient light sensor [1] for that as it’s simply sending lux values through Server Sent Events [2] [1] https://lunar.fyi/sensor https://lunar.fyi/sensor [2] https://github.com/alin23/lunarsensor https://github.com/alin23/lunarsensor
- mintplant 4y agoThere's also Monitorian for Windows: https://github.com/emoacht/Monitorian https://github.com/emoacht/Monitorian
- jorvi 4y agoAnd for a more advanced feature set, ClickMonitorDDC. Sadly it is no longer hosted by the company where the developer worked. I mailed them, asking where the dev went or if they could put me in contact with him so he could release the source code. Regretfully I never got a response.
- vuciv1 4y agoI’m sorry, but most of this is gibberish to me. How did you learn about all this? Would you be kind enough to go into more depth? I’m curious. Your comments also gave me my daily reminder of how little I know (in the best way)
- alin23 4y agoNo worries! The same sentiment is what keeps me enthusiastic about programming day after day :) So computer monitors have support for a communication protocol called Display Data Channel which is normally used by the host (Mac, PC) to get info about supported resolutions, frame rates, signal timing etc. On top of that, a command interface has been created called MCCS or Monitor Control Command Set [1] which allows changing brightness, volume, input and a ton of other aspects of the monitor, by sending specific bytes through the cable. That cable can be HDMI, DisplayPort, Thunderbolt, VGA, DVI. It doesn’t matter, as long as it has dedicated wires to carry the I2C signal. I2C is the 2-wire communication protocol used by DDC, and it basically defines things like “a pulse of 5V (volts) of x milliseconds followed by 0V of y milliseconds means the 0 bit. The 1 bit is represented by a pulse of 5V of 2x milliseconds”. It’s a bit more complex than that, also defining TCP-like features with data frames and ACK packets, but you get the idea. It’s something that both devices agree on so that they can send raw bytes using 5 volt pulses. I’ve created Lunar as an adaptive brightness app for macOS after finding out about a little CLI called ddcctl: https://github.com/kfix/ddcctl https://github.com/kfix/ddcctl That’s where I learned how DDC packets look like, where to place the payload (brightness value between 0 and 100, input ID, etc) and how to write that to the monitor using the macOS I2C APIs. When Apple Silicon came out, none of that was possible anymore so I had to go looking around kernel assembly and private macOS frameworks for “the Apple Silicon way” of writing data through I2C. If you’re also curious how I learned that, it’s a very cool domain called “reverse engineering” and I learned it while working as a Malware Researcher at Bitdefender. A bit hard to get started, but so many gems to discover once you know how to open binaries in IDA/Hopper and look around their disassembled code. [1] https://milek7.pl/ddcbacklight/mccs.pdf https://milek7.pl/ddcbacklight/mccs.pdf
- byt3swap 4y agoI also started working on something similar a while back, unfortunately got sidetracked with other things before I got many of the features (color adjustment, contrast, etc) implemented. Both of the monitors on my desk have ESP32 based HDMI dongles plugged into a spare HDMI port. I have 2 USB 3.0 switches that have been retrofitted with ESP32s as well, one for my keyboard and mouse, and one for a hub on my desk. A short press of the button on the switch on my desk will switch my keyboard/mouse between my desktop and a thunderbolt 4 dock, which will then trigger both of the monitors to switch the the inputs that are also connected to the dock. A long press of the button will do the same, but will also switch the secondary hub over (speakers, mic, webcam, and a few free ports for flash drives and the like). I was looking for an alternative option to an expensive KVM that would do the job I needed. As a 'poor man's KVM' it works pretty well, though I do hope to flesh out the rest of DDC/CI to get some of these other features implemented as well.
- alanbernstein 4y agoAny chance you could share more details, photos, product links, etc? I am working on something similar.
- byt3swap 4y agoI have a repo for the switch firmware, which has some pics and other details. Keep in mind though that was pretty quick and dirty, and I think there is a fix for the secondary switch that I still need to push. I should hopefully have some free time to get back to it soon though. The HDMI dongle repo is still private, and I really want to do some cleanup before making it public. But, as for parts, I just used a breakout off amazon, and some cheap perfboard to make a hat containing the ESP32. USB Switch Repo: https://github.com/byt3swap/mqtt_usb_switch https://github.com/byt3swap/mqtt_usb_switch HDMI Breakout: https://www.amazon.com/gp/product/B075Q83W5F https://www.amazon.com/gp/product/B075Q83W5F
- alin23 4y agoThat sounds awesome! Have you ended up using this DDC library? https://www.arduinolibraries.info/libraries/ddc-ci-vpc-library https://www.arduinolibraries.info/libraries/ddc-ci-vpc-libra... Or did you end up coding your own raw I2C implementation?
- alanbernstein 4y agoLooks like lunar.fyi is just for Mac, right? Any idea about an equivalent on Linux? I want to add an input switch shortcut on my keyboard, but I want it to work on both machines.
- alin23 4y agoddcutil is the standard utility on Linux for that. It is just command line but it’s highly compatible and very easy to use: https://www.ddcutil.com/ https://www.ddcutil.com/ I even use it for the network-based DDC in Lunar through a Raspberry Pi when wire-DDC from the Mac is not available: https://alinpanaitiu.com/blog/journey-to-ddc-on-m1-macs/#the-raspberry-pi-idea https://alinpanaitiu.com/blog/journey-to-ddc-on-m1-macs/#the...
- happyhardcore 4y agoThis just solved a problem I have that I never knew there was a solution for! It seems really weird to me that every OS doesn't have a native solution for changing external monitor brightness; I thought it was down to the monitor but clearly it isn't. Thanks for the link and thanks for your work on Lunar!
- alin23 4y agoI’m happy you find it useful! Well it kinda is up to the monitor. Given how many monitors don’t implement the DDC/CI standard correctly and flash and crash and blackout on simple brightness change commands, it would turn into a PR nightmare at the scale of an operating system. I’m overwhelmed by the daily support I have to provide for Lunar users and I barely have 20k users. I can’t even imagine how bad it would be if 100k users started having their monitor crash or lose color on “such a simple thing as changing brightness”.
- Xeoncross 4y agoWow, this looks fantastic! No one ever mentions that the Apple displays integrate with the brightness controls on macs. This can be a major quality-of-life feature if you work during the day and night and don't want to keep changing brightness on multiple monitors every day. However, I have non-Apple displays as well. Just tried https://lunar.fyi/ https://lunar.fyi/ via usbc and it worked great so far!
- alin23 4y agoI see a lot of questions on the internet on “how do I control monitor brightness on macOS?” and a lot of “just use Control+Brightness Up/Down” answers from people not realizing that only Apple vendored monitors support that. And that’s only possible because Apple implements a proprietary USB protocol inside their monitors for changing brightness so they have smooth transitions and be sure it works every time. I’m pretty sure they’ll never touch DDC/CI for that, and rightfully so as it has very spotty support, especially with these new Thunderbolt hubs/adapters and smart monitors. I’m glad Lunar works for you!
- behnamoh 4y agoThis was documented here: https://medium.com/@parttimeben/mac-it-just-works-horribly-c98fd9be4001 https://medium.com/@parttimeben/mac-it-just-works-horribly-c... I personally blame Apple for not supporting CEC. I have over 19 apps running in the background to “fix” macOS.
- sharikous 4y agoDo you happen to know if the HDMI port on 2021 MacBook Pros passes DDC commands? Because even with Lunar I couldn't make it control my monitor. A nuisance, actually. And could a hypothetical Asahi Linux make it work?
- alin23 4y agoThe HDMI port on newer Macs doesn’t work with DDC, I’ve tried to document that here: https://lunar.fyi/faq#brightness-not-changing https://lunar.fyi/faq#brightness-not-changing These HDMI ports use an internal MCDP29xx chip to convert the HDMI signal to DisplayPort. That chip supports DDC, but the method we use to write the DDC commands to the monitor (IOAVServiceWriteI2C) fails when used through it. There are other WriteI2C methods specifically for this chip inside the DCPAVFamilyProxy.kext but they’re not available to be used inside an app like Lunar. Asahi Linux shouldn’t be limited by the API, but the problem might be in the MCDP chip firmware itself. 1 year later, I’m still investigating new methods to fix this but so far I have no results.
- deleted 4y ago[deleted]
- deleted 4y ago[deleted]
- orliesaurus 4y agoYour website (Lunar) looks incredible. It's clean and concise from a design standpoint, but also quite in depth in content you have on it- congrats!
- alin23 4y agoThank you! It was built incrementally over the past year to reach this state, so I thought it might be a tad too long and in-depth :) happy to hear you find it just right!
- ElCapitanMarkla 4y agoYour app is really cool. It solves a problem I didn’t realise I had until now… thank you?
- alin23 4y agoThank you as well! It’s nice to see I’m really solving problems and saving people time and frustration. That’s the only thing I like to create software for.
- Brajeshwar 4y ago[OffTopic] Thank you for Lunar.fyi. I tried Lunar and then stumbled on MonitorControl[1]. Went back to Lunar and bought the pro. I'm not aware of the details but Lunar just works with the LG external monitor and syncing with the iMac. 1. https://github.com/MonitorControl/MonitorControl https://github.com/MonitorControl/MonitorControl
- beltsazar 4y agoI'm using MonitorControl [1] and it works great. Plus, it is really open source, in contrast to Lunar which is "open source" but you can't build it as per its repo's README: > Lunar can't be built from this repo yet as the source code for the paid features is hidden. [1]: https://github.com/MonitorControl/MonitorControl https://github.com/MonitorControl/MonitorControl
- alin23 4y agoThank you for the snark, but what you probably don’t know is that MonitorControl for M1 wouldn’t have been possible if I hadn’t open sourced Lunar’s code and my reasearch on that. All the work on MC after Apple Silicon is done by a previous Lunar user (@waydabber) which I helped for months on Discord until he got the implementation right, and then eventually got to do his own paid implementation called BetterDisplay. Lunar is my full time job, I can’t have it fully open source and still earn money from it. I would still be working at some corp on gluing web APIs if I hadn’t done this.
- forty 4y agoI think it's perfectly fine to do non open source work as long as one does not pretend to be open source. I had a quick look to your website at in all fairness, it's pretty clear that the product is proprietary and paid (at least it doesn't claim "the de facto open source app to ..."). In your comparison table I would suggest to put at least a yellow tick (rather than the green one currently) in the open source line though, because that is slightly misleading.
- alin23 4y agoDoes Open Source require the source to be compilable? The free parts of the app are fully open source with an MIT license, you’re free to modify it and add mocks for the paid parts. It’s gonna be hard, but infinitely easier than having to rewrite such an app from scratch. For me, the source code is there and open, call it whatever you want, they’re just vague terms anyway. I’m gonna keep calling it open source.