Commit 0c5d48d6 authored by egorguslyan's avatar egorguslyan
Browse files

Merge branch 'untested' into 'master'

Manual sleep

See merge request !3
parents 80e37f6f 6ff83564
......@@ -127,6 +127,7 @@ struct
char S[64]; // Temp string
uint8_t unpreparedEEPROM : 1; // True if EEPROM contains special_key in each cell
uint8_t sleep : 1; // Sleep mode
uint8_t noAutoChangeScreen : 1; // Blocks idle changing screen
// Gestures events
uint8_t tapLeft : 1; // True when tapped left
......@@ -409,6 +410,8 @@ void setup()
// Start without animation
globalVars.animation = NO_ANIMATION;
globalVars.prepare = true;
// Block idle on welcome screen
globalVars.noAutoChangeScreen = true;
globalVars.minPPM = bit(13) - 1;
......@@ -417,9 +420,10 @@ void setup()
void checkSleep(DateTime* DT)
{
if ((globalVars.sleepHour > globalVars.wakeupHour) ||
((globalVars.sleepHour == globalVars.wakeupHour) &&
(globalVars.sleepMinute >= globalVars.wakeupMinute)))
if(globalVars.noAutoChangeScreen) globalVars.sleep = false;
else if ((globalVars.sleepHour > globalVars.wakeupHour) ||
((globalVars.sleepHour == globalVars.wakeupHour) &&
(globalVars.sleepMinute >= globalVars.wakeupMinute)))
{
globalVars.sleep = (((DT->hour > globalVars.sleepHour) ||
((DT->hour == globalVars.sleepHour) &&
......@@ -442,19 +446,21 @@ void checkSleep(DateTime* DT)
void loop()
{
// Terminate if buttuns are holded
static uint32_t timer_debug0 = 0;
static bool button = 0;
static bool last_button = 0;
last_button = button;
button = digitalRead(LBTN) | digitalRead(RBTN);
if(!button)
timer_debug0 = millis();
TIMER(timer_debug0, 5000)
{
timer_debug0 = millis();
PRINTLN_DEBUG(F("Debugging stopped"));
STOP_DEBUGGING;
}
#if(DEBUG)
static uint32_t timer_debug0 = 0;
static bool button = 0;
static bool last_button = 0;
last_button = button;
button = digitalRead(LBTN) | digitalRead(RBTN);
if(!button)
timer_debug0 = millis();
TIMER(timer_debug0, 5000)
{
timer_debug0 = millis();
PRINTLN_DEBUG(F("Debugging stopped"));
STOP_DEBUGGING;
}
#endif
// Measure CO₂ every 5 seconds
static uint32_t timer0 = 0;
......@@ -555,7 +561,15 @@ void loop()
// Display
static uint32_t timer5 = 0;
TIMER(timer5, 10000){}
TIMER(timer5, 20000)
{
if(!globalVars.noAutoChangeScreen && globalVars.currentScreen != homeScreen)
{
matrix.clear();
globalVars.currentScreen = homeScreen;
globalVars.currentState = 0;
}
}
else globalVars.sleep = false;
switch(globalVars.prepare)
{
......@@ -574,7 +588,10 @@ void loop()
if( globalVars.tapLeft || globalVars.tapRight ||
globalVars.holdLeft || globalVars.holdRight ||
globalVars.swipeLeft || globalVars.swipeRight )
timer5 = millis();
{
timer5 = millis();
// if(globalVars.sleep) unhandle();
}
if(globalVars.sleep)
matrix.clear();
else screens[globalVars.currentScreen].func(&screens[globalVars.currentScreen].arg);
......@@ -593,7 +610,9 @@ void loop()
globalVars.timer = 0;
globalVars.pomodoroTimer = 0;
tb.resetTimers();
timer_debug0 = 0;
#if(DEBUG)
timer_debug0 = 0;
#endif
timer0 = 0;
timer1 = 0;
timer2 = 0;
......
......@@ -8,16 +8,24 @@ void setPixel(mData* buffer, uint8_t x, uint8_t y, mData c)
void drawTomato(mData* buffer)
{
uint8_t x, y;
for(x = 1; x < 8; x++)
{
for(y = 1; y < 7; y++)
{
setPixel(buffer, x + 3, y, ((x == 1 || x == 7) && (y == 1 || y == 6)) ? mBlack : mRed);
}
}
for(x = 3; x < 6; x++)
{
setPixel(buffer, x + 3, 7, mGreen);
}
setPixel(buffer, 4 + 3, 6, mGreen);
}
void drawMoon(mData* buffer)
{
const uint64_t bm = 0b001100011000110000110000110000011001001110;
uint8_t x, y, i;
i = 0;
for(y = 1; y < 8; y++)
for(x = 10; x >= 5; x--)
setPixel(buffer, x, y, bitRead(bm, i++) ? mWhite : mBlack);
}
\ No newline at end of file
#pragma once
#define startWith SCREEN_WELCOME
#define homeScreen SCREEN_DASHBOARD
// Screens
/* Welcome screen with greetings
Swipe left when prompts to continue (nextScreeen0) */
......@@ -18,6 +19,9 @@ extern void pomodoroPrepare();
/* Service desk email */
extern void settings(Arg *arg);
extern void settingsPrepare();
/* Manual sleep screen */
extern void manualSleep(Arg *arg);
extern void manualSleepPrepare();
// Links
enum SCREEN : uint8_t
......@@ -28,12 +32,15 @@ enum SCREEN : uint8_t
SCREEN_GRAPH,
SCREEN_POMODORO,
SCREEN_SETTINGS, // For now it's just service desk
SCREEN_SLEEP,
};
const Screen screens[] = {
{ welcome, {0}, welcomePrepare, SCREEN_DASHBOARD, NONE, NONE },
{ welcome, {0}, welcomePrepare, homeScreen, NONE, NONE },
// Func Args Prepare func Back Forward Select
{ dashboard, {0}, dashboardPrepare, SCREEN_GRAPH, SCREEN_POMODORO, NONE },
{ graph, {0}, graphPrepare, SCREEN_DASHBOARD, NONE, NONE },
{ pomodoro, {0}, pomodoroPrepare, SCREEN_DASHBOARD, SCREEN_SETTINGS, NONE },
{ settings, {0}, settingsPrepare, SCREEN_POMODORO, NONE, NONE },
{ graph, {0}, graphPrepare, NONE, SCREEN_DASHBOARD, NONE },
{ pomodoro, {0}, pomodoroPrepare, SCREEN_DASHBOARD, SCREEN_SLEEP, NONE },
{ settings, {0}, settingsPrepare, SCREEN_SLEEP, NONE, NONE },
{ manualSleep, {0}, manualSleepPrepare, SCREEN_POMODORO, SCREEN_SETTINGS, homeScreen },
};
\ No newline at end of file
......@@ -68,6 +68,7 @@ void welcome(Arg *arg)
{
if(globalVars.panelOrientation != PANEL_UNKNOWN)
{
globalVars.noAutoChangeScreen = false;
changeScreen(SCREEN_WELCOME, 0, NO_ANIMATION);
break;
}
......@@ -141,12 +142,14 @@ void welcome(Arg *arg)
{
if(globalVars.swipeLeft)
{
globalVars.noAutoChangeScreen = false;
globalVars.panelOrientation = PANEL_NORMAL;
EEPROM.write(0, special_key | PANEL_NORMAL);
changeScreen(SCREEN_WELCOME, 0, ANIMATION_SHIFT_LEFT);
}
if(globalVars.swipeRight)
{
globalVars.noAutoChangeScreen = false;
globalVars.panelOrientation = PANEL_REVERSE;
EEPROM.write(0, special_key | PANEL_REVERSE);
changeScreen(SCREEN_WELCOME, 0, ANIMATION_SHIFT_LEFT);
......@@ -256,8 +259,10 @@ void dashboardPrepare()
void graph(Arg *arg)
{
// No need to update the graph, only handle gestures
if(globalVars.swipeRight)
changeScreen(SCREEN_GRAPH, 0, ANIMATION_SHIFT_RIGHT);
if(globalVars.swipeLeft)
changeScreen(SCREEN_GRAPH, 0, ANIMATION_SHIFT_LEFT);
changeScreen(SCREEN_GRAPH, 1, ANIMATION_SHIFT_LEFT);
unhandle();
}
......@@ -405,6 +410,8 @@ void settings(Arg *arg)
// Only handle gestures, update when needed
if(globalVars.swipeRight)
changeScreen(SCREEN_SETTINGS, 0, ANIMATION_SHIFT_RIGHT);
if(globalVars.swipeLeft)
changeScreen(SCREEN_SETTINGS, 1, ANIMATION_SHIFT_LEFT);
if(globalVars.tapLeft && (globalVars.currentState != 0))
{
globalVars.currentState--;
......@@ -427,4 +434,78 @@ void settingsPrepare()
strcpy_P(globalVars.S, strings[4]);
tb.setup(globalVars.S, LANGMASK(4), COLOR2, TB_STATIC, 0, 1, 16, 0);
tb.render();
}
void manualSleep(Arg *arg)
{
// Only 16x9
const uint16_t delayMap[] = {2000, TB_FRAMES_DELAY - 1, 0};
TIMER(globalVars.timer, delayMap[globalVars.currentState])
{
switch(globalVars.currentState)
{
case 0:
{
strcpy_P(globalVars.S, strings[5]);
tb.setup(globalVars.S, LANGMASK(5), COLOR2, TB_REPEAT, 0, 1, 16, TB_FRAMES_DELAY);
globalVars.currentState++;
}
break;
case 1:
{
switch(tb.render())
{
case 1:
globalVars.timer = millis();
break;
case 2:
matrix.clear();
drawMoon(&matrix.leds[0]);
globalVars.currentState = 0;
break;
}
}
break;
case 2:
{
// Do nothing
}
break;
}
}
// Gestures
if(globalVars.currentState == 2)
{
if( globalVars.tapLeft || globalVars.tapRight ||
globalVars.holdLeft || globalVars.holdRight ||
globalVars.swipeLeft || globalVars.swipeRight )
{
globalVars.noAutoChangeScreen = false;
changeScreen(SCREEN_SLEEP, 2, ANIMATION_SHIFT_UP);
}
}
else
{
if(globalVars.swipeRight)
changeScreen(SCREEN_SLEEP, 0, ANIMATION_SHIFT_RIGHT);
if(globalVars.swipeLeft)
changeScreen(SCREEN_SLEEP, 1, ANIMATION_SHIFT_LEFT);
if(globalVars.tapRight)
{
matrix.clear();
globalVars.noAutoChangeScreen = true;
globalVars.currentState = 2;
}
}
unhandle();
}
void manualSleepPrepare()
{
// Working with the main buffer cause there are no memory for additional
// Only 16x9
matrix.clear();
drawMoon(&matrix.leds[0]);
}
\ No newline at end of file
......@@ -6,17 +6,19 @@ const char string_hello[] PROGMEM = "Ghbdtn"; // Привет
const char string_start_prompt[] PROGMEM = "<- Cdfqgyb dktdj"; // Свайпни влево
const char string_pomodoro[] PROGMEM = "Gjvbljh"; // Помидор
const char string_stopped[] PROGMEM = "Jcnfyjdktyyj"; // Остановленно
const char string_sleep[] PROGMEM = "Cjy"; // Сон
// Need to make it PROGMEM
const uint64_t langmask[] = {0xFF, 0xFFFC, 0xFF, 0xFFFF, 0};
const uint64_t langmask[] = {0xFF, 0xFFFC, 0xFF, 0xFFFF, 0, 0xF};
#else
#define LANGMASK(n) 0
const char string_hello[] PROGMEM = "Hello";
const char string_start_prompt[] PROGMEM = "<- Swipe left";
const char string_pomodoro[] PROGMEM = "Pomodoro";
const char string_stopped[] PROGMEM = "Stopped";
const char string_sleep[] PROGMEM = "Sleep";
#endif
// Shared
const char string_service_desk[] PROGMEM = "gitlab+egorguslyan-dashboard-851-issue-@edugit.org";
const char* const strings[] = {string_hello, string_start_prompt, string_pomodoro, string_stopped, string_service_desk};
\ No newline at end of file
const char* const strings[] = {string_hello, string_start_prompt, string_pomodoro, string_stopped, string_service_desk, string_sleep};
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment