Skip to content

Commit 2e59917

Browse files
committed
Added support for separate animation durations; updated mario assets
Added support to the config file for independent timing configurations; updated mario bitmaps to look much better
1 parent 397f5f6 commit 2e59917

File tree

7 files changed

+28
-14
lines changed

7 files changed

+28
-14
lines changed

Config.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,20 @@ Config::Config(const string& filename) {
9898
throw invalid_argument(error.str());
9999
}
100100
// Parse image info
101-
_animation_duration = root["animation_duration"];
101+
int image_set_duration = root["image_set_duration"];
102+
_image_set_duration = ((float)image_set_duration)/1000.0;
103+
libconfig::Setting& animation_durations_config = root["animation_durations"];
104+
this->_animation_durations.clear();
105+
for (int i=0; i<animation_durations_config.getLength(); ++i)
106+
{
107+
libconfig::Setting& row = animation_durations_config[i];
108+
for(int j=0; j<row.getLength(); ++j)
109+
{
110+
int duration = row[j]["value"];
111+
this->_animation_durations.push_back(((float)duration)/1000.0);
112+
}
113+
114+
}
102115
libconfig::Setting& images_config = root["images"];
103116
for (int i = 0; i < images_config.getLength(); ++i)
104117
{
@@ -139,7 +152,7 @@ Config::Config(const string& filename) {
139152
throw invalid_argument(error.str());
140153
}
141154
catch (const libconfig::ConfigException& ex) {
142-
throw runtime_error("Error loading configuration!");
155+
throw runtime_error("Error while loading configuration");
143156
}
144157
}
145158

Config.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ class Config {
1414
~Config();
1515

1616
// Attribute accessors:
17-
float getAnimationDuration() const {
18-
return _animation_duration;
17+
float getAnimationDuration(int set_index) const {
18+
return _animation_durations[set_index];
1919
}
2020

2121
int getDisplayWidth() const {
@@ -49,6 +49,9 @@ class Config {
4949
int getImageSetCount() const {
5050
return _image_sets.size();
5151
}
52+
int getImageSetDuration() const {
53+
return _image_set_duration;
54+
}
5255
int getParallelCount() const {
5356
return _parallel_count;
5457
}
@@ -77,7 +80,8 @@ class Config {
7780
_crop_y;
7881
int _led_cutoff,
7982
_led_max_brightness;
80-
float _animation_duration;
83+
int _image_set_duration;
84+
std::vector<float> _animation_durations;
8185
std::vector<GridTransformer::Panel> _panels;
8286
std::vector<std::vector<std::string>*> _image_sets;
8387
};

Spectrometer.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void Spectrometer::GetBins(short* buffer, int* bins)
6464

6565
unsigned int Spectrometer::GetBitmapSetIndex(float seconds)
6666
{
67-
float full_cycle = 30.0;
67+
float full_cycle = this->config->getImageSetDuration();
6868
float divisor = this->logos.size();
6969
float interval = full_cycle/divisor;
7070
int value = (int)seconds%(int)full_cycle;
@@ -74,7 +74,7 @@ unsigned int Spectrometer::GetBitmapSetIndex(float seconds)
7474

7575
unsigned int Spectrometer::GetBitmapIndex(float seconds, int set_index)
7676
{
77-
int weight = (int)(100.0*this->animationDuration);
77+
int weight = (int)(100.0*this->config->getAnimationDuration(set_index));
7878
int value = (int)(seconds*100.0)%weight;
7979
int image_count = this->config->getImageCount(set_index);
8080
int loop_image_count = 1;
@@ -224,9 +224,6 @@ void Spectrometer::InitializeLEDMatrix(char* config_path)
224224
this->panelHeight = height;
225225
fprintf(stderr, "\tSize: %d x %d\n", this->panelWidth, this->panelHeight);
226226

227-
// bitmap stuff
228-
this->animationDuration = this->config->getAnimationDuration();
229-
230227
// Initialize GPIO
231228
if (!this->io.Init())
232229
{

Spectrometer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ class Spectrometer
7979
int panelWidth = 0;
8080
int panelHeight = 0;
8181
float seconds = 0.0;
82-
float animationDuration = 1.0;
8382
int mailbox;
8483
struct GPU_FFT *fft;
8584

mario-walking-1.bmp

0 Bytes
Binary file not shown.

mario-walking-2.bmp

0 Bytes
Binary file not shown.

matrix.cfg

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,11 @@ led_max_brightness = 225;
7979
//crop_origin = (0, 0)
8080

8181
// define image parameters
82-
image_set_duration = 60.0;
83-
animation_duration = 1.0;
82+
image_set_duration = 60000;
83+
animation_durations = (
84+
( { value = 200; } )
85+
)
8486
images = (
85-
( { value = "burn-logo.bmp"; }, { value = "burn-logo-2.bmp"; }, { value = "burn-logo-3.bmp"; }, { value = "burn-logo-4.bmp"; } , { value = "burn-logo-5.bmp"; } ),
8687
( { value = "mario-walking-1.bmp"; }, { value = "mario-walking-2.bmp"; } )
8788

8889
)

0 commit comments

Comments
 (0)