[O] Optimize fps counter

This commit is contained in:
Hykilpikonna
2023-04-21 17:39:23 -04:00
parent 61eaabfa33
commit 4de4f39269
2 changed files with 17 additions and 18 deletions
+17 -17
View File
@@ -35,7 +35,7 @@ Adafruit_NeoPixel p_led_knob(9, P_LED_KNOB, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel p_led_rotary(9, P_LED_ROTARY, NEO_GRB + NEO_KHZ800); Adafruit_NeoPixel p_led_rotary(9, P_LED_ROTARY, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel lk(LK_NUM_LIGHTS, LK_PIN, NEO_GRB + NEO_KHZ800); Adafruit_NeoPixel lk(LK_NUM_LIGHTS, LK_PIN, NEO_GRB + NEO_KHZ800);
u64 fps_time_counter = 0; u64 fps_last_update = 0;
u32 fps_updates = 0; u32 fps_updates = 0;
u32 fps_interval_ms = 1000; u32 fps_interval_ms = 1000;
@@ -49,7 +49,7 @@ u32 pot_states[P_PINS_PER_MUX];
Encoder *encoders[P_NUM_ROTARY]; Encoder *encoders[P_NUM_ROTARY];
int encoder_states[P_NUM_ROTARY]; int encoder_states[P_NUM_ROTARY];
TaskHandle_t thread1, thread2; TaskHandle_t thread2;
void setup() void setup()
{ {
@@ -199,7 +199,7 @@ void readPanel()
// i >> j is the jth bit of i // i >> j is the jth bit of i
digitalWrite(P_MUX_SEL_OUT[j], (i >> j) & 1); digitalWrite(P_MUX_SEL_OUT[j], (i >> j) & 1);
} }
delayMicroseconds(100); vTaskDelay(1);
// Read button // Read button
int key = !digitalRead(P_KEY_MUX_IN); int key = !digitalRead(P_KEY_MUX_IN);
@@ -247,26 +247,26 @@ void readPanel()
while (true) while (true)
{ {
readPanel(); readPanel();
taskYIELD(); }
}
void countFps(u64 time)
{
// Report FPS every second
fps_updates++;
if (time - fps_last_update >= fps_interval_ms)
{
fps_last_update = time;
double fps = 1.0 * fps_updates / fps_interval_ms * 1000;
Serial.printf("FPS: %.2f\r\n", fps);
fps_updates = 0;
} }
} }
void readKeyboard() void readKeyboard()
{ {
u64 time = timeMillis(); u64 time = timeMillis();
u64 elapsed = time - last_refresh_time; countFps(time);
last_refresh_time = time;
// Report FPS every second
fps_time_counter += elapsed;
fps_updates++;
if (fps_time_counter >= fps_interval_ms)
{
fps_time_counter -= fps_interval_ms;
double fps = 1.0 * fps_updates / fps_interval_ms * 1000;
Serial.printf("FPS: %.2f\r\n", fps);
fps_updates = 0;
}
// Toggle LED refresh indicator // Toggle LED refresh indicator
digitalWrite(LED_REFRESH, led_refresh_on = !led_refresh_on); digitalWrite(LED_REFRESH, led_refresh_on = !led_refresh_on);
-1
View File
@@ -27,6 +27,5 @@ void onPotChange(int id, u8 value);
int multisampleRead(int pin, int samples); int multisampleRead(int pin, int samples);
[[noreturn]] void loopPanel(void* pvParameters); [[noreturn]] void loopPanel(void* pvParameters);
[[noreturn]] void loopKeyboard(void* pvParameters);
#endif //FIRMWARE_MAIN_H #endif //FIRMWARE_MAIN_H