Added basic speed limiter
parent
afecfe5890
commit
50dfd244e7
16
src/main.cpp
16
src/main.cpp
|
@ -5,6 +5,9 @@
|
|||
// For reading FIFO
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
// For sleep
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
// Local files
|
||||
#include "utility/bitmap.hpp"
|
||||
|
@ -78,9 +81,19 @@ int main(int argc, char *argv[]) {
|
|||
Dox.connect_loop();
|
||||
|
||||
|
||||
// Frame rate limiter
|
||||
std::chrono::time_point<
|
||||
std::chrono::steady_clock,
|
||||
std::chrono::nanoseconds
|
||||
> t = std::chrono::steady_clock::now();
|
||||
//t += std::chrono::milliseconds(30);
|
||||
//this_thread::sleep_until(t);
|
||||
|
||||
|
||||
while (1) {
|
||||
|
||||
if (Dox.is_connected()) {
|
||||
if (std::chrono::steady_clock::now() > t + std::chrono::milliseconds(30)) {
|
||||
if (Dox.get_animation_mode() == 0x02) {
|
||||
buf.update();
|
||||
fft.update(buf);
|
||||
|
@ -101,6 +114,9 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
Dox.write(CMD_ANIM_DATA, hid_buf, Dox.packet_size);
|
||||
|
||||
t = std::chrono::steady_clock::now();
|
||||
}
|
||||
|
||||
// Dox.write might detect that we've been disconnected,
|
||||
// and Dox.read will fail if we are.
|
||||
// This check prevents it from doing that, and instead jumps to reconnect.
|
||||
|
|
Loading…
Reference in New Issue