/**************************************************************** * Private Functionalities **/ private async Task <bool> OnCreate(string p_dbPath, string p_dbName) { KreyosUtils.Log("DatabaseManager::OnCreate", "creating db at path:" + p_dbPath); try { bool dbExisted = this.CheckFileExists(p_dbName).Result; KreyosUtils.Log("DatabaseManager::OnCreate", "db:" + p_dbName + " exists? " + dbExisted); if (!dbExisted) { KreyosUtils.Log("DatabaseManager::OnCreate", "a.."); using (m_dbConnection = new SQLiteConnection(p_dbPath)) { KreyosUtils.Log("DatabaseManager::OnCreate", "b.."); m_dbConnection.CreateTable <Kreyos_User_Activities>(); KreyosUtils.Log("DatabaseManager::OnCreate", "New db.."); } } else { KreyosUtils.Log("DatabaseManager::OnCreate", "Existing db.."); } return(true); } catch (FileNotFoundException e) { KreyosUtils.Log("DatabaseManager::OnCreate", "No db.. name:" + e.FileName + " error:" + e.Message + " " + e.StackTrace); return(false); } }
/// <summary> /// Connection with the watch is disconnected. /// </summary> private void OnDeviceDisconnected(string p_error) { KreyosUtils.Log("BluetoothTest::OnDeviceDisconnected", "message:" + p_error); this.ClearDevices(); this.UpdateDevices(); BluetoothManager.Instance.GetKreyosDevices(); }
public void SyncWatch() { if (!IsConnected) { return; } DeviceConfiguration config = DeviceConfigManager.Instance.GetDeviceConfig(); BluetoothAgent.Instance.InnerProtocol.syncWatchConfig(config.WorldClockTable, config.WorldClockOffset, config.IsDigitalClock, config.DigitalClock, config.AnalogClock, config.SportsGridType, config.SportsGridValues, config.Goals, config.Weight, config.Height, config.IsEnableGesture, config.IsLeftHandGesture, config.Actionstable, config.IsUkUnit); KreyosUtils.Log("Protocol", "Sync Watch"); }
/// <summary> /// LongListSelected Event that is triggered when an Item is selected /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnDeviceSelected(object sender, System.Windows.Controls.SelectionChangedEventArgs e) { if (e.AddedItems.Count <= 0) { return; } DeviceData selectedDevice = (DeviceData)e.AddedItems[0]; // check if device is already connected and it was the selected. disconnect the device if (selectedDevice.DeviceStatus == EDevice.Status_Connected) { // disconnect the device selectedDevice.UpdateStatus(EDevice.Status_Disconnected); BluetoothManager.Instance.DisconnectKreyosDevice(); return; } // check if the app is currently connected to a watch if (BluetoothManager.Instance.IsConnected) { // disconnect the device BluetoothManager.Instance.DisconnectKreyosDevice(); } selectedDevice.UpdateStatus(EDevice.Status_Connecting); // update device list this.UpdateDevices(); KreyosUtils.Log("BluetoothTest::OnDeviceSelected", "cellData:" + selectedDevice); // Connected to Watch BluetoothManager.Instance.ConnectKreyosDevice(selectedDevice.Name); }
/**************************************************************** * Helpers **/ public static List <ActivityStatsHeader <ActivityStatsData> > ListFrom(List <ActivityStatsData> p_activities) { List <ActivityStatsHeader <ActivityStatsData> > list = new List <ActivityStatsHeader <ActivityStatsData> >(); // string = (DAY OF WEEK)_(DATE) | ActivityStatsHeader::DateString Dictionary <string, ActivityStatsHeader <ActivityStatsData> > mapData = new Dictionary <string, ActivityStatsHeader <ActivityStatsData> >(); foreach (ActivityStatsData cellData in p_activities) { DateTime epoch = KreyosUtils.ToDateTime((long)cellData.EpochTime); string dateKey = KreyosUtils.DateString(epoch); if (!mapData.ContainsKey(dateKey)) { ActivityStatsHeader <ActivityStatsData> headerData = new ActivityStatsHeader <ActivityStatsData>((uint)cellData.EpochTime); mapData.Add(dateKey, headerData); list.Add(headerData); } mapData[dateKey].Add(cellData); mapData[dateKey].UpdateTotalValues(); Debug.WriteLine("MainPage::ListFrom epoch:" + epoch + " dateKey:" + dateKey + " count:" + list.Count + " headCount:" + mapData[dateKey].Count + " unix:" + (long)cellData.EpochTime); } return(list); }
/// <summary> /// Connection to a bluetooth device is initiated. /// </summary> private void OnDeviceConnected(string p_device) { KreyosUtils.Log("BluetoothTest::OnDeviceConnected", " device:" + p_device); DeviceData selectedDevice = DeviceData.DeviceFromName(m_devices, p_device); selectedDevice.UpdateStatus(EDevice.Status_Connected); this.UpdateDevices(); }
/// <summary> /// Sports Mode is done. /// </summary> /// <param name="data"></param> private void OnActivityDataEnd(byte[] data) { KreyosUtils.Log("BluetoothManager::OnActivityDataEnd", "data:" + data); ObserverInfo info = new ObserverInfo(); info.Command = EBTEvent.BTE_OnFinishSportsMode; BluetoothObserver.Instance.Trigger(EBTEvent.BTE_OnFinishSportsMode, info); }
/**************************************************************** * Constructors **/ public ActivityStatsHeader(uint p_unix) { DateTime epoch = KreyosUtils.ToDateTime((long)p_unix); this.Day = epoch.DayOfWeek.ToString(); this.Date = KreyosUtils.Month(epoch.Month) + " " + epoch.Day; this.UnixTime = p_unix; }
private void OnTodayActivityReceived(TodayActivity ta) { KreyosUtils.Log("BluetoothManager::OnTodayActivityReceived", ""); ObserverInfo info = new ObserverInfo(); info.Command = EBTEvent.BTE_OnTodaysActivity; info.TodaysData = ta; BluetoothObserver.Instance.Trigger(EBTEvent.BTE_OnTodaysActivity, info); }
public void GetOverallActivities() { if (!IsConnected) { return; } BluetoothAgent.Instance.InnerProtocol.getActivityData(); KreyosUtils.Log("Protocol", "Get Overall Activity Data"); }
public void SyncDateTime() { if (!IsConnected) { return; } BluetoothAgent.Instance.InnerProtocol.syncTime(); KreyosUtils.Log("Protocol", "Sync Date and Time"); }
public void SetDateTime(DateTime p_dateTime) { if (!IsConnected) { return; } BluetoothAgent.Instance.InnerProtocol.syncTimeFromInput(p_dateTime); KreyosUtils.Log("Protocol", "Set Date and Time"); }
/**************************************************************** * UI Callbacks **/ /// <summary> /// Check of Updates button callback. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnUpdateWatch(object sender, System.Windows.Input.GestureEventArgs e) { if (!BluetoothManager.Instance.IsConnected) { KreyosUtils.Log("UpdateFirmwareScreen::OnUpdateWatch", "Please connect your phone to your Kreyos watch."); return; } BluetoothManager.Instance.UpdateWatch(); }
public void GetTodayActivity() { if (!IsConnected) { return; } BluetoothAgent.Instance.InnerProtocol.sendDailyActivityRequest(); KreyosUtils.Log("Protocol", "Get Today Activity Data"); }
/// <summary> /// On Picker Date Changed /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnValueChanged(object sender, Microsoft.Phone.Controls.DateTimeValueChangedEventArgs e) { KreyosUtils.Log("SimpleAlarmScreen::OnValueChanged", "Value Changed.."); KreyosTimePicker timePicker = sender as KreyosTimePicker; DateTime? timeSet = timePicker.Value; AlarmView view = m_alarmViews[m_selectedIndex]; view.SetAlarm((DateTime)timeSet); view.UpdateView((bool)view.ToggleSwitch.IsChecked); }
private void OnOverallActivitiesReceived(ActivityDataDoc doc) { KreyosUtils.Log("BluetoothManager::OnOverallActivitiesReceived", ""); //~~~Display overall data ObserverInfo info = new ObserverInfo(); info.Command = EBTEvent.BTE_OnOverallActivity; info.OverallData = doc; BluetoothObserver.Instance.Trigger(EBTEvent.BTE_OnOverallActivity, info); }
private void OpenReadCompleted(object sender, OpenReadCompletedEventArgs e) { try { BluetoothAgent.Instance.InnerProtocol.sendStream("firmware", e.Result); } catch (WebException exc) { KreyosUtils.Log("BluetoothManager::OpenReadCompleted", "Error: " + exc.Message); } }
/// <summary> /// LongListSelected Event that is triggered when an Item is selected /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnDeviceSelected(object sender, System.Windows.Controls.SelectionChangedEventArgs e) { if (e.AddedItems.Count <= 0) { return; } BTCellData cellData = (BTCellData)e.AddedItems[0]; KreyosUtils.Log("BluetoothTest::OnDeviceSelected", "cellData:" + cellData); // Connected to Watch BluetoothManager.Instance.ConnectKreyosDevice(cellData.Name); }
/// <summary> /// Debug print the User Profile data /// </summary> public void Print() { KreyosUtils.Log("KreyosUserProfile::Print", "ID " + this.ID); KreyosUtils.Log("KreyosUserProfile::Print", "Email " + this.Email); KreyosUtils.Log("KreyosUserProfile::Print", "FacebookID " + this.FacebookID); KreyosUtils.Log("KreyosUserProfile::Print", "TwitterID " + this.TwitterID); KreyosUtils.Log("KreyosUserProfile::Print", "GoogleID " + this.GoogleID); KreyosUtils.Log("KreyosUserProfile::Print", "Password " + this.Password); KreyosUtils.Log("KreyosUserProfile::Print", "Name " + this.Name); KreyosUtils.Log("KreyosUserProfile::Print", "LastName " + this.LastName); KreyosUtils.Log("KreyosUserProfile::Print", "Birthday " + this.Birthday); KreyosUtils.Log("KreyosUserProfile::Print", "Gender " + this.Gender); KreyosUtils.Log("KreyosUserProfile::Print", "Height " + this.Height); KreyosUtils.Log("KreyosUserProfile::Print", "Weight " + this.Weight); }
public void UpdateFromRow(ActivityDataRow p_row) { Dictionary <ActivityDataRow.DataType, double> data = (Dictionary <ActivityDataRow.DataType, double>)p_row.data; this.Sport_ID = (uint)p_row.mode; this.ActivitySteps = (uint)data[ActivityDataRow.DataType.DATA_COL_STEP]; this.ActivityDistance = (uint)data[ActivityDataRow.DataType.DATA_COL_DIST]; this.ActivityCalories = (uint)data[ActivityDataRow.DataType.DATA_COL_CALS]; this.ActivityHeart = (uint)data[ActivityDataRow.DataType.DATA_COL_HR]; //~~~update time DateTime today = KreyosUtils.NowWith(p_row.hour, p_row.minute); this.CreatedTime = KreyosUtils.EpochFrom(today); this.CreatedDate = KreyosUtils.DateStringWithYear(today); }
} // Sub scroller data /**************************************************************** * Constructors **/ public ActivityStatsData( EAct_Types p_type, ulong p_epoch = 0, // seconds passed since 1/1/1970 uint p_steps = 0, uint p_distance = 0, uint p_calories = 0, uint p_altitude = 0 ) { this.EpochTime = p_epoch; this.Steps = p_steps; this.Distance = p_distance; this.Calories = p_calories; this.Altitude = p_altitude; this.ActType = p_type; // Test print DateTime date = KreyosUtils.ToDateTime((long)p_epoch); KreyosUtils.Log("ActivityStatsData::Constructor", "epoch:" + p_epoch + " date:" + date + " epochDate:" + date.ToShortDateString());// date.ToShortDateString() // Add display values this.TxtTime = date.Hour + ":" + date.Minute + date.ToString("tt").ToLower().Substring(0, 1); // Add am or pm after the minute value this.TxtActImage = ActivityStatsData.ActImage(p_type); this.TxtActTitle = ActivityStatsData.ActToString(p_type); this.Hour = date.Hour; this.Minute = date.Minute; this.Second = date.Second; // display altitude values for cycling. // Hard coded D: if (this.ActType == EAct_Types.ECycling) { this.TxtItemTitle = "altitude"; this.TxtItemValue = p_altitude.ToString(); } else { this.TxtItemTitle = "calories"; this.TxtItemValue = p_calories.ToString(); } // Create sub scroller data this.Stats = new List <StatsData>(); this.UpdateData(); }
public List <Kreyos_User_Activities> Activities(ulong p_epoch) { DateTime epoch = KreyosUtils.ToDateTime((long)p_epoch); string dateKey = this.KreyosPrefsKey + KreyosUtils.DateString(epoch); List <Kreyos_User_Activities> activities = null; try { activities = (List <Kreyos_User_Activities>)m_prefs[dateKey]; } catch (KeyNotFoundException ex) { return(null); } return(activities); }
/**************************************************************** * Public Functionalities * Assumes that p_acts contains 'today's data' only. **/ public void SaveUserAct(List <Kreyos_User_Activities> p_acts) { if (p_acts == null || p_acts.Count < 1) { return; } uint epochTime = p_acts[0].CreatedTime; DateTime epoch = KreyosUtils.ToDateTime((long)epochTime); string dateKey = this.KreyosPrefsKey + KreyosUtils.DateString(epoch); List <Kreyos_User_Activities> activities = null; try { //~~~Old Items activities = (List <Kreyos_User_Activities>)m_prefs[dateKey]; } catch (KeyNotFoundException ex) { //~~~New Items // sort activities p_acts = p_acts.OrderBy(act => act.CreatedTime).ToList(); m_prefs[dateKey] = (List <Kreyos_User_Activities>)p_acts; m_userActivityDates.Add(dateKey); this.Save(); return; } if (activities == null) { activities = new List <Kreyos_User_Activities>(); } //~~~insert the new items activities.AddRange(p_acts); //~~~sort activities = activities.OrderBy(act => act.CreatedTime).ToList(); m_prefs[dateKey] = (List <Kreyos_User_Activities>)activities; //~~~temp save // this shouldn't be called here this.Save(); }
private void OnSportsDataReceived(SportsDataRow sport) { KreyosUtils.Log("BluetoothManager::OnSportsDataReceived", ""); //* Logs KreyosUtils.Log("Mode:", "" + sport.sports_mode); KreyosUtils.Log("Time:", "" + sport.seconds_elapse); foreach (KeyValuePair <SportsDataRow.DataType, double> pair in sport.data) { KreyosUtils.Log("Data", "" + pair.Key + ":" + pair.Value); } //*/ ObserverInfo info = new ObserverInfo(); info.Command = EBTEvent.BTE_OnStartSportsMode; info.SportsData = sport; BluetoothObserver.Instance.Trigger(EBTEvent.BTE_OnStartSportsMode, info); }
public void SetAlarm(int p_index, bool p_bIsEnable, int p_hour, int p_minute) { if (!IsConnected) { return; } // int index // int mode // int monthday // int weekday // int hour // int minute // syncWatchAlarmConf(index, mEnableAlarm, mEnableVibrate, 0, 0, valueHour, valueMinute); int mode = p_bIsEnable ? 0x04 : 0x01; BluetoothAgent.Instance.InnerProtocol.setWatchAlarm(p_index, mode, 0, 0, p_hour, p_minute); KreyosUtils.Log("Protocol", "Set Alarm"); }
/**************************************************************** * Private Functions **/ private bool IsDataValid() { // check similar password if (m_txtPassword.Password == null || m_txtEmail.Text == null || m_txtPassword.Password.Length < KreyosUtils.MIN_CHARS || m_txtEmail.Text.Length < KreyosUtils.MIN_CHARS || m_txtPassword.Password.Equals(KreyosUtils.CONFIRM_PASSWORD_DEFAULT) || m_txtEmail.Text.Equals(KreyosUtils.EMAIL_DEFAULT) || !m_txtPassword.Password.Equals(m_txtConfirmPassword.Password) ) { // missed match password KreyosUtils.ClearField(this.txt_password_dummy, m_txtPassword.Password.Length, KreyosUtils.PASSWORD_DEFAULT); KreyosUtils.ClearField(this.txt_password_confirm_dummy, m_txtConfirmPassword.Password.Length, KreyosUtils.CONFIRM_PASSWORD_DEFAULT); return(false); } return(true); }
private void OnUpdateWatch(object sender, System.Windows.Input.GestureEventArgs e) { KreyosUtils.Log("SimpleAlarmScreen::OnUpdateWatch", "Update.."); for (int i = 0; i < m_alarmViews.Length; i++) { /* * AlarmView view = m_alarmViews[0]; * KreyosUtils.Log("Alarm Status", "" + view.ToggleSwitch.IsChecked); * KreyosUtils.Log("Alarm Time", "" + view.AlarmData.Hour); */ AlarmView alarm = m_alarmViews[i]; if (!(bool)alarm.ToggleSwitch.IsChecked) { continue; } BluetoothManager.Instance.SetAlarm(i, true, alarm.AlarmData.Hour, alarm.AlarmData.Minute); } }
/**************************************************************** * UI Callbacks **/ /// <summary> /// Toggle Switch Button Callback /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnEnabledAlarm(object sender, System.Windows.Input.GestureEventArgs e) { KreyosToggleSwitchButton button = sender as KreyosToggleSwitchButton; KreyosUtils.Log("SimpleAlarmScreen::OnEnabledAlarm", "Tap SelectedItem:" + e + " IsChecked:" + button.IsChecked); int index = AlarmView.GetIndex(button.Name); if (index >= 0 && index <= m_alarmViews.Length - 1) { AlarmView view = m_alarmViews[index]; view.UpdateView((bool)button.IsChecked); m_selectedIndex = index; // show picker if ((bool)button.IsChecked) { m_ctpContainer.Value = (DateTime?)view.AlarmData; m_ctpContainer.ClickTemplateButton(); } } }
/// <summary> /// Handle the change pivot view /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnPivotChangedPage(object sender, System.Windows.Controls.SelectionChangedEventArgs e) { // TODO: Add event handler implementation here. KreyosUtils.Log("MainScreen::OnPivotChangedPage", "update, do something here.."); Pivot page = (Pivot)sender; PivotItem item = (PivotItem)page.SelectedItem; string pageName = item.Name; EPivotPage pageToLoad = ScreenManager.PageMap[pageName]; //~~~check if screen is already loaded if (m_loadedScreen[(int)pageToLoad] == true) { this.FetchDataForPage(pageToLoad); return; } //~~~set the flag to load m_loadedScreen[(int)pageToLoad] = true; switch (pageToLoad) { case EPivotPage.TodaysActivity: { this.InitTodaysActivity(); item.UpdateLayout(); } break; case EPivotPage.OverallActivity: { this.InitActivityStats(); item.UpdateLayout(); } break; case EPivotPage.SportsMode: { this.InitSportsMode(); item.UpdateLayout(); } break; case EPivotPage.DailyTarget: { this.InitDailyTarget(); item.UpdateLayout(); } break; case EPivotPage.PersonalProfile: { this.InitProfile(); item.UpdateLayout(); } break; case EPivotPage.Settings: { } break; } KreyosUtils.Log("MainScreen::OnPivotChangedPage", "Loaded Page:" + pageName); }
/// <summary> /// Connection with the watch is disconnected. /// </summary> private void OnDeviceDisconnected(string p_error) { KreyosUtils.Log("BluetoothTest::OnDeviceDisconnected", "message:" + p_error); m_txtBTStatus.Text = "Disconnected"; }