arduino stuffs
Diffstat (limited to 'mp3player/arduino/display/display.h')
-rw-r--r--mp3player/arduino/display/display.h35
1 files changed, 17 insertions, 18 deletions
diff --git a/mp3player/arduino/display/display.h b/mp3player/arduino/display/display.h
index 2445934..764e7f1 100644
--- a/mp3player/arduino/display/display.h
+++ b/mp3player/arduino/display/display.h
@@ -4,13 +4,11 @@
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
+#include "../math.h"
#include "freeserif.h"
#include "splash.h"
#include <Adafruit_SSD1306.h>
#include <Wire.h>
-
-static inline float lerp(float from, float to, float weight) { return from + (to - from) * weight; }
-
namespace OLED {
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
@@ -21,8 +19,8 @@ inline void clear() { oled.clearDisplay(); }
inline void flush() { oled.display(); }
// Adafruit_GFX::drawBitmap(..., size_x, size_y). adds multiplication factors
-void draw_bitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color, uint8_t size_x,
- uint8_t size_y) {
+void draw_bitmap(const int8_t x, const int8_t y, const uint8_t *bitmap, const int8_t w, const int8_t h,
+ const uint16_t color, const uint8_t size_x, const uint8_t size_y) {
int16_t i, j, byteWidth = (w + 7) / 8;
for (j = 0; j < h; j++)
@@ -35,21 +33,22 @@ void draw_bitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t
}
}
-#define SPLASH_SCALE 2
-#define SPLASH_BOTTOM (SCREEN_HEIGHT - SPLASH_SIZE) * (SPLASH_SCALE * SPLASH_SCALE)
-#define SPLASH_MIDDLE SCREEN_WIDTH / SPLASH_SCALE - SPLASH_SIZE
+static constexpr uint8_t SPLASH_SCALE = 2;
+static constexpr uint8_t SPLASH_BOTTOM = SCREEN_HEIGHT + (SPLASH_SIZE * SPLASH_SCALE);
+static constexpr uint8_t SPLASH_MIDDLE = SCREEN_WIDTH / SPLASH_SCALE - SPLASH_SIZE;
+
+static constexpr uint8_t splash_step = SPLASH_BOTTOM - lerp(SPLASH_BOTTOM, 0 - (SPLASH_SIZE * SPLASH_SCALE), 0.1);
+static constexpr int8_t SPLASH_TOP = -splash_step - (SPLASH_SIZE * SPLASH_SCALE);
void show_splash() {
- for (unsigned int c = 0; c < 2; c++) {
- for (unsigned int i = 0; i < 9; i++) {
- clear();
- const int16_t y_pos = lerp(SPLASH_BOTTOM, 0 - (SPLASH_SIZE * SPLASH_SCALE) - 30, (i + 1) / 10.);
- const int16_t x_pos = (rand() % 10 - 5) + SPLASH_MIDDLE;
- draw_bitmap(x_pos, y_pos, ships[i], SPLASH_SIZE, SPLASH_SIZE, WHITE, SPLASH_SCALE, SPLASH_SCALE);
- flush();
- delay(20);
- }
- delay(40);
+ int8_t x_pos = SPLASH_MIDDLE;
+ for (uint8_t i = 0; i < 100; i++) {
+ clear();
+ const int8_t y_pos = lerp(SPLASH_BOTTOM, SPLASH_TOP, (i + 1) / 100.0);
+ x_pos = clamp(x_pos + (rand() % 4 - 2), SPLASH_MIDDLE - 50, SPLASH_MIDDLE + 50);
+ draw_bitmap(x_pos, y_pos, ships[wrapi(i, 0, 8)], SPLASH_SIZE, SPLASH_SIZE, WHITE, SPLASH_SCALE, SPLASH_SCALE);
+ flush();
+ delay(20);
}
}