More callbacks, further GUI work
This commit is contained in:
parent
d1e0ca32db
commit
44f70f5275
9 changed files with 699 additions and 91 deletions
96
mw_utility.c
96
mw_utility.c
|
@ -21,11 +21,15 @@
|
|||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "mw_utility.h"
|
||||
#include "metawatch.h"
|
||||
#include "mw_utility.h"
|
||||
|
||||
#include "fonts.h"
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* Generic drawing functions
|
||||
* ---------------------------------------------------------------------- */
|
||||
|
||||
/*
|
||||
* The pixmap buffer has at least one byte per pixel, even for monochrome (bpp=1)
|
||||
* bitmaps
|
||||
|
@ -252,3 +256,93 @@ void mw_buf_draw_line_bresenham(mw_buffer *mwbuf, unsigned int xstart, unsigned
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* Complex combined functions, for user convenience
|
||||
* ---------------------------------------------------------------------- */
|
||||
|
||||
/*
|
||||
* send a text notification, automatically take care of device type (ana/digi)
|
||||
* char *title is displayed inverse in top line
|
||||
* char *text is the notification text
|
||||
* vibrate is the number of 300ms vibrations, 0 for none
|
||||
*/
|
||||
void mw_do_notification(mwdevice_t *mwdevice, char *title, char *text, unsigned char vibrate)
|
||||
{
|
||||
mw_buffer *mwbuf;
|
||||
unsigned char *bbuf;
|
||||
int len,i,c,r;
|
||||
char sstr[32];
|
||||
|
||||
// fprintf(stderr, "do_notify devtype=%d, title='%s', text='%s', vibrate=%d\n", mwdevice->devtype, title, text, vibrate);
|
||||
if (mwdevice->devtype == MW_DEVICE_TYPE_DIGITAL || mwdevice->devtype == MW_DEVICE_TYPE_DEVB_DIGI) {
|
||||
mwbuf = mw_alloc_pbuffer(96, 96, 1);
|
||||
mw_buf_clear(mwbuf, MW_BLACK);
|
||||
|
||||
mw_buf_print(mwbuf, 0, 0, title, 0, MW_BLACK, MW_WHITE);
|
||||
|
||||
i=0;
|
||||
c=0; r=1;
|
||||
memset(sstr,0,32);
|
||||
while (i<strlen(text)) {
|
||||
sstr[c++] = text[i++];
|
||||
if (c>=16 || i>=strlen(text)) {
|
||||
mw_buf_print(mwbuf, 0, r*9, sstr, 0, MW_WHITE, MW_BLACK);
|
||||
memset(sstr,0,32);
|
||||
c=0; r++;
|
||||
if (r>10)
|
||||
break;
|
||||
};
|
||||
};
|
||||
|
||||
bbuf = mw_make_mw_buffer(mwbuf, &len);
|
||||
mw_send_bitmap(mwdevice, MW_SCREEN_MODE_NOTIFICATION, 96, 96, 0, bbuf, len);
|
||||
mw_update_display(mwdevice, MW_SCREEN_MODE_NOTIFICATION, 1);
|
||||
mw_free_pbuffer(mwbuf);
|
||||
} else if (mwdevice->devtype == MW_DEVICE_TYPE_ANA_DIGI || mwdevice->devtype == MW_DEVICE_TYPE_DEVB_ANA_DIGI) {
|
||||
fprintf(stderr, "do notify OLED\n");
|
||||
mwbuf = mw_alloc_pbuffer(80, 16, 1);
|
||||
mw_buf_clear(mwbuf, MW_BLACK);
|
||||
|
||||
mw_buf_print(mwbuf, 0, 0, title, 0, MW_BLACK, MW_WHITE);
|
||||
|
||||
i=0;
|
||||
c=0; r=1;
|
||||
memset(sstr,0,32);
|
||||
while (i<strlen(text) && r<2) {
|
||||
sstr[c++] = text[i++];
|
||||
if (c>=13 || i>=strlen(text)) {
|
||||
mw_buf_print(mwbuf, 0, r*9, sstr, 0, MW_WHITE, MW_BLACK);
|
||||
memset(sstr,0,32);
|
||||
c=0; r++;
|
||||
};
|
||||
};
|
||||
|
||||
bbuf = mw_make_mw_oled_buffer(mwbuf, &len);
|
||||
mw_write_oled_buffer(mwdevice, 0, MW_OLED_UPPER, 80, 0, bbuf, len);
|
||||
|
||||
mw_buf_clear(mwbuf, MW_BLACK);
|
||||
c=0; r=0;
|
||||
memset(sstr,0,32);
|
||||
while (i<strlen(text) && r<2) {
|
||||
sstr[c++] = text[i++];
|
||||
if (c>=13 || i>=strlen(text)) {
|
||||
mw_buf_print(mwbuf, 0, r*9, sstr, 0, MW_WHITE, MW_BLACK);
|
||||
memset(sstr,0,32);
|
||||
c=0; r++;
|
||||
if (r>2)
|
||||
break;
|
||||
};
|
||||
};
|
||||
|
||||
bbuf = mw_make_mw_oled_buffer(mwbuf, &len);
|
||||
mw_write_oled_buffer(mwdevice, 0, MW_OLED_LOWER, 80, 0, bbuf, len);
|
||||
|
||||
mw_free_pbuffer(mwbuf);
|
||||
} else
|
||||
fprintf(stderr, "Watch type not set - forgot to call mw_init()?\n");
|
||||
|
||||
if (vibrate)
|
||||
mw_set_vibrate_mode(mwdevice, 1, 300, 300, vibrate);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue