Skip to content

Commit

Permalink
Release 0.1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
alexruperez committed May 16, 2017
1 parent 542e7c2 commit a12fd6a
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 51 deletions.
2 changes: 1 addition & 1 deletion AVPlayerItemHomeOutput.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'AVPlayerItemHomeOutput'
s.version = '0.1.4'
s.version = '0.1.5'
s.summary = 'Coordinate the output of content associated with your HomeKit lightbulbs. #Ambilight'

s.homepage = 'https://github.com/alexruperez/AVPlayerItemHomeOutput'
Expand Down
4 changes: 2 additions & 2 deletions AVPlayerItemHomeOutput.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@
DEBUG_INFORMATION_FORMAT = dwarf;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 0.1.0;
DYLIB_CURRENT_VERSION = 0.1.4;
DYLIB_CURRENT_VERSION = 0.1.5;
DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
Expand Down Expand Up @@ -932,7 +932,7 @@
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 0.1.0;
DYLIB_CURRENT_VERSION = 0.1.4;
DYLIB_CURRENT_VERSION = 0.1.5;
DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Release 0.1.5

- [x] Another CodeBeat refactor.

# Release 0.1.4

- [x] CodeBeat refactor.
Expand Down
78 changes: 33 additions & 45 deletions Core/HomeManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,12 @@ class HomeManager {
let extent = image.extent
for i in 0..<colors {
for j in 0..<colors {
var bitmap = [UInt8](repeating: 0, count: 4)
let context = CIContext()
let x = (extent.size.width / CGFloat(colors)) * CGFloat(i)
let y = (extent.size.height / CGFloat(colors)) * CGFloat(j)
let width = extent.size.width / CGFloat(colors)
let height = extent.size.height / CGFloat(colors)
let inputExtent = CIVector(x: x, y: y, z: width, w: height)
let inputParameters = [kCIInputImageKey: image, kCIInputExtentKey: inputExtent]
guard let filter = CIFilter(name: "CIAreaAverage", withInputParameters: inputParameters), let outputImage = filter.outputImage else {
let inputExtent = CIVector(x: (extent.size.width / CGFloat(colors)) * CGFloat(i), y: (extent.size.height / CGFloat(colors)) * CGFloat(j), z: extent.size.width / CGFloat(colors), w: extent.size.height / CGFloat(colors))
guard let outputImage = CIFilter(name: "CIAreaAverage", withInputParameters: [kCIInputImageKey: image, kCIInputExtentKey: inputExtent])?.outputImage else {
break
}
let outputExtent = outputImage.extent
assert(outputExtent.size.width == 1 && outputExtent.size.height == 1)
let bounds = CGRect(x: 0, y: 0, width: 1, height: 1)
context.render(outputImage, toBitmap: &bitmap, rowBytes: 4, bounds: bounds, format: kCIFormatRGBA8, colorSpace: CGColorSpaceCreateDeviceRGB())
var bitmap = [UInt8](repeating: 0, count: 4)
CIContext().render(outputImage, toBitmap: &bitmap, rowBytes: 4, bounds: CGRect(x: 0, y: 0, width: 1, height: 1), format: kCIFormatRGBA8, colorSpace: CGColorSpaceCreateDeviceRGB())
samples.append(bitmap)
}
}
Expand All @@ -59,27 +50,23 @@ class HomeManager {
}
var colorIndex = 0
for lightbulbService in lightbulbServices {
let color = colors[colorIndex % colors.count]
var HSBA = [CGFloat](repeating: 0, count: 4)
color.getHue(&HSBA[0], saturation: &HSBA[1], brightness: &HSBA[2], alpha: &HSBA[3])
colors[colorIndex % colors.count].getHue(&HSBA[0], saturation: &HSBA[1], brightness: &HSBA[2], alpha: &HSBA[3])
for characteristic in lightbulbService.characteristics {
if updating[characteristic] == nil {
updating[characteristic] = false
}
guard updating[characteristic] == false else {
guard updating[characteristic] == nil || updating[characteristic] == false else {
break
}
switch characteristic.characteristicType {
case HMCharacteristicTypePowerState:
update(characteristic, floatValue: 1)
case HMCharacteristicTypeBrightness:
update(characteristic, floatValue: Float(HSBA[2]))
case HMCharacteristicTypeSaturation:
update(characteristic, floatValue: Float(HSBA[1]))
case HMCharacteristicTypeHue:
update(characteristic, floatValue: Float(HSBA[0]))
default:
break
case HMCharacteristicTypePowerState:
update(characteristic, floatValue: 1)
case HMCharacteristicTypeBrightness:
update(characteristic, floatValue: Float(HSBA[2]))
case HMCharacteristicTypeSaturation:
update(characteristic, floatValue: Float(HSBA[1]))
case HMCharacteristicTypeHue:
update(characteristic, floatValue: Float(HSBA[0]))
default:
break
}
}
colorIndex += 1
Expand All @@ -92,18 +79,23 @@ extension HomeManager {

func update(_ characteristic: HMCharacteristic, floatValue: Float) {
let value = NSNumber(value: Int(floatValue * (characteristic.metadata?.maximumValue?.floatValue ?? (floatValue > 1 ? 100 : 1))))
if characteristic.value as? Float != value.floatValue {
updating[characteristic] = true
characteristic.writeValue(value, completionHandler: { error in
if error != nil {
let deadline: DispatchTime = .now() + .seconds(1)
DispatchQueue.global().asyncAfter(deadline: deadline, execute: { [weak self] in
self?.updating[characteristic] = false
})
} else {
self.updating[characteristic] = false
}
guard characteristic.value as? Float != value.floatValue else {
return
}
updating[characteristic] = true
characteristic.writeValue(value, completionHandler: { error in
self.unlock(characteristic, error)
})
}

func unlock(_ characteristic: HMCharacteristic, _ error: Error?) {
if error != nil {
let deadline: DispatchTime = .now() + .seconds(1)
DispatchQueue.global().asyncAfter(deadline: deadline, execute: { [weak self] in
self?.updating[characteristic] = false
})
} else {
self.updating[characteristic] = false
}
}

Expand All @@ -121,11 +113,7 @@ extension HomeManager {
let diffRed = abs(CGFloat(components[0]) - CGFloat(diffComponents[0]))
let diffGreen = abs(CGFloat(components[1]) - CGFloat(diffComponents[1]))
let diffBlue = abs(CGFloat(components[2]) - CGFloat(diffComponents[2]))
let red = CGFloat(components[0]) / 255
let green = CGFloat(components[1]) / 255
let blue = CGFloat(components[2]) / 255
let alpha = CGFloat(components[3]) / 255
let color = UIColor(red: red, green: green, blue: blue, alpha: alpha)
let color = UIColor(red: CGFloat(components[0]) / 255, green: CGFloat(components[1]) / 255, blue: CGFloat(components[2]) / 255, alpha: CGFloat(components[3]) / 255)
diffColors[color] = (diffColors[color] ?? 0) + diffRed + diffGreen + diffBlue
}
}
Expand Down
2 changes: 1 addition & 1 deletion Core/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.1.4</string>
<string>0.1.5</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSHomeKitUsageDescription</key>
Expand Down
2 changes: 1 addition & 1 deletion Example/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.1.4</string>
<string>0.1.5</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>LSRequiresIPhoneOS</key>
Expand Down
2 changes: 1 addition & 1 deletion tvExample/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.1.4</string>
<string>0.1.5</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>LSRequiresIPhoneOS</key>
Expand Down

0 comments on commit a12fd6a

Please sign in to comment.