Skip to content

Commit

Permalink
Adde StatelessProgrammable switch accessory and prepared to fire its …
Browse files Browse the repository at this point in the history
…events
  • Loading branch information
TheMisfit68 committed Dec 17, 2023
1 parent 95a7164 commit 2a1bc75
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 238 deletions.
121 changes: 121 additions & 0 deletions Accessory Delegates/ PLCClassAccessoryDelegates/FunctionKey.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
//
// 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


/// A PLC-Class type object that is not an Accessory-Delegate
/// because it has no Accessory associated with it,
/// it only processes hardware-signals
class FunctionKey:PLCClassAccessoryDelegate{

var characteristicChanged: Bool = false
var hardwareFeedbackChanged: Bool = false


private var inputPuls:Bool = false
private var inputTriggered:EBool

var clicked:Bool = false{
didSet{
if clicked{
#warning("DEBUGPRINT") // TODO: - remove temp print statement
print("🐞\tClicked")
}
clicked.reset()
}
}

let doubleclikInterval:TimeInterval
let doubleClickTimer:DigitalTimer
var doubleClicked:Bool = false{
didSet{
if doubleClicked{
#warning("DEBUGPRINT") // TODO: - remove temp print statement
print("🐞\tDoubleClicked")
}
doubleClicked.reset()
}
}

let longPressTime:TimeInterval
let longPressTimer:DigitalTimer
var longPressed:Bool = false{
didSet{
if longPressed{
#warning("DEBUGPRINT") // TODO: - remove temp print statement
print("🐞\tPressedlong")
}
longPressed.reset()
}
}


override init(){

self.inputTriggered = EBool(&inputPuls)

self.doubleclikInterval = 1.0
self.doubleClickTimer = DigitalTimer.OffDelay(time: doubleclikInterval)

self.longPressTime = 2.0
self.longPressTimer = DigitalTimer.OnDelay(time: longPressTime)

super.init()
}

var inputSignal:DigitalInputSignal{
let ioSymbol:SoftPLC.IOSymbol = .functionKey(circuit:String(localized: "\(instanceName)", table:"AccessoryNames"))
return plc.signal(ioSymbol:ioSymbol) as! DigitalInputSignal
}

public func assignInputParameters(){

if let hardwarePuls = inputSignal.logicalValue{
inputPuls = hardwarePuls
}else{
inputPuls = false
}

}

public func assignOutputParameters(){
// Function keys have no outputs associated with them!
}

// MARK: - PLC Processing
public func runCycle() {

let risingEdge = inputTriggered.🔼

if risingEdge && !doubleClickTimer.output{
clicked.set()
}else if risingEdge && doubleClickTimer.output{
doubleClicked.set()
}else if longPressTimer.output{
longPressed.set()
}

// reevaluate(&clicked, characteristic:accessory.programmableSwitchEvent, hardwareFeedback: hardwarePowerState)
// reevaluate(&doubleClicked, characteristic:accessory.outlet.powerState, hardwareFeedback: hardwarePowerState)



doubleClickTimer.input = inputPuls
longPressTimer.input = inputPuls

}

}
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)
}
}
}

34 changes: 15 additions & 19 deletions HAPiNest.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
DC0761B02A8A9DA3009FA191 /* DashboardPreview.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC0761AF2A8A9DA3009FA191 /* DashboardPreview.swift */; };
DC0761B12A8A9DA3009FA191 /* HomeKitServerPreview.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC0761AE2A8A9DA3009FA191 /* HomeKitServerPreview.swift */; };
DC0CA92C268BBD0700E5AB06 /* MilightDriver in Frameworks */ = {isa = PBXBuildFile; productRef = DC0CA92B268BBD0700E5AB06 /* MilightDriver */; };
DC120EE72AE31AF10052F1A6 /* ServiceNames.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = DC120EE62AE31AF10052F1A6 /* ServiceNames.xcstrings */; };
DC1888352961C0CF00D3363D /* EnableSwitchService.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC1888342961C0CF00D3363D /* EnableSwitchService.swift */; };
DC2C19BF26BB3BD400A3AB83 /* HAP in Frameworks */ = {isa = PBXBuildFile; productRef = DC2C19BE26BB3BD400A3AB83 /* HAP */; };
DC342E0C2AEE74EF00C578A2 /* PLCAccessoryDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC342E0B2AEE74EF00C578A2 /* PLCAccessoryDelegate.swift */; };
Expand All @@ -33,10 +32,9 @@
DC54B6F72570628E00D9169F /* HomeKitServerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC3626EF256D9B0800F0AC35 /* HomeKitServerView.swift */; };
DC54B6FD2570686D00D9169F /* PLCConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC23DF9424E7499A00DD8371 /* PLCConfiguration.swift */; };
DC55156A296AE2A9003432CD /* ElectricCarAccessory.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC551569296AE2A9003432CD /* ElectricCarAccessory.swift */; };
DC6DEE212B2E5EE300BDAB31 /* FunctionKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC6DEE202B2E5EE300BDAB31 /* FunctionKey.swift */; };
DC746D7325ACA97A00B33314 /* SmartSprinklerAccessory.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC746D7225ACA97A00B33314 /* SmartSprinklerAccessory.swift */; };
DC846E3A26D996E9002CEDFB /* JVCocoa in Frameworks */ = {isa = PBXBuildFile; productRef = DC846E3926D996E9002CEDFB /* JVCocoa */; };
DC87DC852AF31227003ABD83 /* SceneNames.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = DC87DC842AF31227003ABD83 /* SceneNames.xcstrings */; };
DC8D0F69259DAA6A00DD04E4 /* FunctionKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC8D0F68259DAA6A00DD04E4 /* FunctionKey.swift */; };
DC90DA642732817000068839 /* TizenSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC90DA5E2732817000068839 /* TizenSettingsView.swift */; };
DC90DA652732817000068839 /* PreferencesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC90DA5F2732817000068839 /* PreferencesView.swift */; };
DC90DA672732817000068839 /* GeneralSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC90DA612732817000068839 /* GeneralSettingsView.swift */; };
Expand All @@ -45,8 +43,9 @@
DC90DA6C2732828200068839 /* DashboardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC90DA6B2732828200068839 /* DashboardView.swift */; };
DC9963892AD3073000915EAC /* CirtcuitEnabler.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC9963882AD3073000915EAC /* CirtcuitEnabler.swift */; };
DCA37CF926BB29EF003CC3BF /* HAPTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCA37CF826BB29EF003CC3BF /* HAPTests.swift */; };
DCA3DF312B28D97000554A8A /* DimmerTimer.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCA3DF302B28D97000554A8A /* DimmerTimer.swift */; };
DCA3DF312B28D97000554A8A /* BrightnessTimer.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCA3DF302B28D97000554A8A /* BrightnessTimer.swift */; };
DCAB996A2A816734005FCC29 /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = DCAB99692A816734005FCC29 /* README.md */; };
DCBBC7082B2EE4D80005EE6E /* StatelessProgrammableSwitch.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCBBC7072B2EE4D80005EE6E /* StatelessProgrammableSwitch.swift */; };
DCBCFB5529678657000F0376 /* Enums.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCBCFB5429678657000F0376 /* Enums.swift */; };
DCC01B5825B434BC00984BB5 /* SmartSprinkler.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCC01B5725B434BC00984BB5 /* SmartSprinkler.swift */; };
DCC1D8C529886687000067D0 /* LeafAccessoryDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCC1D8C429886687000067D0 /* LeafAccessoryDelegate.swift */; };
Expand Down Expand Up @@ -77,7 +76,6 @@
/* Begin PBXFileReference section */
DC0761AE2A8A9DA3009FA191 /* HomeKitServerPreview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeKitServerPreview.swift; sourceTree = "<group>"; };
DC0761AF2A8A9DA3009FA191 /* DashboardPreview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DashboardPreview.swift; sourceTree = "<group>"; };
DC120EE62AE31AF10052F1A6 /* ServiceNames.xcstrings */ = {isa = PBXFileReference; lastKnownFileType = text.json.xcstrings; path = ServiceNames.xcstrings; sourceTree = "<group>"; };
DC1888342961C0CF00D3363D /* EnableSwitchService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnableSwitchService.swift; sourceTree = "<group>"; };
DC197CAA24D9A74300C07E90 /* MilightAccessoryDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MilightAccessoryDelegate.swift; sourceTree = "<group>"; };
DC23DF8C24E73F8600DD8371 /* DimmableLight.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DimmableLight.swift; sourceTree = "<group>"; };
Expand All @@ -99,11 +97,10 @@
DC54B6C72570586E00D9169F /* HAPiNest.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = HAPiNest.entitlements; sourceTree = "<group>"; };
DC551569296AE2A9003432CD /* ElectricCarAccessory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ElectricCarAccessory.swift; sourceTree = "<group>"; };
DC5A4C2324D9A952001CF95B /* TizenAccessoryDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TizenAccessoryDelegate.swift; sourceTree = "<group>"; };
DC6DEE202B2E5EE300BDAB31 /* FunctionKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FunctionKey.swift; sourceTree = "<group>"; };
DC6E461523B75BF8006A3E61 /* ToDo.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = ToDo.md; sourceTree = "<group>"; };
DC746D7225ACA97A00B33314 /* SmartSprinklerAccessory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SmartSprinklerAccessory.swift; sourceTree = "<group>"; };
DC7FB14026C99142003CAFB0 /* JVCocoa */ = {isa = PBXFileReference; lastKnownFileType = folder; name = JVCocoa; path = ../../JVCocoa; sourceTree = "<group>"; };
DC87DC842AF31227003ABD83 /* SceneNames.xcstrings */ = {isa = PBXFileReference; lastKnownFileType = text.json.xcstrings; path = SceneNames.xcstrings; sourceTree = "<group>"; };
DC8D0F68259DAA6A00DD04E4 /* FunctionKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FunctionKey.swift; sourceTree = "<group>"; };
DC90DA5E2732817000068839 /* TizenSettingsView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TizenSettingsView.swift; sourceTree = "<group>"; };
DC90DA5F2732817000068839 /* PreferencesView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PreferencesView.swift; sourceTree = "<group>"; };
DC90DA612732817000068839 /* GeneralSettingsView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GeneralSettingsView.swift; sourceTree = "<group>"; };
Expand All @@ -117,8 +114,9 @@
DC9EFF2224F3131F001B70EE /* DoorLock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DoorLock.swift; sourceTree = "<group>"; };
DCA37CF626BB29EF003CC3BF /* HAPiNestTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = HAPiNestTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
DCA37CF826BB29EF003CC3BF /* HAPTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HAPTests.swift; sourceTree = "<group>"; };
DCA3DF302B28D97000554A8A /* DimmerTimer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DimmerTimer.swift; sourceTree = "<group>"; };
DCA3DF302B28D97000554A8A /* BrightnessTimer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BrightnessTimer.swift; sourceTree = "<group>"; };
DCAB99692A816734005FCC29 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
DCBBC7072B2EE4D80005EE6E /* StatelessProgrammableSwitch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatelessProgrammableSwitch.swift; sourceTree = "<group>"; };
DCBCFB5429678657000F0376 /* Enums.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Enums.swift; sourceTree = "<group>"; };
DCC01B5725B434BC00984BB5 /* SmartSprinkler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SmartSprinkler.swift; sourceTree = "<group>"; };
DCC1D8C429886687000067D0 /* LeafAccessoryDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LeafAccessoryDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -199,19 +197,16 @@
children = (
DCD592F8270A6C2600882387 /* HAPiNestApp.swift */,
DC342E0D2AEE757E00C578A2 /* CyclicPoller.swift */,
DC8D0F68259DAA6A00DD04E4 /* FunctionKey.swift */,
DC54B6C62570586E00D9169F /* Info.plist */,
DC54B6C72570586E00D9169F /* HAPiNest.entitlements */,
DC54B6C12570586E00D9169F /* Assets.xcassets */,
DC4D66792A956AC1004C9D30 /* Localizable.xcstrings */,
DC87DC842AF31227003ABD83 /* SceneNames.xcstrings */,
DC4D667B2A9571BA004C9D30 /* AccessoryNames.xcstrings */,
DC120EE62AE31AF10052F1A6 /* ServiceNames.xcstrings */,
DCF7D5AB2AD0D106000010AA /* TVChannelNames.xcstrings */,
DC90DA6A2732828200068839 /* MainWindow */,
DC90DA5D2732817000068839 /* PreferencesWindow */,
DC2D4572256E486D00DF3EC5 /* HomekitServer */,
DCA3DF322B28D99000554A8A /* AdaptableLightning */,
DCA3DF322B28D99000554A8A /* AmbientLightning */,
);
path = HAPiNest;
sourceTree = "<group>";
Expand Down Expand Up @@ -258,6 +253,7 @@
DC2D4573256E48C100DF3EC5 /* PLCClassAccessoryDelegates */ = {
isa = PBXGroup;
children = (
DC6DEE202B2E5EE300BDAB31 /* FunctionKey.swift */,
DC23DF8C24E73F8600DD8371 /* DimmableLight.swift */,
DC9963882AD3073000915EAC /* CirtcuitEnabler.swift */,
DC23DF8E24E73FB900DD8371 /* Light.swift */,
Expand Down Expand Up @@ -307,17 +303,18 @@
path = HAPiNestTests;
sourceTree = "<group>";
};
DCA3DF322B28D99000554A8A /* AdaptableLightning */ = {
DCA3DF322B28D99000554A8A /* AmbientLightning */ = {
isa = PBXGroup;
children = (
DCA3DF302B28D97000554A8A /* DimmerTimer.swift */,
DCA3DF302B28D97000554A8A /* BrightnessTimer.swift */,
);
path = AdaptableLightning;
path = AmbientLightning;
sourceTree = "<group>";
};
DCA8FA1B25B2FE0900532E4A /* Custom Accessories */ = {
isa = PBXGroup;
children = (
DCBBC7072B2EE4D80005EE6E /* StatelessProgrammableSwitch.swift */,
DCD1230F25ACE01C00060708 /* StatelessGarageDoorOpenerAccessory.swift */,
DC746D7225ACA97A00B33314 /* SmartSprinklerAccessory.swift */,
DC551569296AE2A9003432CD /* ElectricCarAccessory.swift */,
Expand Down Expand Up @@ -468,11 +465,9 @@
buildActionMask = 2147483647;
files = (
DCF7D5AC2AD0D106000010AA /* TVChannelNames.xcstrings in Resources */,
DC87DC852AF31227003ABD83 /* SceneNames.xcstrings in Resources */,
DCAB996A2A816734005FCC29 /* README.md in Resources */,
DC54B6C22570586E00D9169F /* Assets.xcassets in Resources */,
DC4D667A2A956AC1004C9D30 /* Localizable.xcstrings in Resources */,
DC120EE72AE31AF10052F1A6 /* ServiceNames.xcstrings in Resources */,
DC4D667C2A9571BA004C9D30 /* AccessoryNames.xcstrings in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -508,16 +503,17 @@
DC746D7325ACA97A00B33314 /* SmartSprinklerAccessory.swift in Sources */,
DC0761B12A8A9DA3009FA191 /* HomeKitServerPreview.swift in Sources */,
DC55156A296AE2A9003432CD /* ElectricCarAccessory.swift in Sources */,
DC8D0F69259DAA6A00DD04E4 /* FunctionKey.swift in Sources */,
DC342E0E2AEE757E00C578A2 /* CyclicPoller.swift in Sources */,
DCCF8CCC296B4BB400B1C50F /* Accessory.swift in Sources */,
DCC9603D2670305000FB84BC /* Hapinest.docc in Sources */,
DCCBE29C25B8B7D800BAED50 /* ToggleableOutlet.swift in Sources */,
DC6DEE212B2E5EE300BDAB31 /* FunctionKey.swift in Sources */,
DCBBC7082B2EE4D80005EE6E /* StatelessProgrammableSwitch.swift in Sources */,
DC0761B02A8A9DA3009FA191 /* DashboardPreview.swift in Sources */,
DC90DA642732817000068839 /* TizenSettingsView.swift in Sources */,
DC54B6F42570628B00D9169F /* HomeKitServer.swift in Sources */,
DC4D6DE225713CD00087E51D /* DimmableLight.swift in Sources */,
DCA3DF312B28D97000554A8A /* DimmerTimer.swift in Sources */,
DCA3DF312B28D97000554A8A /* BrightnessTimer.swift in Sources */,
DCD592F9270A6C2600882387 /* HAPiNestApp.swift in Sources */,
DC90DA652732817000068839 /* PreferencesView.swift in Sources */,
DC90DA692732817000068839 /* WeatherKitSettingsView.swift in Sources */,
Expand Down
Loading

0 comments on commit 2a1bc75

Please sign in to comment.