Skip to content
This repository has been archived by the owner on Feb 17, 2020. It is now read-only.

Latest commit

 

History

History
52 lines (40 loc) · 1.53 KB

README.md

File metadata and controls

52 lines (40 loc) · 1.53 KB

LightKit

License CocoaPods compatible Carthage compatible

Access the ambient light sensors, and control MacBook's display & keyboard brightness in Swift.

LightKit

Warning: While it should be safe to play with the backlight, I am not responsible for any damages made to a computer using this code.

Installation

# Podfile
pod "LightKit"

# Cartfile
github "maxmouchet/LightKit"

Usage

import LightKit
let lk = LightKit()! // May be nil if it failed to open I/Os.

Note : Most methods and properties are returning optional as I/Os requests may fail if sensors and controllers could not be found.

Ambient light sensors

let lightSensorsReadings = lk.lightSensors
print("Left sensor: \(lightSensorsReadings?.left).")
print("Right sensor: \(lightSensorsReadings?.right).")

Display

print("Display brightness is \(lk.displayBrightness)")
lk.setDisplayBrightness(0.8) // A value between 0 and 1.
lk.setDisplayPower(false) // Put display to sleep
lk.setDisplayPower(true) // Wake up display

Keyboard

print("Keyboard brightness is \(lk.keyboardBrightness)")
lk.setKeyboardBrightness(0.8) // A value between 0 and 1.