/
spaceswimmer
/
perf-source
Обзор
Документация
Войти
/
spaceswimmer
/
perf-source
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
PerfSource/Schedule.cpp
66 строк
2 KB
spaceswimmer
master removed sleeping in loop
06 апр 2026, 11:56
06 апр 2026, 11:56
e32908d
Код
Авторство
О чём код?
#include "Schedule.h" #include <math.h> #include "Config.h" float potToFrequency(uint8_t potValue) { return fMin_exact + (float)(potValue - 1) * (fMax_exact - fMin_exact) / 234.0; } uint8_t frequencyToPot(float frequency) { float value = 1 + (frequency - fMin_exact) * 234.0 / (fMax_exact - fMin_exact); if (value < 1) value = 1; if (value > 235) value = 235; return (uint8_t)value; } int findCurrentPoint(unsigned long elapsed) { for (int i = 0; i < scheduleSize; i++) { if (schedule[i].timeMs >= elapsed) { return i > 0 ? i - 1 : 0; } } return scheduleSize - 1; } void generateSchedule(uint8_t pot_min, uint8_t pot_max) { scheduleSize = 0; unsigned long totalTimeMs = (unsigned long)(tMax * 1000); unsigned long stepTimeMs = 50; for (unsigned long t = 0; t <= totalTimeMs && scheduleSize < 1200; t += stepTimeMs) { uint8_t potValue; float normalizedTime = (float)t / (float)totalTimeMs; if (law == "linear") { potValue = pot_min + (uint8_t)(normalizedTime * (pot_max - pot_min)); } else if (law == "exponential") { float I = pot_min + (pot_max - pot_min) * (exp(normalizedTime * log(236)) - 1) / 235; if (I > 235.0) I = 235.0; if (I < 1.0) I = 1.0; potValue = (uint8_t)I; } else if (law == "chirp") { // Cast to float BEFORE arithmetic to avoid integer division float f_start = (float)pot_min; float f_end = (float)pot_max; // Logarithmic chirp (appropriate for frequency-like values) float ratio = f_end / f_start; float potValueFloat = f_start * powf(ratio, normalizedTime); // Clamp to valid range if (potValueFloat > 255.0f) potValueFloat = 255.0f; if (potValueFloat < 1.0f) potValueFloat = 1.0f; potValue = (uint8_t)potValueFloat; } schedule[scheduleSize].timeMs = t; schedule[scheduleSize].potValue = potValue; scheduleSize++; } Serial.print("Generated "); Serial.print(scheduleSize); Serial.println(" points"); }