3
3
4
4
import sys
5
5
6
+ sys .path .append ("Advertiser" )
7
+ from Advertiser .IAdvertisingDevice import IAdvertisingDevice
8
+
6
9
sys .path .append ("MouldKing" )
7
10
from MouldKing .MouldKingDeviceNibble import MouldKingDeviceNibble
8
11
@@ -17,16 +20,48 @@ class handling 3 x MouldKing 4.0 Module
17
20
18
21
__telegram_base = bytes ([0x7D , 0x7B , 0xA7 , 0x88 , 0x88 , 0x88 , 0x88 , 0x88 , 0x88 , 0x82 ]) # byte array for base Telegram
19
22
23
+
20
24
def __init__ (self ):
21
25
"""
22
26
initializes the object and defines the fields
23
27
"""
24
-
25
28
# call baseclass init and set number of channels
26
29
super ().__init__ ("MK4" , 12 , 3 , 1 , MouldKing_4_Hubs .__telegram_connect , MouldKing_4_Hubs .__telegram_base )
27
30
31
+ self ._connectedSubDevices = list ()
32
+
33
+
34
+ def SubDevice_Register (self , subDevice : IAdvertisingDevice ) -> None :
35
+ """
36
+ returns the telegram to switch the MouldKing Hubs in bluetooth mode
37
+ """
38
+ connectedSubDevicesLen = len (self ._connectedSubDevices )
39
+
40
+ if (not subDevice is None and not subDevice in self ._connectedSubDevices ):
41
+ self ._connectedSubDevices .append (subDevice )
42
+
43
+ # first subDevice was added
44
+ if (connectedSubDevicesLen == 0 ):
45
+ self .Connect ()
46
+
47
+ return
48
+
49
+
50
+ def SubDevice_Unregister (self , subDevice : IAdvertisingDevice ) -> None :
51
+ """
52
+ disconnects the device from the advertiser
53
+ """
54
+ if (not subDevice is None and subDevice in self ._connectedSubDevices ):
55
+ self ._connectedSubDevices .remove (subDevice )
56
+
57
+ # last subDevice was removed
58
+ if (len (self ._connectedSubDevices ) == 0 ):
59
+ self .Disconnect ()
60
+
61
+ return
62
+
28
63
29
- def Stop (self , hubDeviceId : int , hubNumberOfChannels : int ) -> bytes :
64
+ def SubDevice_Stop (self , hubDeviceId : int , hubNumberOfChannels : int ) -> bytes :
30
65
"""
31
66
set internal stored value of all channels to zero and return the telegram
32
67
"""
@@ -46,7 +81,7 @@ def Stop(self, hubDeviceId: int, hubNumberOfChannels: int) -> bytes:
46
81
return self .CreateTelegram ()
47
82
48
83
49
- def SetChannel (self , hubDeviceId : int , hubNumberOfChannels : int , hubChannelId : int , value : float ) -> bytes :
84
+ def SubDevice_SetChannel (self , hubDeviceId : int , hubNumberOfChannels : int , hubChannelId : int , value : float ) -> bytes :
50
85
"""
51
86
set internal stored value of channel with channelId to value and return the telegram
52
87
"""
@@ -59,9 +94,9 @@ def SetChannel(self, hubDeviceId: int, hubNumberOfChannels: int, hubChannelId: i
59
94
# -> channelId 9..12
60
95
channelIdHubs = hubDeviceId * hubNumberOfChannels + hubChannelId
61
96
62
- if hubChannelId > self ._NumberOfChannels - 1 :
97
+ if channelIdHubs > self ._NumberOfChannels - 1 :
63
98
raise Exception ("only channelId 0.." + int (self ._NumberOfChannels - 1 ) + "are allowed" )
64
99
65
- self ._ChannelValueList [hubChannelId ] = value
100
+ self ._ChannelValueList [channelIdHubs ] = value
66
101
67
102
return self .CreateTelegram ()
0 commit comments