Libraryless. Click here for Pure Java version (8743L/51K).
1 | sclass OnOffOscillator is AutoCloseable {
|
2 | double percentageOn = 50; |
3 | Frequency frequency = freq(50); |
4 | |
5 | transient PingSource clientPingSource; |
6 | transient Schedule<Runnable> schedule; |
7 | transient Thread thread; |
8 | transient new BoolVar on; |
9 | |
10 | *(PingSource *clientPingSource) {}
|
11 | |
12 | void init {
|
13 | schedule = new Schedule<Runnable>; |
14 | schedule.add(0, r {
|
15 | clientPingSource?.action(null); |
16 | on.set(); |
17 | }); |
18 | schedule.add(percentageOn/100, r {
|
19 | on.unset(); |
20 | clientPingSource?.action(-> {
|
21 | temp tempPingPrivileged(); |
22 | on.waitUntilTrue(); |
23 | true; |
24 | }); |
25 | }); |
26 | schedule.jumpFromTo(1, 0); |
27 | schedule.speedUp(frequency!); |
28 | } |
29 | |
30 | void start {
|
31 | init(); |
32 | thread = startThread("OnOffOscillator", r { schedule.run(); });
|
33 | } |
34 | |
35 | // Note: May leave switch in on or off state |
36 | public void stop aka close() {
|
37 | interruptThread(thread); |
38 | thread = null; |
39 | } |
40 | } |
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): bhatertpkbcr, ekrmjmnbrukm, mqqgnosmbjvj
No comments. add comment
| Snippet ID: | #1033552 |
| Snippet name: | OnOffOscillator |
| Eternal ID of this version: | #1033552/5 |
| Text MD5: | 99dc6817c6adeb56ecc85a99b44a78d7 |
| Transpilation MD5: | 948eeffe16c5dbe398ca810c5e1f524e |
| Author: | stefan |
| Category: | javax / execution |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2021-11-03 14:44:48 |
| Source code size: | 960 bytes / 40 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 433 / 592 |
| Version history: | 4 change(s) |
| Referenced in: | [show references] |