-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/ProgrammableSwitches' into feature/AdaptableLig…
…htning
- Loading branch information
Showing
20 changed files
with
213 additions
and
263 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
Accessory Delegates/ PLCClassAccessoryDelegates/FunctionKey.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// | ||
// FunctionKey.swift | ||
// HAPiNest | ||
// | ||
// Created by Jan Verrept on 31/12/2020. | ||
// Copyright © 2020 Jan Verrept. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
import Cocoa | ||
import HAP | ||
import SoftPLC | ||
import ModbusDriver | ||
import IOTypes | ||
import JVCocoa | ||
|
||
|
||
class FunctionKey:PLCClassAccessoryDelegate{ | ||
|
||
// MARK: - Accessory binding | ||
typealias AccessorySubclass = Accessory.StatelessProgrammableSwitch | ||
var characteristicChanged: Bool = false | ||
|
||
// MARK: - State | ||
private enum SwitchEvent:UInt8{ | ||
case singlePress = 0 | ||
case doublePress = 1 | ||
case longPress = 2 | ||
} | ||
|
||
private var clicksCounter:Int = 0 | ||
private var switchEvent:SwitchEvent? = nil{ | ||
|
||
didSet{ | ||
clicksCounter = 0 | ||
longPressTimer.reset() | ||
doubleClickTimer.reset() | ||
} | ||
} | ||
|
||
|
||
private var inputPuls:Bool = false | ||
private var inputTriggered:EBool | ||
|
||
private let doubleclikInterval:TimeInterval = 2.0 | ||
private let doubleClickTimer:DigitalTimer | ||
|
||
private let longPressTime:TimeInterval = 3.0 | ||
private let longPressTimer:DigitalTimer | ||
|
||
// Hardware feedback state | ||
// Function keys only have inputs, no controlable outputs and therefore also no associated hardwarefeedback | ||
var hardwareFeedbackChanged:Bool = false | ||
|
||
override init(){ | ||
|
||
inputTriggered = EBool(&inputPuls) | ||
self.doubleClickTimer = DigitalTimer.OffDelay(time: doubleclikInterval) | ||
self.longPressTimer = DigitalTimer.OnDelay(time: longPressTime) | ||
|
||
super.init() | ||
} | ||
|
||
// MARK: - IO-Signal assignment | ||
var inputSignal:DigitalInputSignal{ | ||
let ioSymbol:SoftPLC.IOSymbol = .functionKey(circuit:String(localized: "\(instanceName)")) | ||
return plc.signal(ioSymbol:ioSymbol) as! DigitalInputSignal | ||
} | ||
|
||
// MARK: - PLC Parameter assignment | ||
public func assignInputParameters(){ | ||
inputPuls = inputSignal.logicalValue ?? false | ||
} | ||
|
||
public func assignOutputParameters(){ | ||
// Function keys have no outputs associated with them! | ||
} | ||
|
||
// MARK: - PLC Processing | ||
public func runCycle() { | ||
|
||
doubleClickTimer.input = inputPuls | ||
longPressTimer.input = inputPuls | ||
|
||
if longPressTimer.output{ | ||
switchEvent = .longPress | ||
}else if (clicksCounter >= 2) { | ||
switchEvent = .doublePress | ||
}else if (clicksCounter == 1) && !doubleClickTimer.output{ | ||
switchEvent = .singlePress | ||
} | ||
|
||
if inputTriggered.🔼 { | ||
clicksCounter += 1 | ||
}else if !doubleClickTimer.output{ | ||
clicksCounter = 0 | ||
} | ||
|
||
reevaluate(&switchEvent, characteristic:accessory.primaryService.programmableSwitchEvent, hardwareFeedback: nil) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
HAP Extensions/Custom Accessories/StatelessProgrammableSwitch.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// StatelessProgrammableSwitch.swift | ||
// HAPiNest | ||
// | ||
// Created by Jan Verrept on 17/12/2023. | ||
// Copyright © 2023 Jan Verrept. All rights reserved. | ||
// | ||
import Foundation | ||
import HAP | ||
|
||
#warning("TODO") // TODO: - Create a pull request to get this implemented by HAP itself | ||
extension HAP.Accessory { | ||
open class ProgrammableSwitch: Accessory { | ||
public let primaryService:Service.StatelessProgrammableSwitch = Service.StatelessProgrammableSwitch() | ||
|
||
public init(info: Service.Info, additionalServices: [Service] = []) { | ||
super.init(info: info, type: .programmableSwitch, services: [primaryService] + additionalServices) | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.