Generator for the DrawPoints struct above. n_led: How many led's there are in total. factor: 0->1, indicates % of led's "on".
| 258 | // n_led: How many led's there are in total. |
| 259 | // factor: 0->1, indicates % of led's "on". |
| 260 | struct F { |
| 261 | static DrawPoints Generate(int n_led, float factor) { |
| 262 | DrawPoints out; |
| 263 | fl::memset(&out, 0, sizeof(out)); |
| 264 | if (n_led == 0 || factor == 0.0f) { |
| 265 | out.n_black0 = n_led; |
| 266 | return out; |
| 267 | } |
| 268 | const int is_odd = (n_led % 2); |
| 269 | const int n_half_lights = n_led / 2 + is_odd; |
| 270 | const float f_half_fill = n_half_lights * factor; |
| 271 | const int n_half_fill = static_cast<int>(f_half_fill); // Truncates float. |
| 272 | |
| 273 | float fade_pix_perc = f_half_fill - static_cast<float>(n_half_fill); |
| 274 | int n_fade_pix = fade_pix_perc < 1.0f; |
| 275 | if (n_half_fill == 0) { |
| 276 | n_fade_pix = 1; |
| 277 | } |
| 278 | int n_half_black = n_half_lights - n_half_fill - n_fade_pix; |
| 279 | |
| 280 | int n_fill_pix = 0; |
| 281 | if (n_half_fill > 0) { |
| 282 | n_fill_pix = n_half_fill * 2 + (is_odd ? -1 : 0); |
| 283 | } |
| 284 | |
| 285 | out.n_black0 = n_half_black; |
| 286 | out.n_fade0 = n_fade_pix; |
| 287 | out.n_fill = n_fill_pix; |
| 288 | out.n_fade1 = n_fade_pix; |
| 289 | if (!n_fill_pix && is_odd) { |
| 290 | out.n_fade1 = 0; |
| 291 | } |
| 292 | out.n_black1 = n_half_black; |
| 293 | out.fade_factor = fade_pix_perc; |
| 294 | return out; |
| 295 | } |
| 296 | }; |
| 297 | |
| 298 | |
| 299 | led_rope->RawBeginDraw(); |
no outgoing calls
no test coverage detected