Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lilygo face #17

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## A TTGO-T-Watch-2020 Arduino sketch

<img src="https://github.com/AlexGoodyear/agoodWatch/blob/master/images/agoodWatchV02.jpg" width="300" /> <img src="https://github.com/AlexGoodyear/agoodWatch/blob/master/images/agoodWatchV06.jpg" width="250" />
<img src="images/agoodWatchV02.jpg" width="300" /> <img src="images/agoodWatchV06.jpg" width="250" /> <img src="images/LilyGoFace.jpg" width="250" />

### Installation.
First ensure that you have installed the [TTGO_TWatch_Library](https://github.com/AlexGoodyear/TTGO_TWatch_Library) into your Arduino/libraries directory. Next put the agoodWatch directory from this repository into your Arduino sketch area.
Expand Down Expand Up @@ -31,7 +31,7 @@ To get to the WiFi and About menus you must start from the left most watch face

This is a "map" of the current screens ...
```
[Face 1]---[Face 2]
[Face 1]---[Face 2]--[Face 3]
|
|
[Wifi icon]---[Wifi config] <-- the WiFi list and keyboard password entry
Expand Down
6 changes: 6 additions & 0 deletions agoodWatch/agoodWatch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef A_GOOD_WATCH_H
#define A_GOOD_WATCH_H

extern char buff[512];

#endif /* A_GOOD_WATCH_H */
2 changes: 2 additions & 0 deletions agoodWatch/agoodWatch.ino
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Created by Lewis he on October 10, 2019.
#include "esp_wifi.h"
#include <WiFi.h>
#include "gui.h"
#include "agoodWatch.h"

#define G_EVENT_VBUS_PLUGIN _BV(0)
#define G_EVENT_VBUS_REMOVE _BV(1)
Expand Down Expand Up @@ -54,6 +55,7 @@ EventGroupHandle_t isr_group = NULL;
bool lenergy = false;
TTGOClass *ttgo;
lv_icon_battery_t batState = LV_ICON_CALCULATION;
char buff[512];

unsigned int defaultCpuFrequency = CPU_FREQ_NORM;
unsigned int defaultScreenTimeout = DEFAULT_SCREEN_TIMEOUT;
Expand Down
209 changes: 6 additions & 203 deletions agoodWatch/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,13 @@ Created by Lewis he on October 10, 2019.
#include "string.h"
#include <Ticker.h>

#include "homerFace.h"
#include "lilygoFace.h"

LV_FONT_DECLARE(Ubuntu);

LV_IMG_DECLARE(bg2);
LV_IMG_DECLARE(foot_16px);
LV_IMG_DECLARE(homerFace);
LV_IMG_DECLARE(hourHand);
LV_IMG_DECLARE(minHand);
LV_IMG_DECLARE(secHand);
LV_IMG_DECLARE(eye);

LV_IMG_DECLARE(wifi);
LV_IMG_DECLARE(on);
LV_IMG_DECLARE(off);
Expand All @@ -49,12 +46,10 @@ static lv_obj_t *torchLabel = nullptr;

static uint8_t globalIndex = 0;

static void lv_update_task(struct _lv_task_t *);
static void lv_battery_task(struct _lv_task_t *);

static int createOriginalFace (int);
static int updateOriginalFace (int);
static int createHomerFace (int);
static int createWiFi (int);
static int createWiFiSwitches (int);
static int createAbout (int);
Expand Down Expand Up @@ -279,7 +274,7 @@ class StatusBar

StatusBar bar;

TileDesc_t tileDesc[] = {{0, createOriginalFace}, {1, createHomerFace},
TileDesc_t tileDesc[] = {{0, createOriginalFace}, {1, createHomerFace}, {2, createLilygoFace},
{0, createWiFi}, {1, createWiFiSwitches},
{0, createAbout}, {1, createAboutInfo}};

Expand Down Expand Up @@ -357,7 +352,7 @@ static void tileViewEvent_cb (lv_obj_t * obj, lv_event_t event)
}
}

static void watchFaceEvent_cb (lv_obj_t * obj, lv_event_t event)
void watchFaceEvent_cb (lv_obj_t * obj, lv_event_t event)
{
log_d ("obj=%p, event=%d: %s", obj, event, decodeEvent (event));

Expand Down Expand Up @@ -698,7 +693,7 @@ void updateBatteryIcon(lv_icon_battery_t icon)
}


static void lv_update_task(struct _lv_task_t *data)
void lv_update_task(struct _lv_task_t *data)
{
log_d ("update %d", (int)(data->user_data));

Expand All @@ -710,198 +705,6 @@ static void lv_battery_task(struct _lv_task_t *data)
updateBatteryLevel();
}

typedef struct
{
lv_task_t *timeTask;
lv_obj_t *hourHand;
lv_obj_t *minHand;
lv_obj_t *secHand;
lv_obj_t *hourShadow;
lv_obj_t *minShadow;
lv_obj_t *secShadow;
lv_obj_t *leftEye;
lv_obj_t *rightEye;
} HomerFaceData_t;

static int updateHomerFace (int idx)
{
time_t now;
struct tm info;
HomerFaceData_t *hfd = (HomerFaceData_t *)(tileDesc[idx].data);
static int lastMin = 61;

log_d ("idx=%d", idx);

time (&now);
localtime_r (&now, &info);

int sec = 60 * info.tm_sec;

lv_img_set_angle (hfd->leftEye, sec);
lv_img_set_angle (hfd->rightEye, sec);

if (info.tm_min != lastMin)
{
lastMin = info.tm_min;

int hour = (300 * (info.tm_hour % 12)) + (5 * lastMin);
int min = 60 * lastMin;

lv_img_set_angle (hfd->minShadow, min);
lv_img_set_angle (hfd->minHand, min);

lv_img_set_angle (hfd->hourShadow, hour);
lv_img_set_angle (hfd->hourHand, hour);
}

lv_img_set_angle (hfd->secShadow, sec);
lv_img_set_angle (hfd->secHand, sec);
}

static int onEntryHomerFace (int idx)
{
HomerFaceData_t *hfd = (HomerFaceData_t *)(tileDesc[idx].data);

log_d ("idx=%d", idx);

screenTimeout = defaultScreenTimeout = DEFAULT_SCREEN_TIMEOUT * 5;
defaultCpuFrequency = CPU_FREQ_MAX;
setCpuFrequencyMhz (defaultCpuFrequency);

if (hfd->timeTask == nullptr)
{
hfd->timeTask = lv_task_create (lv_update_task, 1000, LV_TASK_PRIO_LOWEST, (void *)idx);
}
}

static int onExitHomerFace (int idx)
{
HomerFaceData_t *hfd = (HomerFaceData_t *)(tileDesc[idx].data);

log_d ("idx=%d", idx);

if (hfd->timeTask != nullptr)
{
lv_task_del (hfd->timeTask);
hfd->timeTask = nullptr;
}

screenTimeout = defaultScreenTimeout = DEFAULT_SCREEN_TIMEOUT;
defaultCpuFrequency = CPU_FREQ_NORM;
}

static int createHomerFace (int idx)
{
lv_obj_t *parentObj = tileDesc[idx].tile;
lv_obj_t *canvas = lv_canvas_create (parentObj, NULL);
lv_color_t *cbuf = (lv_color_t *)ps_malloc(LV_CANVAS_BUF_SIZE_TRUE_COLOR_ALPHA(240, 240) * sizeof (lv_color_t));

memcpy (cbuf, homerFace.data, homerFace.data_size);

lv_canvas_set_buffer (canvas, cbuf, 240, 240, LV_IMG_CF_TRUE_COLOR_ALPHA);

lv_draw_line_dsc_t ticks;
lv_draw_line_dsc_init (&ticks);
ticks.opa = LV_OPA_100;
ticks.color = LV_COLOR_WHITE;

lv_point_t line[2];

for (int i = 0; i < 60; i++)
{
int bot;
float sx = cos(((i * 6) - 90) * 0.0174532925);
float sy = sin(((i * 6) - 90) * 0.0174532925);

line[0].x = sx * 117 + 120;
line[0].y = sy * 117 + 120;

if ((i % 15) == 0)
{
bot = 97;
ticks.width = 6;
}
else if ((i % 5) == 0)
{
bot = 107;
ticks.width = 4;
}
else
{
bot = 112;
ticks.width = 2;
}

line[1].x = sx * bot + 120;
line[1].y = sy * bot + 120;

lv_canvas_draw_line (canvas, line, 2, &ticks);
}

lv_obj_align (canvas, parentObj, LV_ALIGN_CENTER, 0, 0);

lv_obj_set_event_cb (parentObj, watchFaceEvent_cb);

tileDesc[idx].onEntry = onEntryHomerFace;
tileDesc[idx].onExit = onExitHomerFace;
tileDesc[idx].onUpdate = updateHomerFace;

tileDesc[idx].data = malloc (sizeof (HomerFaceData_t));

HomerFaceData_t *hfd = (HomerFaceData_t *)(tileDesc[idx].data);

hfd->leftEye = lv_img_create (parentObj, NULL);
hfd->rightEye = lv_img_create (parentObj, NULL);

hfd->minShadow = lv_img_create (parentObj, NULL);
hfd->minHand = lv_img_create (parentObj, NULL);

hfd->hourShadow = lv_img_create (parentObj, NULL);
hfd->hourHand = lv_img_create (parentObj, NULL);

hfd->secShadow = lv_img_create (parentObj, NULL);
hfd->secHand = lv_img_create (parentObj, NULL);

lv_img_set_src (hfd->leftEye, &eye);
lv_img_set_src (hfd->rightEye, &eye);

lv_img_set_src (hfd->hourShadow, &hourHand); lv_img_set_pivot (hfd->hourShadow, 7, 77);
lv_img_set_src (hfd->minShadow, &minHand); lv_img_set_pivot (hfd->minShadow, 7, 105);
lv_img_set_src (hfd->secShadow, &secHand); lv_img_set_pivot (hfd->secShadow, 22, 90);

lv_img_set_src (hfd->hourHand, &hourHand); lv_img_set_pivot (hfd->hourHand, 7, 77);
lv_img_set_src (hfd->minHand, &minHand); lv_img_set_pivot (hfd->minHand, 7, 105);
lv_img_set_src (hfd->secHand, &secHand); lv_img_set_pivot (hfd->secHand, 22, 90);

lv_obj_align (hfd->leftEye, parentObj, LV_ALIGN_CENTER, -30, -28);
lv_obj_align (hfd->rightEye, parentObj, LV_ALIGN_CENTER, 30, -28);

lv_obj_align (hfd->hourShadow, parentObj, LV_ALIGN_CENTER, 0, -32);
lv_obj_align (hfd->minShadow, parentObj, LV_ALIGN_CENTER, 0, -41);
lv_obj_align (hfd->secShadow, parentObj, LV_ALIGN_CENTER, 3, -15);

lv_obj_align (hfd->hourHand, parentObj, LV_ALIGN_CENTER, 1, -40);
lv_obj_align (hfd->minHand, parentObj, LV_ALIGN_CENTER, 1, -49);
lv_obj_align (hfd->secHand, parentObj, LV_ALIGN_CENTER, 4, -26);

static lv_style_t shadowStyle;

lv_style_init (&shadowStyle);
lv_style_set_radius (&shadowStyle, LV_OBJ_PART_MAIN, 0);
lv_style_set_image_recolor (&shadowStyle, LV_STATE_DEFAULT, LV_COLOR_BLACK);
lv_style_set_image_recolor_opa (&shadowStyle, LV_STATE_DEFAULT, LV_OPA_100);
lv_style_set_image_opa (&shadowStyle, LV_STATE_DEFAULT, 63); // LV_OPA_25ish!
lv_style_set_border_width (&shadowStyle, LV_OBJ_PART_MAIN, 0);

lv_obj_add_style (hfd->hourShadow, LV_IMG_PART_MAIN, &shadowStyle);
lv_obj_add_style (hfd->minShadow, LV_IMG_PART_MAIN, &shadowStyle);
lv_obj_add_style (hfd->secShadow, LV_IMG_PART_MAIN, &shadowStyle);

hfd->timeTask = nullptr;

updateHomerFace (idx);
}

/*****************************************************************
*
* ! Keyboard Class
Expand Down
6 changes: 6 additions & 0 deletions agoodWatch/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ typedef struct
void *data;
} TileDesc_t;

extern TileDesc_t tileDesc[];

void setupGui();
void updateStepCounter(uint32_t counter);
void updateBatteryIcon(lv_icon_battery_t index);
Expand All @@ -83,10 +85,14 @@ void updateTime();
void torchOn();
void torchOff();

void watchFaceEvent_cb (lv_obj_t * obj, lv_event_t event);

extern unsigned int screenTimeout;
extern unsigned int defaultScreenTimeout;
extern unsigned int defaultCpuFrequency;

void lv_update_task(struct _lv_task_t *data);

extern "C" {
extern void lv_keyboard_def_event_cb(lv_obj_t * kb, lv_event_t event);
}
Expand Down
Loading