Reworked the compass graphics a bit and did some minor changes to the menu screen.
This commit is contained in:
parent
a636659a95
commit
eaf5473928
@ -51,14 +51,6 @@ static void cleanup_event_cb(lv_event_t * e)
|
||||
LV_LOG_USER("cleanup");
|
||||
}
|
||||
|
||||
//To delete
|
||||
/*static void timer_anim_cb(lv_timer_t *timer)
|
||||
{
|
||||
CompassScreen_t *compassScreen = timer->user_data;
|
||||
static uint16_t azimuth = 0;
|
||||
compass_screen_set_azimuth(compassScreen, azimuth++);
|
||||
}*/
|
||||
|
||||
static void create_cardinal(CompassCardinal_t *cardidanl, const char *cardinalText, lv_color_t textColor, lv_coord_t x, lv_coord_t y, lv_obj_t *parent)
|
||||
{
|
||||
cardidanl->label = lv_label_create(parent);
|
||||
@ -110,33 +102,36 @@ void compass_screen_set_azimuth(CompassScreen_t * const compassScreen, uint16_t
|
||||
|
||||
//We make sure the azimuth is in the right range ie 0 to 359
|
||||
azimuth %= 360;
|
||||
uint16_t azimuthAdjusted = 359 - azimuth;
|
||||
|
||||
uint8_t index;
|
||||
|
||||
if(azimuth >= 23 && azimuth <= 67)
|
||||
if(azimuthAdjusted >= 23 && azimuthAdjusted <= 67)
|
||||
index = 1;//NE
|
||||
else if(azimuth >= 68 && azimuth <= 112)
|
||||
else if(azimuthAdjusted >= 68 && azimuthAdjusted <= 112)
|
||||
index = 2;//E
|
||||
else if(azimuth >= 113 && azimuth <= 157)
|
||||
else if(azimuthAdjusted >= 113 && azimuthAdjusted <= 157)
|
||||
index = 3;//SE
|
||||
else if(azimuth >= 158 && azimuth <= 202)
|
||||
else if(azimuthAdjusted >= 158 && azimuthAdjusted <= 202)
|
||||
index = 4;//S
|
||||
else if(azimuth >= 203 && azimuth <= 247)
|
||||
else if(azimuthAdjusted >= 203 && azimuthAdjusted <= 247)
|
||||
index = 5;//SW
|
||||
else if(azimuth >= 248 && azimuth <= 292)
|
||||
else if(azimuthAdjusted >= 248 && azimuthAdjusted <= 292)
|
||||
index = 6;//W
|
||||
else if(azimuth >= 293 && azimuth <= 337)
|
||||
else if(azimuthAdjusted >= 293 && azimuthAdjusted <= 337)
|
||||
index = 7;//NW
|
||||
else
|
||||
index = 0;//N
|
||||
|
||||
//Update the center label
|
||||
sprintf(compassScreen->compassAzimuth.text, "%u° %s", azimuth, cardinals[index]);
|
||||
sprintf(compassScreen->compassAzimuth.text, "%u° %s", azimuthAdjusted, cardinals[index]);
|
||||
lv_label_set_text_static(compassScreen->compassAzimuth.label, compassScreen->compassAzimuth.text);
|
||||
|
||||
//Rotate each cardinal with the current azimuth
|
||||
rotate_cardinal(&compassScreen->northCardinal, azimuth);
|
||||
lv_img_set_angle(compassScreen->northMarker, azimuth*10);
|
||||
//lv_meter_set_scale_range(compassScreen->compassGraduation.meter, compassScreen->compassGraduation.scale, 0, 330, 330, azimuth-90);
|
||||
|
||||
rotate_cardinal(&compassScreen->eastCardinal, azimuth);
|
||||
rotate_cardinal(&compassScreen->southCardinal, azimuth);
|
||||
rotate_cardinal(&compassScreen->westCardinal, azimuth);
|
||||
@ -165,22 +160,32 @@ void compass_screen_create(CompassScreen_t * const compassScreen)
|
||||
compassScreen->display = lv_obj_create(NULL);
|
||||
lv_obj_set_style_bg_color(compassScreen->display, lv_color_white(), LV_PART_MAIN);
|
||||
|
||||
//Let's add some arcs
|
||||
lv_obj_t *arc = lv_arc_create(compassScreen->display);
|
||||
lv_arc_set_angles(arc, 0, 360);
|
||||
lv_obj_set_style_arc_width(arc, 2, LV_PART_INDICATOR);
|
||||
lv_obj_remove_style(arc, NULL, LV_PART_KNOB);
|
||||
lv_obj_set_style_arc_width(arc, 0, LV_PART_MAIN);
|
||||
lv_obj_clear_flag(arc, LV_OBJ_FLAG_CLICKABLE);
|
||||
|
||||
lv_obj_set_size(arc, 168, 168);
|
||||
lv_obj_center(arc);
|
||||
|
||||
arc = lv_arc_create(compassScreen->display);
|
||||
lv_arc_set_angles(arc, 0, 360);
|
||||
lv_obj_set_style_arc_width(arc, 2, LV_PART_INDICATOR);
|
||||
lv_obj_remove_style(arc, NULL, LV_PART_KNOB);
|
||||
lv_obj_set_style_arc_width(arc, 0, LV_PART_MAIN);
|
||||
lv_obj_clear_flag(arc, LV_OBJ_FLAG_CLICKABLE);
|
||||
|
||||
lv_obj_set_size(arc, 210, 210);
|
||||
lv_obj_center(arc);
|
||||
|
||||
//Marker images are created here
|
||||
lv_obj_t *compassMarker = lv_img_create(compassScreen->display);
|
||||
lv_img_set_src(compassMarker, &compass_marker);
|
||||
lv_obj_set_pos(compassMarker, 113, 0);
|
||||
|
||||
if(compassScreen->northMarker)
|
||||
{
|
||||
LV_LOG_ERROR("img should be NULL here !");
|
||||
lv_obj_del(compassScreen->northMarker);
|
||||
compassScreen->northMarker = NULL;
|
||||
}
|
||||
compassScreen->northMarker = lv_img_create(compassScreen->display);
|
||||
lv_img_set_src(compassScreen->northMarker, &compass_marker_north);
|
||||
lv_obj_set_pos(compassScreen->northMarker, 113, 20);
|
||||
lv_img_set_pivot(compassScreen->northMarker, 7, 100);
|
||||
|
||||
//Azimuth label is created here
|
||||
if(compassScreen->compassAzimuth.label)
|
||||
{
|
||||
@ -193,6 +198,35 @@ void compass_screen_create(CompassScreen_t * const compassScreen)
|
||||
lv_obj_set_style_text_font(compassScreen->compassAzimuth.label, &lv_font_montserrat_28, LV_PART_MAIN);
|
||||
lv_obj_center(compassScreen->compassAzimuth.label);
|
||||
|
||||
//Add some graduation : ( was nice but is too CPU intensive :( )
|
||||
/*if(compassScreen->compassGraduation.meter)
|
||||
{
|
||||
LV_LOG_ERROR("meter should be NULL here !");
|
||||
lv_obj_del(compassScreen->compassGraduation.meter);
|
||||
compassScreen->compassGraduation.meter = NULL;
|
||||
}
|
||||
compassScreen->compassGraduation.meter = lv_meter_create(compassScreen->display);
|
||||
lv_obj_remove_style(compassScreen->compassGraduation.meter, NULL, LV_PART_INDICATOR);
|
||||
lv_obj_remove_style(compassScreen->compassGraduation.meter, NULL, LV_PART_MAIN);
|
||||
lv_obj_set_size(compassScreen->compassGraduation.meter, 204, 204);
|
||||
lv_obj_center(compassScreen->compassGraduation.meter);
|
||||
|
||||
compassScreen->compassGraduation.scale = lv_meter_add_scale(compassScreen->compassGraduation.meter);
|
||||
lv_meter_set_scale_ticks(compassScreen->compassGraduation.meter, compassScreen->compassGraduation.scale, 12, 1, 0, lv_color_black());
|
||||
lv_meter_set_scale_major_ticks(compassScreen->compassGraduation.meter, compassScreen->compassGraduation.scale, 1, 1, 0, lv_color_black(), 11);
|
||||
lv_meter_set_scale_range(compassScreen->compassGraduation.meter, compassScreen->compassGraduation.scale, 0, 330, 330, -90);*/
|
||||
|
||||
if(compassScreen->northMarker)
|
||||
{
|
||||
LV_LOG_ERROR("img should be NULL here !");
|
||||
lv_obj_del(compassScreen->northMarker);
|
||||
compassScreen->northMarker = NULL;
|
||||
}
|
||||
compassScreen->northMarker = lv_img_create(compassScreen->display);
|
||||
lv_img_set_src(compassScreen->northMarker, &compass_marker_north);
|
||||
lv_obj_set_pos(compassScreen->northMarker, 113, 18);
|
||||
lv_img_set_pivot(compassScreen->northMarker, 7, 101);
|
||||
|
||||
//Cardinal labels are created here
|
||||
if(compassScreen->northCardinal.label)
|
||||
{
|
||||
@ -200,8 +234,7 @@ void compass_screen_create(CompassScreen_t * const compassScreen)
|
||||
lv_obj_del(compassScreen->northCardinal.label);
|
||||
compassScreen->northCardinal.label = NULL;
|
||||
}
|
||||
create_cardinal(&compassScreen->northCardinal, cardinals[0], lv_palette_main(LV_PALETTE_RED), 120, 50, compassScreen->display);
|
||||
|
||||
create_cardinal(&compassScreen->northCardinal, cardinals[0], lv_palette_main(LV_PALETTE_RED), 120, 53, compassScreen->display);
|
||||
|
||||
if(compassScreen->eastCardinal.label)
|
||||
{
|
||||
@ -209,7 +242,7 @@ void compass_screen_create(CompassScreen_t * const compassScreen)
|
||||
lv_obj_del(compassScreen->eastCardinal.label);
|
||||
compassScreen->eastCardinal.label = NULL;
|
||||
}
|
||||
create_cardinal(&compassScreen->eastCardinal, cardinals[2], lv_color_black(), 190, 120, compassScreen->display);
|
||||
create_cardinal(&compassScreen->eastCardinal, cardinals[2], lv_color_black(), 187, 120, compassScreen->display);
|
||||
|
||||
if(compassScreen->southCardinal.label)
|
||||
{
|
||||
@ -217,7 +250,7 @@ void compass_screen_create(CompassScreen_t * const compassScreen)
|
||||
lv_obj_del(compassScreen->southCardinal.label);
|
||||
compassScreen->southCardinal.label = NULL;
|
||||
}
|
||||
create_cardinal(&compassScreen->southCardinal, cardinals[4], lv_color_black(), 120, 190, compassScreen->display);
|
||||
create_cardinal(&compassScreen->southCardinal, cardinals[4], lv_color_black(), 120, 187, compassScreen->display);
|
||||
|
||||
if(compassScreen->westCardinal.label)
|
||||
{
|
||||
@ -225,15 +258,12 @@ void compass_screen_create(CompassScreen_t * const compassScreen)
|
||||
lv_obj_del(compassScreen->westCardinal.label);
|
||||
compassScreen->westCardinal.label = NULL;
|
||||
}
|
||||
create_cardinal(&compassScreen->westCardinal, cardinals[6], lv_color_black(), 50, 120, compassScreen->display);
|
||||
create_cardinal(&compassScreen->westCardinal, cardinals[6], lv_color_black(), 53, 120, compassScreen->display);
|
||||
|
||||
//We register the event callback to handle gestures
|
||||
lv_obj_add_event_cb(compassScreen->display, &(gesture_event_cb), LV_EVENT_GESTURE, compassScreen);
|
||||
//We register the event callback to handle the cleanup
|
||||
lv_obj_add_event_cb(compassScreen->display, &(cleanup_event_cb), LV_EVENT_DELETE, compassScreen);
|
||||
|
||||
//To delete
|
||||
//lv_timer_create(&(timer_anim_cb), 2, compassScreen);
|
||||
}
|
||||
|
||||
void compass_screen_destroy(CompassScreen_t * const compassScreen)
|
||||
@ -244,11 +274,13 @@ void compass_screen_destroy(CompassScreen_t * const compassScreen)
|
||||
return;
|
||||
}
|
||||
|
||||
compassScreen->display = NULL;
|
||||
compassScreen->compassAzimuth.label = NULL;
|
||||
compassScreen->northCardinal.label = NULL;
|
||||
compassScreen->eastCardinal.label = NULL;
|
||||
compassScreen->southCardinal.label = NULL;
|
||||
compassScreen->westCardinal.label = NULL;
|
||||
compassScreen->northMarker = NULL;
|
||||
compassScreen->display = NULL;
|
||||
compassScreen->compassAzimuth.label = NULL;
|
||||
compassScreen->northCardinal.label = NULL;
|
||||
compassScreen->eastCardinal.label = NULL;
|
||||
compassScreen->southCardinal.label = NULL;
|
||||
compassScreen->westCardinal.label = NULL;
|
||||
compassScreen->northMarker = NULL;
|
||||
//compassScreen->compassGraduation.meter = NULL;
|
||||
//compassScreen->compassGraduation.scale = NULL;
|
||||
}
|
||||
|
@ -16,6 +16,12 @@ typedef struct CompassCardinal
|
||||
lv_point_t offset;
|
||||
} CompassCardinal_t;
|
||||
|
||||
typedef struct CompassGraduation
|
||||
{
|
||||
lv_obj_t *meter;
|
||||
lv_meter_scale_t *scale;
|
||||
} CompassGraduation_t;
|
||||
|
||||
/* Compass screen context object */
|
||||
typedef struct CompassScreen
|
||||
{
|
||||
@ -24,6 +30,8 @@ typedef struct CompassScreen
|
||||
CompassCardinal_t southCardinal;
|
||||
CompassCardinal_t westCardinal;
|
||||
|
||||
//CompassGraduation_t compassGraduation;
|
||||
|
||||
lv_obj_t *northMarker;
|
||||
lv_obj_t *display;
|
||||
|
||||
|
@ -61,6 +61,11 @@ WatchFace_t watchFace;
|
||||
MenuScreen_t menuScreen;
|
||||
CompassScreen_t compassScreen;
|
||||
|
||||
static uint16_t angle_with_offset(uint16_t angle, uint16_t offset)
|
||||
{
|
||||
return (angle + offset) >= 360 ? angle + offset - 360 : angle + offset;
|
||||
}
|
||||
|
||||
|
||||
void gfx_task(void *param)
|
||||
{
|
||||
@ -124,8 +129,9 @@ void gfx_task(void *param)
|
||||
|
||||
uint8_t aliveCounter = 0;
|
||||
|
||||
QMC5883L_MData_calibrated_t temp;
|
||||
uint8_t average = 0;
|
||||
//QMC5883L_MData_calibrated_t temp;
|
||||
//uint8_t average = 0;
|
||||
//uint16_t angle;
|
||||
|
||||
if(!QMC5883L_init())
|
||||
APP_LOG_INFO("Failed to init QMC5883L");
|
||||
@ -142,7 +148,7 @@ void gfx_task(void *param)
|
||||
else
|
||||
APP_LOG_INFO("QMC5883L configured");
|
||||
|
||||
QMC5883L_set_calibration_data(-900, 2500, -1400, 1400, 2300, 7500);
|
||||
QMC5883L_set_calibration_data(-900, 2500, -1400, 1400, 2300, 7500, 0.0);
|
||||
|
||||
for(;;)
|
||||
{
|
||||
@ -156,7 +162,7 @@ void gfx_task(void *param)
|
||||
|
||||
QMC5883L_MData_calibrated_t MData = QMC5883L_get_MFields_calibrated();
|
||||
|
||||
if(average++ == 0)
|
||||
/*if(average++ == 0)
|
||||
{
|
||||
temp.MFieldX = MData.MFieldX;
|
||||
temp.MFieldY = MData.MFieldY;
|
||||
@ -165,19 +171,20 @@ void gfx_task(void *param)
|
||||
else
|
||||
{
|
||||
temp.MFieldX += MData.MFieldX;
|
||||
temp.MFieldX /= 2;
|
||||
temp.MFieldX >>= 1;
|
||||
temp.MFieldY += MData.MFieldY;
|
||||
temp.MFieldY /= 2;
|
||||
temp.MFieldY >>= 1;
|
||||
temp.MFieldZ += MData.MFieldZ;
|
||||
temp.MFieldZ /= 2;
|
||||
}
|
||||
temp.MFieldZ >>= 1;
|
||||
}*/
|
||||
|
||||
if(average == 1)
|
||||
/*if(average == 1)
|
||||
{
|
||||
average = 0;
|
||||
int16_t angle = QMC5883L_get_azimuth(temp);
|
||||
compass_screen_set_azimuth(&compassScreen, angle-180);
|
||||
}
|
||||
angle = angle_with_offset(QMC5883L_get_azimuth(MData), 180);
|
||||
compass_screen_set_azimuth(&compassScreen, angle);
|
||||
}*/
|
||||
compass_screen_set_azimuth(&compassScreen, angle_with_offset(QMC5883L_get_azimuth(MData), 180));
|
||||
}
|
||||
|
||||
if(++aliveCounter % 200 == 0)
|
||||
@ -185,6 +192,5 @@ void gfx_task(void *param)
|
||||
APP_LOG_DEBUG("GFX thread");
|
||||
aliveCounter = 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -17,14 +17,14 @@ static void menu_item_cb(lv_event_t *e)
|
||||
{
|
||||
extern WatchFace_t watchFace;
|
||||
watch_face_create(&watchFace);
|
||||
lv_scr_load_anim(watchFace.display, LV_SCR_LOAD_ANIM_FADE_ON, 400, 0, true);
|
||||
lv_scr_load_anim(watchFace.display, LV_SCR_LOAD_ANIM_MOVE_LEFT, 400, 0, true);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
{
|
||||
extern CompassScreen_t compassScreen;
|
||||
compass_screen_create(&compassScreen);
|
||||
lv_scr_load_anim(compassScreen.display, LV_SCR_LOAD_ANIM_FADE_ON, 400, 0, true);
|
||||
lv_scr_load_anim(compassScreen.display, LV_SCR_LOAD_ANIM_MOVE_LEFT, 400, 0, true);
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
|
Loading…
Reference in New Issue
Block a user