Browse Source

some cleanup

master
Martin Vladic 2 years ago
parent
commit
56ac9f58e8
  1. 2
      Middlewares/eez
  2. 2
      Src/CMakeLists.txt
  3. 7
      Src/conf/eez/gui_conf.h
  4. 175
      Src/date_time.cpp
  5. 22
      Src/date_time.h
  6. 1
      Src/firmware.cpp
  7. 22
      Src/gui/action.cpp
  8. 36
      Src/gui/data.cpp
  9. 13466
      Src/gui/document.cpp
  10. 104
      Src/gui/document.h
  11. 2
      template/post.js

2
Middlewares/eez

@ -1 +1 @@
Subproject commit 23839e9ea1c7118a7cc947712b37a3045f260804 Subproject commit 913fc220a21256119f6d590f8d7fa6334ea56240

2
Src/CMakeLists.txt

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.10) cmake_minimum_required(VERSION 3.10)
set (PROJECT_NAME eez-flow-template-sdl) set (PROJECT_NAME eez-flow-template-stm32f469i-disco)
project(${PROJECT_NAME}) project(${PROJECT_NAME})

7
Src/conf/eez/gui_conf.h

@ -1,10 +1,3 @@
#pragma once #pragma once
#include "../../gui/document.h" #include "../../gui/document.h"
#define PAGE_ID_ASYNC_OPERATION_IN_PROGRESS 0
#define COLOR_ID_BOOKMARK 0
/// Maximum allowed length (including label) of the keypad text.
#define MAX_KEYPAD_TEXT_LENGTH 128
#define MAX_KEYPAD_LABEL_LENGTH 64

175
Src/date_time.cpp

@ -1,175 +0,0 @@
#ifdef EEZ_PLATFORM_STM32
#include "main.h"
//#include "rtc.h"
#endif
#if defined(EEZ_PLATFORM_SIMULATOR)
#include <stdio.h>
#include <time.h>
#endif
#include "date_time.h"
namespace date_time {
// leap year calulator expects year argument as years offset from 1970
#define LEAP_YEAR(Y) \
(((1970 + Y) > 0) && !((1970 + Y) % 4) && (((1970 + Y) % 100) || !((1970 + Y) % 400)))
#define SECONDS_PER_MINUTE 60UL
#define SECONDS_PER_HOUR (SECONDS_PER_MINUTE * 60)
#define SECONDS_PER_DAY (SECONDS_PER_HOUR * 24)
// API starts months from 1, this array starts from 0
static const uint8_t monthDays[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
#if defined(EEZ_PLATFORM_SIMULATOR)
static uint32_t g_offset;
#endif
DateTime g_dateTime;
uint32_t makeTime(int year, int month, int day, int hour, int minute, int second) {
// seconds from 1970 till 1 jan 00:00:00 of the given year
year -= 1970;
uint32_t seconds = year * 365 * SECONDS_PER_DAY;
for (int i = 0; i < year; i++) {
if (LEAP_YEAR(i)) {
seconds += SECONDS_PER_DAY; // add extra days for leap years
}
}
// add days for this year, months start from 1
for (int i = 1; i < month; i++) {
if ((i == 2) && LEAP_YEAR(year)) {
seconds += SECONDS_PER_DAY * 29;
}
else {
seconds += SECONDS_PER_DAY * monthDays[i - 1]; // monthDay array starts from 0
}
}
seconds += (day - 1) * SECONDS_PER_DAY;
seconds += hour * SECONDS_PER_HOUR;
seconds += minute * SECONDS_PER_MINUTE;
seconds += second;
return seconds;
}
void breakTime(uint32_t time, int &resultYear, int &resultMonth, int &resultDay, int &resultHour,
int &resultMinute, int &resultSecond) {
// break the given time_t into time components
uint8_t year;
uint8_t month, monthLength;
uint32_t days;
resultSecond = time % 60;
time /= 60; // now it is minutes
resultMinute = time % 60;
time /= 60; // now it is hours
resultHour = time % 24;
time /= 24; // now it is days
year = 0;
days = 0;
while ((unsigned)(days += (LEAP_YEAR(year) ? 366 : 365)) <= time) {
year++;
}
resultYear = year + 1970; // year is offset from 1970
days -= LEAP_YEAR(year) ? 366 : 365;
time -= days; // now it is days in this year, starting at 0
days = 0;
month = 0;
monthLength = 0;
for (month = 0; month < 12; ++month) {
if (month == 1) { // february
if (LEAP_YEAR(year)) {
monthLength = 29;
}
else {
monthLength = 28;
}
}
else {
monthLength = monthDays[month];
}
if (time >= monthLength) {
time -= monthLength;
}
else {
break;
}
}
resultMonth = month + 1; // jan is month 1
resultDay = time + 1; // day of month
}
#if defined(EEZ_PLATFORM_SIMULATOR)
uint32_t nowUtc() {
time_t now_time_t = time(0);
struct tm *now_tm = gmtime(&now_time_t);
return makeTime(1900 + now_tm->tm_year, now_tm->tm_mon + 1, now_tm->tm_mday,
now_tm->tm_hour, now_tm->tm_min, now_tm->tm_sec);
}
#endif
bool readTime(uint8_t &hour, uint8_t &minute, uint8_t &second, uint8_t &subSeconds) {
#if defined(EEZ_PLATFORM_STM32)
// RTC_TimeTypeDef time;
// HAL_RTC_GetTime(&hrtc, &time, FORMAT_BIN);
//
// second = time.Seconds;
// minute = time.Minutes;
// hour = time.Hours;
// subSeconds = time.SubSeconds;
#endif
#if defined(EEZ_PLATFORM_SIMULATOR)
int year_, month_, day_, hour_, minute_, second_;
breakTime(g_offset + nowUtc(), year_, month_, day_, hour_, minute_, second_);
hour = uint8_t(hour_);
minute = uint8_t(minute_);
second = uint8_t(second_);
subSeconds = 0;
#endif
return true;
}
bool readDate(uint8_t &year, uint8_t &month, uint8_t &day) {
#if defined(EEZ_PLATFORM_STM32)
// RTC_DateTypeDef date;
// HAL_RTC_GetDate(&hrtc, &date, FORMAT_BIN);
//
// day = date.Date;
// month = date.Month;
// year = date.Year;
#endif
#if defined(EEZ_PLATFORM_SIMULATOR)
int year_, month_, day_, hour_, minute_, second_;
breakTime(g_offset + nowUtc(), year_, month_, day_, hour_, minute_, second_);
year = uint8_t(year_ - 2000);
month = uint8_t(month_);
day = uint8_t(day_);
#endif
return true;
}
void tick() {
readTime(g_dateTime.hour, g_dateTime.minute, g_dateTime.second, g_dateTime.subSecond);
readDate(g_dateTime.year, g_dateTime.month, g_dateTime.day);
}
} // date_time

22
Src/date_time.h

@ -1,22 +0,0 @@
#pragma once
#include <stdint.h>
namespace date_time {
struct DateTime {
uint8_t year;
uint8_t month;
uint8_t day;
uint8_t hour;
uint8_t minute;
uint8_t second;
uint8_t subSecond;
};
extern DateTime g_dateTime;
void tick();
}

1
Src/firmware.cpp

@ -25,7 +25,6 @@
#include <eez/flow/flow.h> #include <eez/flow/flow.h>
#include "date_time.h"
#include "firmware.h" #include "firmware.h"
#include "tasks.h" #include "tasks.h"
#include "gui/hooks.h" #include "gui/hooks.h"

22
Src/gui/action.cpp

@ -1,30 +1,8 @@
#include <eez/gui/gui.h> #include <eez/gui/gui.h>
#include <eez/core/util.h>
#include <eez/gui/widgets/input.h>
#include "../firmware.h"
#include "app_context.h"
#include "keypad.h"
namespace eez { namespace eez {
namespace gui { namespace gui {
void action_show_toast_message1() {
g_deviceAppContext.infoMessage("This is info message\nWith line 2!");
}
void action_show_toast_message2() {
g_deviceAppContext.errorMessage("This is error message\nWith line 2 ...\nand line 3!", true);
}
void doAction() {
g_deviceAppContext.infoMessage("It should be fixed now!");
}
void action_show_toast_message3() {
g_deviceAppContext.errorMessageWithAction("Some error occured!\nYou should fix it.", doAction, "Fix");
}
} // namespace gui } // namespace gui
} // namespace eez } // namespace eez

36
Src/gui/data.cpp

@ -1,45 +1,9 @@
#include <eez/core/alloc.h>
#include <eez/core/os.h>
#include <limits.h>
#include <eez/gui/gui.h> #include <eez/gui/gui.h>
#include <eez/gui/draw.h>
#include "../date_time.h"
#include "../firmware.h"
namespace eez { namespace eez {
namespace gui { namespace gui {
const EnumItem *g_enumDefinitions[] = { nullptr }; const EnumItem *g_enumDefinitions[] = { nullptr };
void data_date_year(DataOperationEnum operation, const WidgetCursor &widgetCursor, Value &value) {
value = date_time::g_dateTime.year + 2000;
}
void data_date_month(DataOperationEnum operation, const WidgetCursor &widgetCursor, Value &value) {
value = date_time::g_dateTime.month;
}
void data_date_day(DataOperationEnum operation, const WidgetCursor &widgetCursor, Value &value) {
value = date_time::g_dateTime.day;
}
void data_time_hour(DataOperationEnum operation, const WidgetCursor &widgetCursor, Value &value) {
value = date_time::g_dateTime.hour;
}
void data_time_minute(DataOperationEnum operation, const WidgetCursor &widgetCursor, Value &value) {
value = date_time::g_dateTime.minute;
}
void data_time_second(DataOperationEnum operation, const WidgetCursor &widgetCursor, Value &value) {
value = date_time::g_dateTime.second;
}
void data_time_sub_second(DataOperationEnum operation, const WidgetCursor &widgetCursor, Value &value) {
value = date_time::g_dateTime.subSecond;
}
} // namespace gui } // namespace gui
} // namespace eez } // namespace eez

13466
Src/gui/document.cpp

File diff suppressed because it is too large Load Diff

104
Src/gui/document.h

@ -117,29 +117,16 @@ enum StylesEnum {
STYLE_ID_MENU_WITH_BUTTONS_BUTTON = 12, STYLE_ID_MENU_WITH_BUTTONS_BUTTON = 12,
STYLE_ID_FPS_GRAPH = 13, STYLE_ID_FPS_GRAPH = 13,
STYLE_ID_BACKGROUND = 14, STYLE_ID_BACKGROUND = 14,
STYLE_ID_DEFAULT = 15, STYLE_ID_DEFAULT_24 = 15,
STYLE_ID_INLINE15 = 16, STYLE_ID_DEFAULT = 16,
STYLE_ID_INLINE16 = 17, STYLE_ID_DEFAULT_38 = 17,
STYLE_ID_INLINE17 = 18, STYLE_ID_BUTTON = 18,
STYLE_ID_DEFAULT_24 = 19, STYLE_ID_DISABLED_BUTTON = 19,
STYLE_ID_BUTTON = 20, STYLE_ID_BUTTON_ICON = 20,
STYLE_ID_BUTTON_DISABLED = 21, STYLE_ID_TEXT_INPUT = 21,
STYLE_ID_DEFAULT_38 = 22, STYLE_ID_TEXT_BUTTON = 22,
STYLE_ID_DISABLED_BUTTON = 23, STYLE_ID_TEXT_BUTTON_ICON = 23,
STYLE_ID_BUTTON_ICON = 24, STYLE_ID_TEXT_BUTTON_ICON_DISABLED = 24
STYLE_ID_TEXT_INPUT = 25,
STYLE_ID_TEXT_BUTTON = 26,
STYLE_ID_TEXT_BUTTON_ICON = 27,
STYLE_ID_TEXT_BUTTON_ICON_DISABLED = 28,
STYLE_ID_TAB = 29,
STYLE_ID_QUOTE = 30,
STYLE_ID_INLINE30 = 31,
STYLE_ID_INLINE31 = 32,
STYLE_ID_INLINE32 = 33,
STYLE_ID_INLINE33 = 34,
STYLE_ID_LABEL_LEFT_ALIGNED = 35,
STYLE_ID_BUTTON_LARGE = 36,
STYLE_ID_BLOCK = 37
}; };
enum ThemesEnum { enum ThemesEnum {
@ -182,29 +169,17 @@ enum ColorsEnum {
COLOR_ID_TEXT_INPUT_BORDER = 31, COLOR_ID_TEXT_INPUT_BORDER = 31,
COLOR_ID_CUSTOM_UNDEFINED = 32, COLOR_ID_CUSTOM_UNDEFINED = 32,
COLOR_ID_CUSTOM_000000 = 33, COLOR_ID_CUSTOM_000000 = 33,
COLOR_ID_CUSTOM_00FF1E = 34, COLOR_ID_CUSTOM_00FF1E = 34
COLOR_ID_CUSTOM_3510E6 = 35,
COLOR_ID_CUSTOM_14D224 = 36,
COLOR_ID_CUSTOM_EC2A15 = 37,
COLOR_ID_CUSTOM_B9F3F0 = 38,
COLOR_ID_CUSTOM_EEE30F = 39,
COLOR_ID_CUSTOM_C0C0C0 = 40,
COLOR_ID_CUSTOM_808080 = 41,
COLOR_ID_CUSTOM_C8C8C8 = 42
}; };
enum PagesEnum { enum PagesEnum {
PAGE_ID_NONE = 0, PAGE_ID_NONE = 0,
PAGE_ID_MAIN = 1, PAGE_ID_MAIN = 1,
PAGE_ID_NUMERIC_KEYPAD = 2, PAGE_ID_NUMERIC_KEYPAD = 2,
PAGE_ID_KEYBOARD = 3, PAGE_ID_KEYBOARD = 3
PAGE_ID_ANIM_DEMO = 4,
PAGE_ID_INPUT_DEMO = 5,
PAGE_ID_ROLLER_INPUT_DEMO = 6,
PAGE_ID_LOADER = 7
}; };
extern const uint8_t assets[66919]; extern const uint8_t assets[61981];
#elif defined(EEZ_PLATFORM_SIMULATOR) #elif defined(EEZ_PLATFORM_SIMULATOR)
@ -320,30 +295,17 @@ enum StylesEnum {
STYLE_ID_MENU_WITH_BUTTONS_BUTTON = 12, STYLE_ID_MENU_WITH_BUTTONS_BUTTON = 12,
STYLE_ID_FPS_GRAPH = 13, STYLE_ID_FPS_GRAPH = 13,
STYLE_ID_BACKGROUND = 14, STYLE_ID_BACKGROUND = 14,
STYLE_ID_DEFAULT = 15, STYLE_ID_DEFAULT_24 = 15,
STYLE_ID_INLINE15 = 16, STYLE_ID_DEFAULT = 16,
STYLE_ID_INLINE16 = 17, STYLE_ID_DEFAULT_38 = 17,
STYLE_ID_INLINE17 = 18, STYLE_ID_BUTTON = 18,
STYLE_ID_DEFAULT_24 = 19, STYLE_ID_DISABLED_BUTTON = 19,
STYLE_ID_BUTTON = 20, STYLE_ID_BUTTON_ICON = 20,
STYLE_ID_BUTTON_DISABLED = 21, STYLE_ID_TEXT_INPUT = 21,
STYLE_ID_DEFAULT_38 = 22, STYLE_ID_TEXT_BUTTON = 22,
STYLE_ID_DISABLED_BUTTON = 23, STYLE_ID_TEXT_BUTTON_ICON = 23,
STYLE_ID_BUTTON_ICON = 24, STYLE_ID_TEXT_BUTTON_ICON_DISABLED = 24,
STYLE_ID_TEXT_INPUT = 25, STYLE_ID_INLINE24 = 25
STYLE_ID_TEXT_BUTTON = 26,
STYLE_ID_TEXT_BUTTON_ICON = 27,
STYLE_ID_TEXT_BUTTON_ICON_DISABLED = 28,
STYLE_ID_TAB = 29,
STYLE_ID_QUOTE = 30,
STYLE_ID_INLINE30 = 31,
STYLE_ID_INLINE31 = 32,
STYLE_ID_INLINE32 = 33,
STYLE_ID_INLINE33 = 34,
STYLE_ID_LABEL_LEFT_ALIGNED = 35,
STYLE_ID_BUTTON_LARGE = 36,
STYLE_ID_BLOCK = 37,
STYLE_ID_INLINE37 = 38
}; };
enum ThemesEnum { enum ThemesEnum {
@ -387,15 +349,7 @@ enum ColorsEnum {
COLOR_ID_CUSTOM_UNDEFINED = 32, COLOR_ID_CUSTOM_UNDEFINED = 32,
COLOR_ID_CUSTOM_000000 = 33, COLOR_ID_CUSTOM_000000 = 33,
COLOR_ID_CUSTOM_00FF1E = 34, COLOR_ID_CUSTOM_00FF1E = 34,
COLOR_ID_CUSTOM_3510E6 = 35, COLOR_ID_CUSTOM_FFFFFF = 35
COLOR_ID_CUSTOM_14D224 = 36,
COLOR_ID_CUSTOM_EC2A15 = 37,
COLOR_ID_CUSTOM_B9F3F0 = 38,
COLOR_ID_CUSTOM_EEE30F = 39,
COLOR_ID_CUSTOM_C0C0C0 = 40,
COLOR_ID_CUSTOM_808080 = 41,
COLOR_ID_CUSTOM_C8C8C8 = 42,
COLOR_ID_CUSTOM_FFFFFF = 43
}; };
enum PagesEnum { enum PagesEnum {
@ -403,14 +357,10 @@ enum PagesEnum {
PAGE_ID_MAIN = 1, PAGE_ID_MAIN = 1,
PAGE_ID_NUMERIC_KEYPAD = 2, PAGE_ID_NUMERIC_KEYPAD = 2,
PAGE_ID_KEYBOARD = 3, PAGE_ID_KEYBOARD = 3,
PAGE_ID_ANIM_DEMO = 4, PAGE_ID_FRONT_PANEL = 4
PAGE_ID_INPUT_DEMO = 5,
PAGE_ID_ROLLER_INPUT_DEMO = 6,
PAGE_ID_LOADER = 7,
PAGE_ID_FRONT_PANEL = 8
}; };
extern const uint8_t assets[83361]; extern const uint8_t assets[78397];
#endif #endif

2
template/post.js

@ -25,7 +25,7 @@
* @param {WizardContext} context * @param {WizardContext} context
*/ */
async function postProcessing(context) { async function postProcessing(context) {
await context.replaceInFile("Src/CMakeLists.txt", "eez-flow-template-sdl", context.projectName); await context.replaceInFile("Src/CMakeLists.txt", "eez-flow-template-stm32f469i-disco", context.projectName);
await context.replaceInFile("README.md", "{{projectDirPath}}", context.projectDirPath); await context.replaceInFile("README.md", "{{projectDirPath}}", context.projectDirPath);
await context.replaceInFile("README.md", "{{projectName}}", context.projectName); await context.replaceInFile("README.md", "{{projectName}}", context.projectName);

Loading…
Cancel
Save