PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Waveform.h 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #ifndef WAVEFORM_H__
  2. #define WAVEFORM_H__
  3. #include <Arduino.h>
  4. #include <math.h>
  5. #include "ILI9488_t3.h"
  6. #include "BaseAnimation.h"
  7. class Waveform : public BaseAnimation {
  8. public:
  9. Waveform() : BaseAnimation() {};
  10. void init( ILI9488_t3 tft );
  11. uint_fast16_t bgColor( void );
  12. String title();
  13. void perFrame( ILI9488_t3 tft, FrameParams frameParams );
  14. private:
  15. uint_fast16_t _step = 0;
  16. uint_fast8_t _colorPhase = 0;
  17. uint_fast16_t _bgColor;
  18. };
  19. void Waveform::init( ILI9488_t3 tft ) {
  20. _bgColor = tft.color565( 0, 0, 0x55 );
  21. }
  22. uint_fast16_t Waveform::bgColor( void ) {
  23. return _bgColor;
  24. }
  25. String Waveform::title() {
  26. return "Waveform";
  27. }
  28. void Waveform::perFrame( ILI9488_t3 tft, FrameParams frameParams ) {
  29. uint_fast16_t w = tft.width();
  30. uint_fast16_t h = tft.height();
  31. // fillRect: flickers pretty bad
  32. //tft.fillRect( 0, 0, w, h, LV_RED );
  33. // Prepare body color
  34. uint_fast8_t bright = (frameParams.audioPeak >> 1); // 0..512 -> 0..255
  35. uint_fast16_t bodyColor = tft.color565( bright, bright, 0 ); // yellow
  36. // Prepare body height
  37. uint_fast16_t h_2 = (h >> 1);
  38. uint_fast16_t bodyHeight = frameParams.audioMean * h;
  39. tft.drawFastVLine( _step, h_2-(bodyHeight>>1), bodyHeight, bodyColor );
  40. // Clear this column. Background should have a triangle wave effect
  41. uint_fast8_t bgBright = _colorPhase + _step;
  42. if( bgBright & 0x80 ) {
  43. bgBright = (0xff-bgBright) << 1;
  44. } else {
  45. bgBright <<= 1;
  46. }
  47. uint_fast16_t bgColor = tft.color565( 0, 0, bgBright );
  48. // Draw background color in the other pixels
  49. uint_fast16_t margin = (h - bodyHeight) >> 1;
  50. tft.drawFastVLine( _step, 0, margin, bgColor );
  51. tft.drawFastVLine( _step, h - margin, margin, bgColor );
  52. // Advance to next line
  53. if( _step == 0 ) {
  54. _step = w - 1; // Restart drawing on right-hand size
  55. // After the screen is covered: Advance the background color
  56. _colorPhase += 3;
  57. } else {
  58. _step--;
  59. }
  60. }
  61. #endif