main display center strings, uptime calcumation

This commit is contained in:
olikraus 2017-06-05 17:32:53 +02:00
parent e2bbaa69d5
commit b7ce3ac92b
8 changed files with 141 additions and 17 deletions

View File

@ -224,3 +224,12 @@ void set_date(uint8_t yt, uint8_t yo, uint8_t mt, uint8_t mo, uint8_t dayt, uint
__enable_irq();
}
/* value 1..7, 0 is default (do not set) */
void set_contrast(uint8_t v)
{
if ( v > 0 )
{
v = v * 7*32;
u8g2_SetContrast(gui_menu.u8g2, v);
}
}

View File

@ -14,6 +14,8 @@
#include "u8g2.h"
#include "rtc.h"
#ifdef NOT_USED
/* read RTC register into bcd array */
void rtc_register_to_bcd(rtc_t *rtc)
{
@ -75,4 +77,6 @@ void rtc_draw_time(rtc_t *rtc, u8g2_t *u8g2)
u8g2_SetFont(u8g2, u8g2_font_helvB18_tn);
u8g2_DrawStr(u8g2, 0,23, s);
}
}
#endif

View File

@ -23,10 +23,14 @@ extern u8g2_t u8g2;
struct _gui_data
{
uint16_t uptime; /* uptime in days, 10 bits, counts from 0 to 999, this value will be stored in the backup register */
uint16_t week_time; /* calculated: derived from h, mt, mo and weekday */
uint8_t gui_state; /* global running state, see guistate.c, defaults to 0 (GUI_STATE_STOP) */
uint8_t h, mt, mo, st, so; /* input: current time */
uint8_t day; /* input: 1 .. 31 current day in month */
uint8_t last_day; /* last day. This is used to check, whether the day has changed. Required for uptime calc. This is also stored in the backup register. */
uint8_t month; /* input: 1..12 */
uint8_t year_t, year_o; /* input: current year */
uint8_t weekday; /* calculated: 0 = Monday */
@ -41,7 +45,7 @@ struct _gui_data
uint8_t is_alarm; /* input/calculated: set by the software, has to be reset by the user */
uint8_t active_alarm_idx; /* input/calculated: set by the software, has to be reset by the user */
uint8_t contrast;
char s[16]; /* string buffer */
};
@ -114,6 +118,7 @@ void enable_alarm(void);
void disable_alarm(void);
void set_time(uint8_t ht, uint8_t ho, uint8_t mt, uint8_t mo, uint8_t st, uint8_t so);
void set_date(uint8_t yt, uint8_t yo, uint8_t mt, uint8_t mo, uint8_t dayt, uint8_t dayo, uint8_t weekday);
void set_contrast(uint8_t v);
#endif

View File

@ -152,6 +152,7 @@ void gui_alarm_calc_str_time(uint8_t idx)
}
/* adjust day/month and calculates the weekday */
/* this function must be called after reading from RTC or after setting the input vars by the user */
void gui_date_adjust(void)
{
uint16_t ydn;
@ -173,6 +174,12 @@ void gui_date_adjust(void)
gui_data.weekday -= 7;
//cdn = to_century_day_number(y, ydn);
//to_minutes(cdn, h, m);
if ( gui_data.day != gui_data.last_day )
{
gui_data.uptime++;
gui_data.last_day = gui_data.day;
}
}
/*
@ -291,7 +298,9 @@ void gui_LoadData(void)
{
set_alarm_data_by_u32(gui_alarm_list+i, data[i]);
}
gui_data.uptime = data[4] & (uint32_t)0x03ff;
gui_data.last_day = (data[4]>>10) & (uint32_t)31;
gui_data.contrast = (data[4]>>15) & (uint32_t)7;
}
void gui_StoreData(void)
@ -304,6 +313,10 @@ void gui_StoreData(void)
//printf("%d: %08lx\n", i, data[i]);
}
data[4] = 0;
data[4] |= gui_data.uptime & (uint32_t)0x03ff; /* 0...1023 */
data[4] |= (gui_data.last_day & (uint32_t)31)<<10;
data[4] |= (gui_data.contrast & (uint32_t)7)<<15;
store_gui_data(data);
}

View File

@ -100,3 +100,9 @@ void set_time(uint8_t ht, uint8_t ho, uint8_t mt, uint8_t mo, uint8_t st, uint8_
void set_date(uint8_t yt, uint8_t yo, uint8_t mt, uint8_t mo, uint8_t dayt, uint8_t dayo, uint8_t weekday)
{
}
/* value 1..7, 0 is default (do not set) */
void set_contrast(uint8_t v)
{
}

View File

@ -124,6 +124,7 @@ int me_action_handle_display_time(menu_t *menu, const me_t *me, uint8_t msg)
if ( msg == ME_MSG_DRAW )
{
char s[14];
u8g2_uint_t w;
#ifdef D12832
@ -133,10 +134,9 @@ int me_action_handle_display_time(menu_t *menu, const me_t *me, uint8_t msg)
if ( gui_data.next_alarm_index < GUI_ALARM_CNT )
{
u8g2_DrawXBM(menu->u8g2, 67, y-10, 12, 12, (const uint8_t *)(alarm_xbm));
u8g2_DrawXBM(menu->u8g2, 67, y-11, 12, 12, (const uint8_t *)(alarm_xbm));
gui_alarm_to_str(gui_data.next_alarm_index);
u8g2_DrawUTF8(menu->u8g2, 81, y, gui_data.s);
}
else
{
@ -163,9 +163,11 @@ int me_action_handle_display_time(menu_t *menu, const me_t *me, uint8_t msg)
if ( gui_data.next_alarm_index < GUI_ALARM_CNT )
{
u8g2_DrawXBM(menu->u8g2, x, y-10, 12, 12, (const uint8_t *)(alarm_xbm));
gui_alarm_to_str(gui_data.next_alarm_index);
u8g2_DrawUTF8(menu->u8g2, x+14, y, gui_data.s);
w = u8g2_GetUTF8Width(menu->u8g2, gui_data.s)+14;
//u8g2_DrawUTF8(menu->u8g2, x+14, y, gui_data.s);
u8g2_DrawXBM(menu->u8g2, (128-w)/2, y-11, 12, 12, (const uint8_t *)(alarm_xbm));
u8g2_DrawUTF8(menu->u8g2, (128-w)/2+14, y, gui_data.s);
}
y -= 17;
@ -181,7 +183,10 @@ int me_action_handle_display_time(menu_t *menu, const me_t *me, uint8_t msg)
s[10] = gui_data.year_t+'0';
s[11] = gui_data.year_o+'0';
s[12] = '\0';
u8g2_DrawUTF8(menu->u8g2, x, y, s);
w = u8g2_GetUTF8Width(menu->u8g2, s);
u8g2_DrawUTF8(menu->u8g2, (128-w)/2, y, s);
#endif
return 1;
@ -348,7 +353,7 @@ const me_t melist_setup_alarm[] =
{ me_cb_wd_toggle, &(gui_alarm_current.wd[5]), (void *)weekdaystr[5], ME_ALARM_WD_XO+17*5, ME_ALARM_WD_Y},
{ me_cb_wd_toggle, &(gui_alarm_current.wd[6]), (void *)weekdaystr[6], ME_ALARM_WD_XO+17*6, ME_ALARM_WD_Y},
{ me_cb_big_toggle, &(gui_alarm_current.enable), NULL, 28, 47},
{ me_cb_big_toggle, (void *)&(gui_alarm_current.enable), NULL, 28, 47},
{ me_cb_16x16_bitmap_button, (void *)me_action_alarm_done, (void *)ok_xbm, 80, 44 },
@ -534,9 +539,13 @@ int me_action_handle_boot_info(menu_t *menu, const me_t *me, uint8_t msg)
u8g2_DrawStr(menu->u8g2, 0, 24-1, "ResetReason");
u8g2_DrawStr(menu->u8g2, 64, 24-1, reset_reason_str[get_reset_reason()]);
u8g2_DrawStr(menu->u8g2, 0, 32-1, "Wakeups");
u8g2_DrawStr(menu->u8g2, 64, 32-1, u8x8_u16toa(get_wakeup_count(), 5));
u8g2_DrawStr(menu->u8g2, 0, 32-1, "Uptime");
u8g2_DrawStr(menu->u8g2, 64, 32-1, u8x8_u16toa(gui_data.uptime, 3));
u8g2_DrawStr(menu->u8g2, 0, 40-1, "Wakeups");
u8g2_DrawStr(menu->u8g2, 64, 40-1, u8x8_u16toa(get_wakeup_count(), 5));
}
else if ( msg == ME_MSG_SELECT )
@ -554,10 +563,21 @@ const me_t melist_boot_info_menu[] =
{ me_cb_null, NULL, NULL, 0, 0 },
};
/*============================================*/
/* System Menu */
const me_t melist_system_menu[] =
{
{ me_cb_label, NULL, "Helligkeit:", 0, 11},
{ me_cb_scale_1_7, &(gui_data.contrast), NULL, 64, 8},
{ me_cb_button_full_line, (void *)me_action_to_top_menu, "Speichern", 40,30 },
{ me_cb_null, NULL, NULL, 0, 0 },
};
/*============================================*/
/* System 2 Menu */
int me_action_goto_boot_info(menu_t *menu, const me_t *me, uint8_t msg)
{
if ( msg == ME_MSG_SELECT )
@ -578,7 +598,7 @@ int me_action_goto_reset(menu_t *menu, const me_t *me, uint8_t msg)
return 0;
}
const me_t melist_system_menu[] =
const me_t melist_system_2_menu[] =
{
//{ me_cb_button_half_line, (void *)me_action_setup_time, "Uhrzeit", 0,10 },
//{ me_cb_button_half_line, (void *)me_action_setup_date, "Datum", 64,10 },
@ -617,20 +637,30 @@ int me_action_goto_system(menu_t *menu, const me_t *me, uint8_t msg)
{
if ( msg == ME_MSG_SELECT )
{
//menu_SetMEList(menu, melist_reset_menu, 0);
menu_SetMEList(menu, melist_system_menu, 0);
return 1;
}
return 0;
}
int me_action_goto_system_2(menu_t *menu, const me_t *me, uint8_t msg)
{
if ( msg == ME_MSG_SELECT )
{
//menu_SetMEList(menu, melist_reset_menu, 0);
menu_SetMEList(menu, melist_system_2_menu, 0);
return 1;
}
return 0;
}
const me_t melist_setup_menu[] =
{
{ me_cb_button_half_line, (void *)me_action_setup_time, "Uhrzeit", 0,10 },
{ me_cb_button_half_line, (void *)me_action_setup_date, "Datum", 64,10 },
{ me_cb_button_half_line, (void *)NULL, "Power", 0,20 },
{ me_cb_button_half_line, (void *)me_action_goto_system, "System", 64,20 },
{ me_cb_button_half_line, (void *)me_action_goto_system, "Anzeige", 0,20 },
{ me_cb_button_half_line, (void *)me_action_goto_system_2, "System", 64,20 },
{ me_cb_button_full_line, (void *)me_action_to_top_menu, "Zurück", 40,30 },
{ me_cb_null, NULL, NULL, 0, 0 },
};

View File

@ -443,6 +443,62 @@ int me_cb_button_empty(menu_t *menu, const me_t *me, uint8_t msg)
return 0;
}
/*
Name: me_cb_scale_1_7
Val: uint8_t *
*/
int me_cb_scale_1_7(menu_t *menu, const me_t *me, uint8_t msg)
{
uint8_t val = *(uint8_t *)(me->val);
if ( val <= 0 )
val = 1;
switch(msg)
{
case ME_MSG_IS_FOCUS:
return 1;
case ME_MSG_DRAW_FOCUS:
/*
u8g2_SetFont(menu->u8g2, MENU_BIG_NUM);
menu_DrawBoxFocus(menu,
me->x+MENU_BIG_NUM_FOCUS_XO,
me->y - u8g2_GetAscent(menu->u8g2)-1,
u8g2_GetGlyphWidth(menu->u8g2, '0')+MENU_BIG_NUM_FOCUS_EXTRAX,
u8g2_GetAscent(menu->u8g2) + 2);
*/
u8g2_DrawBox(menu->u8g2, me->x-2 + (val-1)*5 , me->y-2, 5, 5);
return 1;
case ME_MSG_SELECT:
{
val++;
if ( val > 7 )
val = 0;
*(uint8_t *)(me->val) = val;
}
return 1;
case ME_MSG_DRAW:
u8g2_SetFont(menu->u8g2, MENU_BIG_NUM);
//u8g2_DrawGlyph(menu->u8g2, me->x, me->y, *(uint8_t *)(me->val) + '0');
u8g2_DrawHLine(menu->u8g2, me->x, me->y, 6*5+1);
u8g2_DrawVLine(menu->u8g2, me->x, me->y-2, 5);
//u8g2_DrawVLine(menu->u8g2, me->x+1*5, me->y-1, 3);
//u8g2_DrawVLine(menu->u8g2, me->x+2*5, me->y-1, 3);
u8g2_DrawVLine(menu->u8g2, me->x+3*5, me->y-2, 5);
//u8g2_DrawVLine(menu->u8g2, me->x+4*5, me->y-1, 3);
//u8g2_DrawVLine(menu->u8g2, me->x+5*5, me->y-1, 3);
u8g2_DrawVLine(menu->u8g2, me->x+6*5, me->y-2, 5);
u8g2_DrawFrame(menu->u8g2, me->x-3 + (val-1)*5 , me->y-3, 7, 7);
u8g2_SetDrawColor(menu->u8g2, 0);
u8g2_DrawBox(menu->u8g2, me->x-2 + (val-1)*5 , me->y-2, 5, 5);
/* draw color is set to 1 in the following function */
menu_ClearEdgePixel(menu, me->x-3 + (val-1)*5 , me->y-3, 7, 7);
return 1;
}
return 0;
}
/*
Name: me_cb_label
can not get focus

View File

@ -102,6 +102,7 @@ int me_cb_num_label(menu_t *menu, const me_t *me, uint8_t msg);
int me_cb_button_full_line(menu_t *menu, const me_t *me, uint8_t msg);
int me_cb_button_half_line(menu_t *menu, const me_t *me, uint8_t msg);
int me_cb_button_empty(menu_t *menu, const me_t *me, uint8_t msg);
int me_cb_scale_1_7(menu_t *menu, const me_t *me, uint8_t msg);
int me_cb_label(menu_t *menu, const me_t *me, uint8_t msg);
int me_cb_inv_label(menu_t *menu, const me_t *me, uint8_t msg);
int me_cb_16x16_bitmap_button(menu_t *menu, const me_t *me, uint8_t msg);