GithubHelp home page GithubHelp logo

swift-ddc's Introduction

DDC (Swift library + command line tool)

This package provides the command line tool and the DDC library for Swift which can be used to get/set settings of displays compatible with the DDC/CI specification.

Usage

Command line tool

% ddc get-vcp-feature contrast  
Contrast = 75 / 100
% ddc get-vcp-feature brightness   
Luminance = 60 / 100
% ddc set-vcp-feature brightness 80
% ddc --help                         
OVERVIEW: Configures display settings over a DDC interface.

USAGE: ddc <subcommand>

OPTIONS:
  -h, --help              Show help information.

SUBCOMMANDS:
  list-displays           Lists connected displays.
  capabilities            Executes the Capabilities DDC/CI command.
  list-vcp-features       Lists VCP codes supported by the display.
  get-vcp-feature         Executes the Get VCP Feature DDC/CI command.
  set-vcp-feature         Executes the Set VCP Feature DDC/CI command.

  See 'ddc help <subcommand>' for detailed help.

Swift library

import DDC
let sem = DispatchSemaphore(value: 0)
let brightness: UInt16 = 75
let ddc = try DDC(framebuffer: framebuffer)
ddc.setVCPFeature(.brightness, to: brightness) {
	switch $0 {
	case .success(_):
		print("Brightness set to \(brightness)%")
	case .failure(let error):
		print("Failed to set brightness to \(brightness)%: \(String(describing: error))")
	}
	sem.signal()
}
ddc.getVCPFeature(.brightness) {
	switch $0 {
	case .success(let reply):
		print("Brightness: \(reply.present)%")
	case .failure(let error):
		print("Failed to get brightness: \(String(describing: error))")
	}
	sem.signal()
}
sem.wait()
sem.wait()

Installation of the ddc command line tool

Using brew

brew install aleksey-mashanov/brisyncd/ddc

Manual

swift build -c release
cp `swift build -c release --show-bin-path`/ddc /usr/local/bin/

Adding the DDC library as a dependency

To use the DDC library in a SwiftPM project, add the following line to the dependencies in your Package.swift file:

.package(url: "https://github.com/aleksey-mashanov/swift-ddc.git", from: "1.0.0"),

Finally, include DDC as a dependency for your executable target:

.product(name: "DDC", package: "swift-ddc"),

Credits

The original idea was taken from:

The main area of improvements is better stability through correct time intervals between DDC commands in accordance with the DDC/CI specification.

swift-ddc's People

Contributors

aleksey-mashanov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

swift-ddc's Issues

brew error: undefined method `cellar' for #<BottleSpecification:0x000000013daf2268>

macOS Ventura 13.1

$ brew install aleksey-mashanov/brisyncd/ddc
==> Tapping aleksey-mashanov/brisyncd
Cloning into '/opt/homebrew/Library/Taps/aleksey-mashanov/homebrew-brisyncd'...
remote: Enumerating objects: 29, done.
remote: Counting objects: 100% (29/29), done.
remote: Compressing objects: 100% (20/20), done.
remote: Total 29 (delta 5), reused 27 (delta 3), pack-reused 0
Receiving objects: 100% (29/29), 5.08 KiB | 2.54 MiB/s, done.
Resolving deltas: 100% (5/5), done.
Tapped 2 formulae (16 files, 15.0KB).
Error: aleksey-mashanov/brisyncd/ddc: undefined method `cellar' for #<BottleSpecification:0x000000013daf2268>

Swift library throws "IOI2CInterfaceOpen failed"

Hi there.

I try to use your library in my own project, but it throws an error, "IOI2CInterfaceOpen failed"

Then I build the command line tool binary file and it works fine.

my code here

var iterator = io_iterator_t()
guard IOServiceGetMatchingServices(kIOMasterPortDefault, IOServiceMatching("AppleDisplay"), &iterator) == kIOReturnSuccess else {
    return
}
defer { IOObjectRelease(iterator) }
while case let service = IOIteratorNext(iterator), service != 0 {
    do {
        let sem = DispatchSemaphore(value: 0)
        let ddc = try DDC(display: service)
        ddc.getVCPFeature(.brightness) {
            switch $0 {
            case .success(let reply):
                print("Brightness: \(reply.present)%")
            case .failure(let error):
                print("Failed to get brightness: \(String(describing: error))")
            }
            sem.signal()
        }
        sem.wait()
    } catch {
        print("try error")
    }
    IOObjectRelease(service)
}

Brightness not working

I have tried your library successfully on one external monitor with a Intel GPU. Then I switched to another Mac with a AMD gpu and the brightness change isn’t working although setVPC feature returns a success.
The problem is that it is working with this library https://github.com/reitermarkus/DDC.swift .
If you need more info, inform me. I will try to help.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.