From 680cc6ceda8ae160e13feda830cc6726aa6749f0 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Mon, 28 Aug 2023 11:00:02 +0800 Subject: [PATCH] update --- components/date/date_helper.cpp | 53 +++++++++++++++++++++++++++++++ components/date/date_helper.hpp | 9 ++++++ components/dwin/text_displayer.cpp | 6 ++++ components/dwin/text_displayer.hpp | 1 + components/dwin/var_icon.cpp | 13 ++++++-- components/dwin/var_icon.hpp | 2 ++ components/zformater/zsimple_formater.cpp | 0 components/zformater/zsimple_formater.hpp | 32 +++++++++++++++++++ 8 files changed, 113 insertions(+), 3 deletions(-) create mode 100644 components/date/date_helper.cpp create mode 100644 components/date/date_helper.hpp create mode 100644 components/zformater/zsimple_formater.cpp create mode 100644 components/zformater/zsimple_formater.hpp diff --git a/components/date/date_helper.cpp b/components/date/date_helper.cpp new file mode 100644 index 0000000..a8fd6e0 --- /dev/null +++ b/components/date/date_helper.cpp @@ -0,0 +1,53 @@ +#include "date_helper.hpp" + +using namespace iflytop; +using namespace std; + +int DateHelper::getMaxDay(int year, int month) { + int daymax = 0; + switch (month) { + case 1: + daymax = 31; + break; + case 2: + if (year % 4 == 0) { + daymax = 29; + } else { + daymax = 28; + } + break; + case 3: + daymax = 31; + break; + case 4: + daymax = 30; + break; + case 5: + daymax = 31; + break; + case 6: + daymax = 30; + break; + case 7: + daymax = 31; + break; + case 8: + daymax = 31; + break; + case 9: + daymax = 30; + break; + case 10: + daymax = 31; + break; + case 11: + daymax = 30; + break; + case 12: + daymax = 31; + break; + default: + break; + } + return daymax; +} \ No newline at end of file diff --git a/components/date/date_helper.hpp b/components/date/date_helper.hpp new file mode 100644 index 0000000..35ee7e5 --- /dev/null +++ b/components/date/date_helper.hpp @@ -0,0 +1,9 @@ +#pragma once + +namespace iflytop { +using namespace std; +class DateHelper { + public: + static int getMaxDay(int year, int month); +}; +} // namespace iflytop \ No newline at end of file diff --git a/components/dwin/text_displayer.cpp b/components/dwin/text_displayer.cpp index eae4c99..a8855d3 100644 --- a/components/dwin/text_displayer.cpp +++ b/components/dwin/text_displayer.cpp @@ -11,6 +11,12 @@ using namespace std; } static uint8_t txcache[256]; +bool TextDisplayer::init(DwinScreen *dwin_screen, uint16_t valsize) { + uint16_t descript_add = dwin_screen->alloc_one_text_displayer(); + uint16_t val_add = dwin_screen->alloc_free_ram(valsize); + return init(dwin_screen, descript_add, val_add); +} + bool TextDisplayer::init(DwinScreen *dwin_screen, uint16_t descript_add, uint16_t val_add) { // m_dwin_screen = dwin_screen; diff --git a/components/dwin/text_displayer.hpp b/components/dwin/text_displayer.hpp index 984c04e..763db44 100644 --- a/components/dwin/text_displayer.hpp +++ b/components/dwin/text_displayer.hpp @@ -72,6 +72,7 @@ class TextDisplayer { TextDisplayerDescript_t m_descript; public: + bool init(DwinScreen *dwin_screen, uint16_t valsize); bool init(DwinScreen *dwin_screen, uint16_t descript_add, uint16_t val_add); /** * @brief Set the Font object diff --git a/components/dwin/var_icon.cpp b/components/dwin/var_icon.cpp index bfbfc14..360395d 100644 --- a/components/dwin/var_icon.cpp +++ b/components/dwin/var_icon.cpp @@ -20,6 +20,15 @@ bool VarIcon::init(DwinScreen *dwin_screen, uint16_t descript_add) { readcfg(); return true; } + +// void VarIcon::initcfg(const char *pos, const char *iconpath, uint16_t initval) { +// int posx = 0; +// int posy = 0; +// sscanf(pos, "(%d,%d)", &posx, &posy); +// initcfg(m_dwin_screen->alloc_one_var_icon(), posx, posy, iconpath, initval); +// } +void VarIcon::initcfg(int x, int y, const char *iconpath, uint16_t initval) { initcfg(m_dwin_screen->alloc_one_var_icon(), x, y, iconpath, initval); } + void VarIcon::initcfg(uint16_t valpointerAdd, uint16_t posx, uint16_t posy, const char *iconpath, uint16_t initval) { int iconlib = 0; int iconmin = 0; @@ -80,6 +89,4 @@ void VarIcon::show() { _setVal(m_val); } VarIconDescript_t &VarIcon::getDescript() { return m_descript; } -bool VarIcon::_setVal(uint16_t val) { - return m_dwin_screen->write_varspace16(m_descript.m_VP, val, 100); -} \ No newline at end of file +bool VarIcon::_setVal(uint16_t val) { return m_dwin_screen->write_varspace16(m_descript.m_VP, val, 100); } \ No newline at end of file diff --git a/components/dwin/var_icon.hpp b/components/dwin/var_icon.hpp index 2c6efc6..3a9682e 100644 --- a/components/dwin/var_icon.hpp +++ b/components/dwin/var_icon.hpp @@ -49,6 +49,8 @@ class VarIcon { * @param posy 图形的左上角y坐标 * @param iconpath 图形的路径 47/1:1 iconlib/iconmin:iconmax */ + // void initcfg(const char *pos, const char *iconpath, uint16_t initval); + void initcfg(int x, int y, const char *iconpath, uint16_t initval); void initcfg(uint16_t valpointerAdd, uint16_t posx, uint16_t posy, const char *iconpath, uint16_t initval); public: diff --git a/components/zformater/zsimple_formater.cpp b/components/zformater/zsimple_formater.cpp new file mode 100644 index 0000000..e69de29 diff --git a/components/zformater/zsimple_formater.hpp b/components/zformater/zsimple_formater.hpp new file mode 100644 index 0000000..231c11e --- /dev/null +++ b/components/zformater/zsimple_formater.hpp @@ -0,0 +1,32 @@ +#pragma once +#include +#include +#include +#include +namespace iflytop { +using namespace std; +class ZSimpleFormater { + private: + char* m_str; + + public: + ZSimpleFormater(const char* fmt, ...) { + m_str = (char*)malloc(128); + + va_list args; + va_start(args, fmt); + vsprintf(m_str, fmt, args); + va_end(args); + } + ~ZSimpleFormater() { + if (m_str) { + free(m_str); + m_str = NULL; + } + }; + const char* c_str() { return m_str; } +}; + +#define zsfmt ZSimpleFormater + +} // namespace iflytop \ No newline at end of file