Skip to content

Commit

Permalink
Make FPS controllable
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed Aug 12, 2024
1 parent 365e614 commit 17d5d25
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
8 changes: 5 additions & 3 deletions Led/Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ struct led_protocol : public ossia::net::protocol_base
return;
}

constexpr float frequency = 60;
m_timer.set_delay(std::chrono::milliseconds{
static_cast<int>(1000.0f / static_cast<float>(frequency))});
auto fps = std::clamp(set.fps, 0.001f, 1000.f);
if (set.fps <= 0.f)
fps = 30.;
m_timer.set_delay(
std::chrono::milliseconds{static_cast<int>(1000.0f / fps)});
}

~led_protocol()
Expand Down
7 changes: 7 additions & 0 deletions Led/ProtocolSettingsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,16 @@ ProtocolSettingsWidget::ProtocolSettingsWidget(QWidget* parent)
m_format = new QComboBox{this};
m_format->addItems({"GRB", "RGB"});

m_fps = new QDoubleSpinBox{this};
m_fps->setRange(0.001, 1000);
m_fps->setValue(60.);

auto layout = new QFormLayout;
layout->addRow(tr("Name"), m_deviceNameEdit);
layout->addRow(tr("Device"), m_spiDevice);
layout->addRow(tr("Pixels"), m_pixels);
layout->addRow(tr("Format"), m_format);
layout->addRow(tr("FPS"), m_fps);

setLayout(layout);
}
Expand All @@ -69,6 +74,7 @@ Device::DeviceSettings ProtocolSettingsWidget::getSettings() const
settings.num_pixels = this->m_pixels->value();
settings.format
= static_cast<NeoPixelsFormat>(this->m_format->currentIndex());
settings.fps = this->m_fps->value();
s.deviceSpecificSettings = QVariant::fromValue(settings);

return s;
Expand All @@ -83,5 +89,6 @@ void ProtocolSettingsWidget::setSettings(
m_spiDevice->setText(specif.device);
m_pixels->setValue(specif.num_pixels);
m_format->setCurrentIndex(static_cast<int>(specif.format));
m_fps->setValue(specif.fps);
}
}
2 changes: 2 additions & 0 deletions Led/ProtocolSettingsWidget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

class QLineEdit;
class QSpinBox;
class QDoubleSpinBox;
class QTableWidget;
class QPushButton;

Expand All @@ -28,5 +29,6 @@ class ProtocolSettingsWidget final : public Device::ProtocolSettingsWidget
QLineEdit* m_spiDevice{};
QSpinBox* m_pixels{};
QComboBox* m_format{};
QDoubleSpinBox* m_fps{};
};
}
1 change: 1 addition & 0 deletions Led/SpecificSettings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ struct SpecificSettings
int num_pixels{12};
int speed{800};
NeoPixelsFormat format{NeoPixelsFormat::GRB};
float fps{60.f};
};
}

Expand Down
6 changes: 4 additions & 2 deletions Led/SpecificSettingsSerialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
template <>
void DataStreamReader::read(const Led::SpecificSettings& n)
{
m_stream << n.device << n.num_pixels << n.speed << n.format;
m_stream << n.device << n.num_pixels << n.speed << n.format << n.fps;
insertDelimiter();
}

template <>
void DataStreamWriter::write(Led::SpecificSettings& n)
{
m_stream >> n.device >> n.num_pixels >> n.speed >> n.format;
m_stream >> n.device >> n.num_pixels >> n.speed >> n.format >> n.fps;
checkDelimiter();
}

Expand All @@ -24,6 +24,7 @@ void JSONReader::read(const Led::SpecificSettings& n)
obj["Pixels"] = n.num_pixels;
obj["Speed"] = n.speed;
obj["Format"] = n.format;
obj["FPS"] = n.fps;
}

template <>
Expand All @@ -33,4 +34,5 @@ void JSONWriter::write(Led::SpecificSettings& n)
n.num_pixels <<= obj["Pixels"];
n.speed <<= obj["Speed"];
n.format <<= obj["Format"];
n.fps <<= obj["FPS"];
}

0 comments on commit 17d5d25

Please sign in to comment.