Skip to content

Commit

Permalink
Bugfix, update to 1.4
Browse files Browse the repository at this point in the history
 - [fix #3] Fixed 12h display mode displaying 00 at midnight
 - Added AM/PM text (toggleable)
  • Loading branch information
Cley Faye committed Feb 24, 2015
1 parent f33e34f commit e7a8014
Show file tree
Hide file tree
Showing 9 changed files with 190 additions and 12 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Pebble-LiveDigits0
A watchface for the Pebble smartwatch.

v1.3
v1.4

Inspiration: this reddit thread
https://www.reddit.com/r/pebble/comments/2un40u/could_someone_put_this_animation_in_a_watchface/
Expand All @@ -10,7 +10,7 @@ Digit animation concept from /u/MattBaster
Watchface by me, /u/Cley_Faye

Current features:
- Display the current time (hour/minutes) with animated digits (customizable speed/animation trigger)
- Display the current time (hour/minutes) with animated digits (customizable speed/animation trigger, toggleable am/pm display)
- Customizable layout
- Invert color (by default use black background on dark pebble, white background on light pebble)
- Customizable vibrate every hour/minute (with off-time)
Expand Down
4 changes: 2 additions & 2 deletions appinfo.json.in
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,8 @@
},
"shortName": "LiveDigits0",
"uuid": "25d9a4fb-18fd-4508-ab41-4b217ebb2161",
"versionCode": 3,
"versionLabel": "1.3",
"versionCode": 4,
"versionLabel": "1.4",
"watchapp": {
"watchface": true
}
Expand Down
6 changes: 6 additions & 0 deletions config/livedigits0.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ Do not vibrate after (hour)
select
21|0=0|1=1|2=2|3=3|4=4|5=5|6=6|7=7|8=8|9=9|10=10|11=11|12=12|13=13|14=14|15=15|16=16|17=17|18=18|19=19|20=20|21=21|22=22|23=23

General
display_daytime
Display AM/PM in 12h mode
checkbox
true

# Animation section
Anim.
skip_digits
Expand Down
1 change: 1 addition & 0 deletions config/livedigits0.header.htm
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<div>Estimated battery impact: <span id="batteryimpact">-</span></div>
<div id="batterygradient" style="background: linear-gradient(to right, white, white, white, white, red, red);">&nbsp;</div>
</div>
<span>Version: 1.4</span>
<script type="text/javascript">
$('#batteryimpact').html('Immense');
function getRadio(name) {
Expand Down
5 changes: 3 additions & 2 deletions src/js/pebble-js-app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var appVersion = 2;
var appVersion = 4;

function isNewVersion()
{
Expand All @@ -24,7 +24,8 @@ Pebble.addEventListener("showConfiguration", function() {
optString = '';
}
}
Pebble.openURL('https://cdn.rawgit.com/CleyFaye/Pebble-LiveDigits0/2a4a8b63cd6bf0a30404b54e190493849ddf2d99/html/livedigits0.htm' + optString);
var commit = 'f33e34f8a50779a801b492ef44ef67bf4a2a14ac';
Pebble.openURL('https://cdn.rawgit.com/CleyFaye/Pebble-LiveDigits0/' + commit + '/html/livedigits0.htm' + optString);
});

Pebble.addEventListener("webviewclosed", function(e) {
Expand Down
35 changes: 30 additions & 5 deletions src/mainwindow.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "widgets/datelayer.h"
#include "widgets/btlayer.h"
#include "widgets/batterylayer.h"
#include "widgets/daytimelayer.h"
#include "config.h"
#include "layout.h"

Expand All @@ -32,6 +33,8 @@ typedef struct {
BtLayer* widget_bt;
BatteryLayer* widget_battery;

DayTimeLayer* extrawidget_daytime;

/** Color invertion layer */
InverterLayer* inverter;

Expand Down Expand Up @@ -304,6 +307,14 @@ lay_components(MainWindow* window)
set_widget_visibility(info,
!layout_widgets_hidden());

// Extra widgets
info->extrawidget_daytime = daytime_layer_create();

if (info->extrawidget_daytime) {
layer_add_child(window_layer,
info->extrawidget_daytime);
}

// Must be last: the inverter, if required
if (layout_is_white_background()) {
info->inverter = inverter_layer_create(GRect(0,
Expand Down Expand Up @@ -339,6 +350,11 @@ clear_components(window_info_t* info)
WIDGETDESTROY(battery);
#undef WIDGETDESTROY

if (info->extrawidget_daytime) {
daytime_layer_destroy(info->extrawidget_daytime);
info->extrawidget_daytime = NULL;
}

if (info->inverter) {
inverter_layer_destroy(info->inverter);
info->inverter = NULL;
Expand Down Expand Up @@ -465,14 +481,18 @@ set_to_time(window_info_t* info,
struct tm* tick_time,
bool animate)
{
int hours = clock_is_24h_style()
? tick_time->tm_hour
: ((tick_time->tm_hour > 12)
? tick_time->tm_hour - 12
: tick_time->tm_hour);
int hours = tick_time->tm_hour;
int minutes = tick_time->tm_min;
int seconds = tick_time->tm_sec;

if (!clock_is_24h_style()) {
if (hours > 12) {
hours -= 12;
} else if (hours == 0) {
hours = 12;
}
}

number_layer_set_number(info->hours,
hours,
animate);
Expand All @@ -485,6 +505,11 @@ set_to_time(window_info_t* info,
tick_time);
}

if (info->extrawidget_daytime) {
daytime_layer_set_time(info->extrawidget_daytime,
tick_time);
}

schedule_animation(info);

if (seconds == 0 && can_vibrate(hours)) {
Expand Down
1 change: 0 additions & 1 deletion src/widgets/batterylayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// TYPES =
// =======


typedef Layer BatteryLayer;

// ===============================
Expand Down
112 changes: 112 additions & 0 deletions src/widgets/daytimelayer.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/** @file
* Display the am/pm text
*
* @author Cley Faye
* Licensing informations in LICENSE.md file.
*/

#include <pebble.h>

#include "config.h"
#include "layout.h"
#include "digits/digit_info.h"
#include "utils.h"

#include "daytimelayer.h"

// ===============
// PRIVATE TYPES =
// ===============

typedef struct {
TextLayer* text_layer;
char text[3];
} daytime_info_t;

// ================================
// PRIVATE FUNCTIONS DECLARATIONS =
// ================================

static inline
daytime_info_t* get_info(DayTimeLayer* layer)
{
return (daytime_info_t*) layer_get_data(layer);
}

static
void
info_init(daytime_info_t* info);

// ===============================
// PRIVATE FUNCTIONS DEFINITIONS =
// ===============================

static
void
info_init(daytime_info_t* info)
{
info->text_layer = NULL;
info->text[0] = '\0';
info->text[1] = 'M';
info->text[2] = '\0';
}

// ==============================
// PUBLIC FUNCTIONS DEFINITIONS =
// ==============================

DayTimeLayer*
daytime_layer_create(void)
{
if (!cfg_get_display_daytime() || clock_is_24h_style()) {
return NULL;
}

GRect layer_rect;
layer_rect.origin = layout_get_hour_offset();
layer_rect.origin.x += 62;
layer_rect.origin.y += 63;
layer_rect.size = GSize(24, 9);
DayTimeLayer* result =
layer_create_with_init_data(layer_rect,
sizeof(daytime_info_t),
(layer_data_init_t) info_init);
daytime_info_t* info = get_info(result);
const int text_vertical_offset = 5;
layer_rect.origin.x = 0;
layer_rect.origin.y = -text_vertical_offset;
layer_rect.size.h += text_vertical_offset;
info->text_layer = text_layer_create(layer_rect);
text_layer_set_font(info->text_layer,
fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD));
text_layer_set_text_alignment(info->text_layer,
GTextAlignmentCenter);
text_layer_set_text_color(info->text_layer,
GColorWhite);
text_layer_set_background_color(info->text_layer,
GColorClear);
layer_add_child(result,
text_layer_get_layer(info->text_layer));
return result;
}

void
daytime_layer_set_time(DayTimeLayer* layer,
struct tm* tick_time)
{
daytime_info_t* info = get_info(layer);
info->text[0] = (tick_time->tm_hour < 12)
? 'A'
: 'P';
text_layer_set_text(info->text_layer,
info->text);
}

void
daytime_layer_destroy(DayTimeLayer* layer)
{
daytime_info_t* info = get_info(layer);
text_layer_destroy(info->text_layer);
layer_destroy(layer);
}

34 changes: 34 additions & 0 deletions src/widgets/daytimelayer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/** @file
* Display a little "AM" or "TM" when required.
*
* @author Cley Faye
* Licensing informations in LICENSE.md file.
*/

#ifndef INCL_DAYTIMELAYER_H
#define INCL_DAYTIMELAYER_H

#include <pebble.h>

// =======
// TYPES =
// =======

typedef Layer DayTimeLayer;

// ===============================
// PUBLIC FUNCTIONS DECLARATIONS =
// ===============================

DayTimeLayer*
daytime_layer_create(void);

void
daytime_layer_set_time(DayTimeLayer* layer,
struct tm* tick_time);

void
daytime_layer_destroy(DayTimeLayer* layer);

#endif

0 comments on commit e7a8014

Please sign in to comment.