typedef struct
{
std::string sleeptime; // 睡眠时间
- std::string walktime; // 醒来时间
+ std::string waketime; // 醒来时间
int totaltime; // 睡眠总时间
} SleepDataUI;
class SleepModel
int get_sleep_total();
std::string get_rest_str(); // 解析入睡时间
- std::string get_walk_str(); // 解析醒来时间
+ std::string get_wake_str(); // 解析醒来时间
std::string get_goal_str(); // 解析目标休息时间
std::string get_notifiy(); // 获取提醒时间
std::string get_sleep_notifiy(); // 获取睡眠时间
- std::string get_walk_notifiy(); // 获取起床时间
+ std::string get_wake_notifiy(); // 获取起床时间
void set_sleep_state(SLEEPSTATE state);
SLEEPSTATE get_sleep_state();
virtual ~SleepModel();
std::string sleepStr{"--"};
- std::string walkStr{"--"};
+ std::string wakeStr{"--"};
std::string goalStr{"--"};
std::string goalnotifyStr{"--"};
std::string goalsleepStr{"--"};
- std::string goalwalkStr{"--"};
+ std::string goalwakeStr{"--"};
uint8_t sleep_total_time = 0;
uint8_t goal_total_time = 0;
private:
UILabelExt *resttitle{nullptr}; // 作息时间标题
UILabelExt *sleeptitle{nullptr}; // 入睡时间标题
- UILabelExt *walktitle{nullptr}; // 醒来标题
+ UILabelExt *waketitle{nullptr}; // 醒来标题
UILabelExt *apptitle{nullptr}; // 详情
UILabelExt *goal{nullptr}; // 作息时间
UILabelExt *sleep{nullptr}; // 入睡时间
- UILabelExt *walk{nullptr}; // 醒来时间
+ UILabelExt *wake{nullptr}; // 醒来时间
UIImageView *transverseline_1{nullptr}; // 横线1
UIImageView *transverseline_2{nullptr}; // 横线2
UIImageView *verticalline{nullptr}; // 竖线
SleepDataUI *data = ReadSleepData();
if (data != nullptr)
{
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ReadSleepData sleepStr %s wakeStr %s sleep_total_time %d",
+ data->sleeptime.c_str(), data->waketime.c_str(), data->totaltime);
sleepStr = data->sleeptime;
- walkStr = data->walktime;
+ wakeStr = data->waketime;
sleep_total_time = data->totaltime;
}
}
SleepDataUI *data = new SleepDataUI();
cJSON *sleeptime_item = cJSON_GetObjectItem(sleep_root, "sleeptime");
- cJSON *walktime_item = cJSON_GetObjectItem(sleep_root, "walktime");
+ cJSON *waketime_item = cJSON_GetObjectItem(sleep_root, "waketime");
cJSON *totaltime_item = cJSON_GetObjectItem(sleep_root, "totaltime");
- if (sleeptime_item && walktime_item && totaltime_item)
+ if (sleeptime_item && waketime_item && totaltime_item)
{
data->sleeptime = sleeptime_item->valuestring;
- data->walktime = walktime_item->valuestring;
+ data->waketime = waketime_item->valuestring;
data->totaltime = totaltime_item->valueint;
}
else
}
cJSON_Delete(sleep_root);
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ReadSleepData is ok!");
// 返回结构体
return data;
}
}
cJSON_AddItemToObject(sleep_root, "sleeptime", cJSON_CreateString(data.sleeptime.c_str()));
- cJSON_AddItemToObject(sleep_root, "walktime", cJSON_CreateString(data.walktime.c_str()));
+ cJSON_AddItemToObject(sleep_root, "waketime", cJSON_CreateString(data.waketime.c_str()));
cJSON_AddItemToObject(sleep_root, "totaltime", cJSON_CreateNumber(data.totaltime));
char *jsonData = cJSON_Print(sleep_root);
cJSON_free(sleep_root);
free(jsonData);
outFile.close();
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UpdateHealthData JSON is ok");
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "UpdateHealthData JSON is ok");
return true;
}
}
// 打印数据
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "fall_asleep_timestamp:%d wake_up_timestamp:%d total_time:%d",
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "fall_asleep_timestamp:%d wake_up_timestamp:%d total_time:%d",
data->fall_asleep_timestamp, data->wake_up_timestamp, data->total_time);
update_time_info(data->fall_asleep_timestamp, sleepStr); // 睡眠字符串
- update_time_info(data->wake_up_timestamp, walkStr); // 醒来
+ update_time_info(data->wake_up_timestamp, wakeStr); // 醒来
// 更新睡眠总时间
sleep_total_time = data->total_time; // 睡眠总时长
SleepDataUI UIdata;
UIdata.sleeptime = sleepStr;
- UIdata.walktime = walkStr;
+ UIdata.waketime = wakeStr;
UIdata.totaltime = sleep_total_time;
// 数据存储
SaveSleepData(UIdata);
// 将原3个字符串清空
goalnotifyStr.clear();
goalsleepStr.clear();
- goalwalkStr.clear();
+ goalwakeStr.clear();
int goal_sleep = get_sleep_time_from_config_model();
- int goal_walk = get_wake_up_time_from_config_model();
+ int goal_wake = get_wake_up_time_from_config_model();
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "goal_sleep:%d goal_walk:%d", goal_sleep, goal_walk);
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "goal_sleep:%d goal_wake:%d", goal_sleep, goal_wake);
/* -------------------------------------------------------------------------- */
// 提取小时部分(前2字节)
int goal_sleep_hour = goal_sleep >> 16;
goalnotifyStr = notifyoss.str();
/* -------------------------------------------------------------------------- */
- int goal_walk_hour = goal_walk >> 16;
- int goal_walk_min = goal_walk & 0x00FF;
- std::ostringstream walkoss;
- walkoss << std::setfill('0') << std::setw(2) << goal_walk_hour << ":" << std::setw(2) << goal_walk_min;
+ int goal_wake_hour = goal_wake >> 16;
+ int goal_wake_min = goal_wake & 0x00FF;
+ std::ostringstream wakeoss;
+ wakeoss << std::setfill('0') << std::setw(2) << goal_wake_hour << ":" << std::setw(2) << goal_wake_min;
// 起床时间点字符串
- goalwalkStr = walkoss.str();
+ goalwakeStr = wakeoss.str();
/* -------------------------------------------------------------------------- */
// 睡眠字符串 以及总时长
- goalStr = goalsleepStr + "-" + goalwalkStr;
+ goalStr = goalsleepStr + "-" + goalwakeStr;
// goal_total_time 计算
int total_hours;
- if (goal_walk_hour < goal_sleep_hour)
+ if (goal_wake_hour < goal_sleep_hour)
{
- total_hours = (goal_walk_hour + 24) - goal_sleep_hour; // 跨天情况
+ total_hours = (goal_wake_hour + 24) - goal_sleep_hour; // 跨天情况
}
else
{
- total_hours = goal_walk_hour - goal_sleep_hour;
+ total_hours = goal_wake_hour - goal_sleep_hour;
}
- int total_minutes = goal_walk_min - goal_sleep_min;
+ int total_minutes = goal_wake_min - goal_sleep_min;
if (total_minutes < 0)
{
total_hours--; // 如果分钟差为负数,小时差减1
return sleepStr;
}
// 获取实际醒来时间str
- std::string SleepModel::get_walk_str()
+ std::string SleepModel::get_wake_str()
{
- return walkStr;
+ return wakeStr;
}
// 获取目标休息时间str
std::string SleepModel::get_goal_str()
}
// 获取 目标起床 时间点str
- std::string SleepModel::get_walk_notifiy()
+ std::string SleepModel::get_wake_notifiy()
{
- return goalwalkStr;
+ return goalwakeStr;
}
// 设置睡眠状态
void SleepModel::set_sleep_state(SLEEPSTATE state)
static SleepTimeView *g_pSleepView{nullptr};
static std::string restStr;
static std::string sleepStr;
- static std::string walkStr;
+ static std::string wakeStr;
SleepTimeView::SleepTimeView()
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SleepTimeView::SleepTimeView");
if (sleep_hour != 0 || sleep_min != 0)
{
sleep->SetText((SleepModel::GetInstance().get_rest_str()).c_str());
- walk->SetText((SleepModel::GetInstance().get_walk_str()).c_str());
+ wake->SetText((SleepModel::GetInstance().get_wake_str()).c_str());
}
goal->SetText((SleepModel::GetInstance().get_goal_str()).c_str());
}
delete sleeptitle;
sleeptitle = nullptr;
}
- if (walktitle != nullptr)
+ if (waketitle != nullptr)
{
- delete walktitle;
- walktitle = nullptr;
+ delete waketitle;
+ waketitle = nullptr;
}
if (apptitle != nullptr)
{
delete sleep;
sleep = nullptr;
}
- if (walk != nullptr)
+ if (wake != nullptr)
{
- delete walk;
- walk = nullptr;
+ delete wake;
+ wake = nullptr;
}
if (transverseline_1 != nullptr)
{
/* -------------------------------- title初始化 -------------------------------- */
InitLabelExt(resttitle, 83, 50, 300, 35, "resttitle", STR_REATTIME, DEFAULT_VECTOR_FONT_FILENAME, 30);
InitLabelExt(sleeptitle, 21, 203, 200, 35, "sleeptitle", STR_SLEEPTIME, DEFAULT_VECTOR_FONT_FILENAME, 30);
- InitLabelExt(walktitle, 213, 203, 300, 35, "walktitle", STR_WALKTIME, DEFAULT_VECTOR_FONT_FILENAME, 30);
+ InitLabelExt(waketitle, 213, 203, 300, 35, "waketitle", STR_WALKTIME, DEFAULT_VECTOR_FONT_FILENAME, 30);
InitLabelExt(apptitle, 93, 300, 300, 200, "apptitle", STR_APPMORE, DEFAULT_VECTOR_FONT_FILENAME, 26);
apptitle->SetTextColor(Color::Gray());
/* ------------------------------- 数据label初始化 ------------------------------- */
sleepStr = "--";
InitLabelAdapt(sleep, 79, 238, 230, 47, "sleeplabel", sleepStr.c_str(), DEFAULT_VECTOR_FONT_FILENAME, 40);
sleep->SetTextColor(Color::Purple());
- walkStr = "--";
- InitLabelAdapt(walk, 319, 238, 230, 47, "walklabel", walkStr.c_str(), DEFAULT_VECTOR_FONT_FILENAME, 40);
- walk->SetTextColor(Color::Purple());
+ wakeStr = "--";
+ InitLabelAdapt(wake, 319, 238, 230, 47, "wakelabel", wakeStr.c_str(), DEFAULT_VECTOR_FONT_FILENAME, 40);
+ wake->SetTextColor(Color::Purple());
/* -------------------------------- 将组件添加到根视图 ------------------------------- */
Add(resttitle);
Add(sleeptitle);
- Add(walktitle);
+ Add(waketitle);
Add(apptitle);
Add(goal);
Add(sleep);
- Add(walk);
+ Add(wake);
Add(transverseline_1);
Add(transverseline_2);
Add(verticalline);
UIImageView *sunnyicon{nullptr};
UIImageView *alarmicon{nullptr};
UILabelExt *nowlabel{nullptr};
- UILabelExt *walklabel{nullptr}; // 早安时间
+ UILabelExt *wakelabel{nullptr}; // 早安时间
UILabelButtonExt *closebutton{nullptr}; // 关闭按键
UILabelButtonExt *nopbutton{nullptr}; // 小睡按键
ConfigModel::GetInstance()->SetDnotdisturb(true);
break;
case SLEEPSTATE::WAKE:
- titleStr = SleepModel::GetInstance().get_walk_notifiy();
+ titleStr = SleepModel::GetInstance().get_wake_notifiy();
textId = STR_MORNNING;
ConfigModel::GetInstance()->SetDnotdisturb(false); // 关闭勿扰
SetAlarmClockView(); // 设置为早安视图
InitLabelExt(alarmtitle, 83, 50, 300, 45, "labletitle", STR_MORNNING, DEFAULT_VECTOR_FONT_FILENAME, 30);
InitLabelExt(nowlabel, 110, 243, 200, 60, "labletitle", STR_NOW, DEFAULT_VECTOR_FONT_FILENAME, 30);
/*获取起床时间labe*/
- std::string walkStr = SleepModel::GetInstance().get_walk_notifiy();
- InitLabel(walklabel, 190, 245, 200, 60, "labletitle", walkStr.c_str(), DEFAULT_VECTOR_FONT_FILENAME, 30);
+ std::string wakeStr = SleepModel::GetInstance().get_wake_notifiy();
+ InitLabel(wakelabel, 190, 245, 200, 60, "labletitle", wakeStr.c_str(), DEFAULT_VECTOR_FONT_FILENAME, 30);
/*设置按键*/
InitButtonExt(nopbutton, 58, 320, 170, 90, NOPBUTTON, STR_NAP, 30);
nopbutton->SetOnTouchListener(static_cast<UIView::OnTouchListener *>(&SleepViewEventListener::GetInstance()));
SleepGroupView->Add(sunnyicon);
SleepGroupView->Add(alarmicon);
SleepGroupView->Add(nowlabel);
- SleepGroupView->Add(walklabel);
+ SleepGroupView->Add(wakelabel);
SleepGroupView->Add(nopbutton);
SleepGroupView->Add(closebutton);
delete nowlabel;
nowlabel = nullptr;
- delete walklabel;
- walklabel = nullptr;
+ delete wakelabel;
+ wakelabel = nullptr;
delete closebutton;
closebutton = nullptr;