Created
September 27, 2020 10:39
-
-
Save aferust/a345eed61051b94f0311b234e4c370eb to your computer and use it in GitHub Desktop.
delayed control signal
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
import core.thread; | |
import std.stdio; | |
import std.concurrency; | |
import std.container.dlist; | |
import std.datetime; | |
import std.datetime.systime; | |
__gshared DList!Entry queue; | |
__gshared bool shouldRun = true; | |
struct Entry { | |
SysTime st; | |
int val; | |
} | |
void main() { | |
spawn(&worker); | |
while (true) { | |
int v; | |
"enter your value: ".write; // getFlameIntensityViaImageProcessing() | |
readf(" %d", &v); | |
if(v==0){ | |
shouldRun = false; | |
break; | |
} | |
queue.insertFront(Entry(Clock.currTime + 1500.msecs, v)); | |
} | |
writeln("main is done."); | |
} | |
void worker() { | |
while(shouldRun){ | |
auto r = queue[]; | |
if(!r.empty && queue.back.st < Clock.currTime){ | |
writeln(queue.back); // consume the value sendPWMSignalToValfe(pwmval) | |
queue.popLastOf(r); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment