Skip to content

Instantly share code, notes, and snippets.

@aferust
Created September 27, 2020 10:39
Show Gist options
  • Save aferust/a345eed61051b94f0311b234e4c370eb to your computer and use it in GitHub Desktop.
Save aferust/a345eed61051b94f0311b234e4c370eb to your computer and use it in GitHub Desktop.
delayed control signal
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