Skip to content

Instantly share code, notes, and snippets.

@matmar10
Last active October 25, 2015 22:22
Show Gist options
  • Save matmar10/e74d164588d45072a3b8 to your computer and use it in GitHub Desktop.
Save matmar10/e74d164588d45072a3b8 to your computer and use it in GitHub Desktop.
#include <pebble.h>
#include <PDUtils.h>
#define KEY_DATE_YEAR 0
#define KEY_DATE_MONTH 1
#define KEY_DATE_DAY 2
#define KEY_FAJR_HOUR 3
#define KEY_FAJR_MINUTE 4
#define KEY_SHUROOQ_HOUR 5
#define KEY_SHUROOQ_MINUTE 6
#define KEY_DHUHR_HOUR 7
#define KEY_DHUHR_MINUTE 8
#define KEY_ASR_HOUR 9
#define KEY_ASR_MINUTE 10
#define KEY_MAGHRIB_HOUR 11
#define KEY_MAGHRIB_MINUTE 12
#define KEY_ISHA_HOUR 13
#define KEY_ISHA_MINUTE 14
static Window *s_main_window;
static TextLayer *s_time_layer;
static TextLayer *s_day_layer;
static TextLayer *s_date_layer;
static TextLayer *s_time_till_next_prayer_layer;
static struct tm *s_fajr;
static struct tm *s_shurooq;
static struct tm *s_dhuhr;
static struct tm *s_asr;
static struct tm *s_maghrib;
static struct tm *s_isha;
static bool s_has_prayer_times = 0;
static void build_prayer_time_next(struct tm *prayer_time, int year, int month, int day, DictionaryIterator *iterator) {
// initialize to current time and modify
time_t temp = time(NULL);
prayer_time = localtime(&temp);
Tuple *prayer_time_hour_tuple = dict_read_next(iterator);
Tuple *prayer_time_minute_tuple = dict_read_next(iterator);
prayer_time->tm_year = year;
prayer_time->tm_mon = month;
prayer_time->tm_mday = day;
prayer_time->tm_hour = (int)prayer_time_hour_tuple->value->int32;
prayer_time->tm_min = (int)prayer_time_minute_tuple->value->int32;
prayer_time->tm_sec = 0;
}
static void inbox_received_callback(DictionaryIterator *iterator, void *context) {
APP_LOG(APP_LOG_LEVEL_INFO, "Received info from JS...!");
// date components
Tuple *date_year_tuple = dict_read_next(iterator);
Tuple *date_month_tuple = dict_read_next(iterator);
Tuple *date_day_tuple = dict_read_next(iterator);
int year = (int)date_year_tuple->value->int32;
int month = (int)date_month_tuple->value->int32;
int day = (int)date_day_tuple->value->int32;
/*
time_t temp = time(NULL);
s_fajr = localtime(&temp);
Tuple *prayer_time_hour_tuple = dict_find(iterator, KEY_FAJR_HOUR);
Tuple *prayer_time_minute_tuple = dict_find(iterator, KEY_FAJR_MINUTE);
s_fajr->tm_year = year;
s_fajr->tm_mon = month;
s_fajr->tm_mday = day;
s_fajr->tm_hour = (int)prayer_time_hour_tuple->value->int32;
s_fajr->tm_min = (int)prayer_time_minute_tuple->value->int32;
s_fajr->tm_sec = 0;
*/
// fajr
build_prayer_time_next(s_fajr, year, month, day, iterator);
char str_fajr[32];
strftime(str_fajr, sizeof(str_fajr), "fajr: %F %H:%M", s_fajr);
APP_LOG(APP_LOG_LEVEL_DEBUG, str_fajr);
// shurooq
build_prayer_time_next(s_shurooq, year, month, day, iterator);
char str_shurooq[32];
strftime(str_shurooq, sizeof(str_shurooq), "shurooq: %F %H:%M", s_shurooq);
APP_LOG(APP_LOG_LEVEL_DEBUG, str_shurooq);
// dhuhr
build_prayer_time_next(s_dhuhr, year, month, day, iterator);
char str_dhuhr[32];
strftime(str_dhuhr, sizeof(str_dhuhr), "dhuhr: %F %H:%M", s_dhuhr);
APP_LOG(APP_LOG_LEVEL_DEBUG, str_dhuhr);
// asr
build_prayer_time_next(s_asr, year, month, day, iterator);
char str_asr[32];
strftime(str_asr, sizeof(str_asr), "asr: %F %H:%M", s_asr);
APP_LOG(APP_LOG_LEVEL_DEBUG, str_asr);
// maghrib
build_prayer_time_next(s_maghrib, year, month, day, iterator);
char str_maghrib[32];
strftime(str_maghrib, sizeof(str_maghrib), "maghrib: %F %H:%M", s_maghrib);
APP_LOG(APP_LOG_LEVEL_DEBUG, str_maghrib);
// isha
build_prayer_time_next(s_isha, year, month, day, iterator);
char str_isha[32];
strftime(str_isha, sizeof(str_isha), "isha: %F %H:%M", s_isha);
APP_LOG(APP_LOG_LEVEL_DEBUG, str_isha);
s_has_prayer_times = 1;
update_prayer_times();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment