11using System ;
2+ using System . Drawing ;
3+ using System . Linq ;
24
35namespace lucidcode . LucidScribe . Plugin . Interval
46{
5- public class PluginHandler : Interface . LucidPluginBase
7+ public static class Device
68 {
7- private int interval = 40 ;
8- private int lastSecond = - 1 ;
9- private DateTime lastTrigger ;
9+ public static EventHandler < EventArgs > ValueChanged ;
1010
11- public override string Name
11+ static bool initialized ;
12+ private static int delay = 40 ;
13+ private static int lastSecond = - 1 ;
14+ private static DateTime lastTrigger ;
15+
16+ private static System . Threading . Timer timer ;
17+
18+ static int interval ;
19+
20+ public static Boolean Initialize ( )
1221 {
13- get
22+ if ( initialized )
1423 {
15- return "Interval REM" ;
24+ return true ;
1625 }
26+ initialized = true ;
27+ timer = new System . Threading . Timer ( Tick , "interval" , TimeSpan . FromMilliseconds ( 10 ) , TimeSpan . FromMilliseconds ( 500 ) ) ;
28+ return true ;
1729 }
1830
19- public override bool Initialize ( )
31+ private static void Tick ( object state )
2032 {
21- lastTrigger = DateTime . Now ;
22- return true ;
33+ if ( lastSecond == DateTime . Now . Second )
34+ {
35+ return ;
36+ }
37+
38+ if ( DateTime . Now >= lastTrigger . AddSeconds ( delay ) &&
39+ lastSecond != DateTime . Now . Second )
40+ {
41+ lastTrigger = DateTime . Now ;
42+ lastSecond = DateTime . Now . Second ;
43+ interval = 888 ;
44+ }
45+ else
46+ {
47+ interval = 1 ;
48+ }
49+
50+ string values = string . Join ( "," , Enumerable . Repeat ( interval , 512 ) ) ;
51+
52+ if ( ValueChanged != null )
53+ {
54+ ValueChanged ( ( object ) values , null ) ;
55+ }
2356 }
2457
25- public override double Value
58+ public static void Dispose ( )
2659 {
27- get
60+ timer . Dispose ( ) ;
61+ }
62+
63+ public static Double GetInterval ( )
64+ {
65+ return interval ;
66+ }
67+ }
68+
69+ namespace Timer
70+ {
71+ public class PluginHandler : Interface . LucidPluginBase
72+ {
73+ private DateTime lastTrigger ;
74+
75+ public override string Name
2876 {
29- if ( DateTime . Now >= lastTrigger . AddSeconds ( interval ) &&
30- lastSecond != DateTime . Now . Second )
77+ get
3178 {
32- lastTrigger = DateTime . Now ;
33- lastSecond = DateTime . Now . Second ;
34- return 888 ;
79+ return "Interval REM" ;
3580 }
81+ }
3682
37- return 1 ;
83+ public override bool Initialize ( )
84+ {
85+ try
86+ {
87+ return Device . Initialize ( ) ;
88+ }
89+ catch ( Exception ex )
90+ {
91+ throw ( new Exception ( "The '" + Name + "' plugin failed to initialize: " + ex . Message ) ) ;
92+ }
3893 }
39- }
4094
95+ public override double Value
96+ {
97+ get
98+ {
99+ double value = Device . GetInterval ( ) ;
100+ if ( value == 888 && DateTime . Now >= lastTrigger . AddSeconds ( 3 ) )
101+ {
102+ lastTrigger = DateTime . Now ;
103+ return value ;
104+ }
105+ return 1 ;
106+ }
107+ }
108+
109+ public override void Dispose ( )
110+ {
111+ Device . Dispose ( ) ;
112+ }
113+ }
41114 }
42115
43- }
116+ namespace RAW
117+ {
118+ public class PluginHandler : Interface . ILluminatedPlugin
119+ {
120+ public string Name
121+ {
122+ get
123+ {
124+ return "Interval RAW" ;
125+ }
126+ }
127+
128+ public bool Initialize ( )
129+ {
130+ try
131+ {
132+ bool initialized = Device . Initialize ( ) ;
133+ Device . ValueChanged += ValueChanged ;
134+ return initialized ;
135+ }
136+ catch ( Exception ex )
137+ {
138+ throw ( new Exception ( "The '" + Name + "' plugin failed to initialize: " + ex . Message ) ) ;
139+ }
140+ }
141+
142+ public event Interface . SenseHandler Sensed ;
143+ public void ValueChanged ( object sender , EventArgs e )
144+ {
145+ if ( ClearTicks )
146+ {
147+ ClearTicks = false ;
148+ TickCount = "" ;
149+ }
150+ TickCount += sender + "," ;
151+
152+ if ( ClearBuffer )
153+ {
154+ ClearBuffer = false ;
155+ BufferData = "" ;
156+ }
157+ BufferData += sender + "," ;
158+ }
159+
160+ public void Dispose ( )
161+ {
162+ Device . ValueChanged -= ValueChanged ;
163+ Device . Dispose ( ) ;
164+ }
165+
166+ public Boolean isEnabled = false ;
167+ public Boolean Enabled
168+ {
169+ get
170+ {
171+ return isEnabled ;
172+ }
173+ set
174+ {
175+ isEnabled = value ;
176+ }
177+ }
178+
179+ public Color PluginColor = Color . White ;
180+ public Color Color
181+ {
182+ get
183+ {
184+ return Color ;
185+ }
186+ set
187+ {
188+ Color = value ;
189+ }
190+ }
191+
192+ private Boolean ClearTicks = false ;
193+ public String TickCount = "" ;
194+ public String Ticks
195+ {
196+ get
197+ {
198+ ClearTicks = true ;
199+ return TickCount ;
200+ }
201+ set
202+ {
203+ TickCount = value ;
204+ }
205+ }
206+
207+ private Boolean ClearBuffer = false ;
208+ public String BufferData = "" ;
209+ public String Buffer
210+ {
211+ get
212+ {
213+ ClearBuffer = true ;
214+ return BufferData ;
215+ }
216+ set
217+ {
218+ BufferData = value ;
219+ }
220+ }
221+
222+ int lastHour ;
223+ public int LastHour
224+ {
225+ get
226+ {
227+ return lastHour ;
228+ }
229+ set
230+ {
231+ lastHour = value ;
232+ }
233+ }
234+ }
235+ }
236+ }
0 commit comments