126 lines
2.6 KiB
C
126 lines
2.6 KiB
C
/*
|
|
* Stairs lighting
|
|
* Copyright 2017 (c) Mark van Renswoude
|
|
*
|
|
* https://git.x2software.net/pub/Stairs
|
|
*/
|
|
#include "display.h"
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
#include <avr/pgmspace.h>
|
|
#include "lib/VeryTinySSD1306.h"
|
|
#include "lib/VeryTinyBigChars.h"
|
|
#include "lib/TinyMillis.h"
|
|
#include "global.h"
|
|
|
|
|
|
#define CharSpacing 4
|
|
#define CharOuterWidth (SSD1306_CharWidth_32px + CharSpacing)
|
|
#define SingleCharCenteredX ((SSD1306_DisplayWidth - SSD1306_CharWidth_32px) / 2)
|
|
#define WaitAnimationInterval 250
|
|
|
|
|
|
#define WaitAnimationMaxStep 3
|
|
const uint16_t WaitAnimation [] PROGMEM = {
|
|
0b0000000000000100, // Left
|
|
0b0000000010000000, // Middle
|
|
0b0001000000000000, // Right
|
|
0b0000000010000000 // Middle
|
|
};
|
|
/*
|
|
#define WaitAnimationMaxStep 7
|
|
const uint16_t WaitAnimation [] PROGMEM = {
|
|
0b0000000001000000, // Top
|
|
0b0000100000000000, // Top-right
|
|
0b0001000000000000, // Right
|
|
0b0010000000000000, // Bottom-right
|
|
0b0000000100000000, // Bottom
|
|
0b0000000000001000, // Bottom-left
|
|
0b0000000000000100, // Left
|
|
0b0000000000000010 // Top-left
|
|
};
|
|
*/
|
|
|
|
|
|
bool isWait = false;
|
|
uint16_t lastWait = 0;
|
|
uint8_t waitAnimationStep = 0;
|
|
|
|
|
|
|
|
inline void display_drawNumber(uint8_t* x, uint8_t value)
|
|
{
|
|
if (value > 9)
|
|
{
|
|
ssd1306_drawdigit_32px(*x, value / 10);
|
|
*x += CharOuterWidth;
|
|
ssd1306_drawdigit_32px(*x, value % 10);
|
|
}
|
|
else
|
|
ssd1306_drawdigit_32px(*x, value);
|
|
|
|
*x += CharOuterWidth;
|
|
}
|
|
|
|
|
|
void display_init(void)
|
|
{
|
|
ssd1306_begin_default();
|
|
ssd1306_clear();
|
|
ssd1306_on();
|
|
ssd1306_switchRenderFrame();
|
|
}
|
|
|
|
|
|
void display_drawIndex(void)
|
|
{
|
|
ssd1306_clear();
|
|
|
|
uint8_t moduleIndex = global_getModuleIndex();
|
|
|
|
if (moduleIndex == ModuleIndexUndefined)
|
|
{
|
|
ssd1306_drawminus_32px(SingleCharCenteredX);
|
|
}
|
|
else
|
|
{
|
|
uint8_t firstStep = (moduleIndex * 2) + 1;
|
|
uint8_t totalWidth = 3 * CharOuterWidth;
|
|
|
|
if (firstStep == 9)
|
|
totalWidth += CharOuterWidth;
|
|
else if (firstStep > 9)
|
|
totalWidth += 2 * CharOuterWidth;
|
|
|
|
|
|
uint8_t currentX = (SSD1306_DisplayWidth - totalWidth) / 2;
|
|
display_drawNumber(¤tX, firstStep);
|
|
|
|
ssd1306_drawminus_32px(currentX);
|
|
currentX += CharOuterWidth;
|
|
|
|
display_drawNumber(¤tX, firstStep + 1);
|
|
}
|
|
|
|
ssd1306_switchFrame();
|
|
}
|
|
|
|
|
|
void display_drawWait(void)
|
|
{
|
|
uint16_t currentTime = millis();
|
|
|
|
if (isWait && currentTime - lastWait < WaitAnimationInterval)
|
|
return;
|
|
|
|
ssd1306_clear();
|
|
ssd1306_drawchar_32px(SingleCharCenteredX, pgm_read_word(&WaitAnimation[waitAnimationStep]));
|
|
ssd1306_switchFrame();
|
|
|
|
waitAnimationStep++;
|
|
if (waitAnimationStep > WaitAnimationMaxStep)
|
|
waitAnimationStep = 0;
|
|
|
|
isWait = true;
|
|
lastWait = currentTime;
|
|
} |