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