From 0c9294022061b6ad20d334767d227d0e1ee6de39 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E8=A2=81=E6=B8=85=E6=A2=A6?= <3449750381@qq.com> Date: Wed, 25 Jun 2025 03:38:01 +0000 Subject: [PATCH] Merge #1886 into sdk602patch0911 from refs/changes/1886/head MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 修改设置获取4G状态 * refs/changes/1886/head: (2 commits squashed) - 修改设置获取4G状态 - 增加gps相关接口 Signed-off-by: Caisking <3449750381@qq.com> Reviewed-by: Caisking <3449750381@qq.com> Reviewed-by: 罗正 <1732036298@qq.com> Reviewed-by: aliyun8003852482 <1224667075@qq.com> Reviewed-by: snickersun@163.com Reviewed-by: aliyun6865282430 <1624952103@qq.com> Reviewed-by: 薛文强 Merged-by: Caisking <3449750381@qq.com> CR-link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/1886 --- .../settings/src/SettingPresenter.cpp | 1 + .../traing/include/TraingEnddataView.h | 28 +++- .../nativeui/traing/include/TraingModel.h | 22 +++ .../nativeui/traing/src/TraingEnddataView.cpp | 132 ++++++++++++++---- .../nativeui/traing/src/TraingModel.cpp | 93 +++++++++++- 5 files changed, 248 insertions(+), 28 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingPresenter.cpp index 0e9463a1b..feac999bd 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingPresenter.cpp @@ -18,6 +18,7 @@ #include "common/key_code.h" #include #include "bleService.h" +#include "custom_runtime.h" namespace OHOS { diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingEnddataView.h b/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingEnddataView.h index e15a82e49..23f89f044 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingEnddataView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingEnddataView.h @@ -36,9 +36,27 @@ #include "traing/Training_UiConfig.h" #include "traing/include/TraingModel.h" #include "uicomponents/UIComponents.h" + +#include "components/ui_canvas.h" + + namespace OHOS { #define BUTTONBACK "button1" +struct TrackSegment { + std::vector points; // 轨迹点 + ColorType color; // 段颜色 + // ColorType endColor; // 段结束颜色 +}; +// 轨迹数据:拆分成多个段(这里分2段:起→达,达→终) + +// 标记点(起、达、终) +struct Marker { + Point pos; + const char *text; + ColorType color; +}; + class TraingEnddataPresenter; class TraingEnddataView : public View { @@ -59,14 +77,16 @@ public: void InitData(void); void InitializeImageViews(void); void InitializeLabels(void); - void SetLabelsTextColor(const std::vector &labels, - OHOS::ColorType color); - void AddLabelsToScrollView(const std::vector &labels); void InitializeExitControls(void); void BonusdataView(); void ExitView(); + void GenerateTrackPoints(void); + void DrawMarkers(UICanvas *canvas); + void DrawTrackSegment(UICanvas *canvas); + // ColorType GetGradientColor(const ColorType &start, const ColorType &end, float progress); + private: UIView::OnDragListener *draglistener{nullptr}; TraingEnddataView(TraingEnddataView &&) = delete; @@ -116,6 +136,8 @@ private: UIImageView *imageLine12 = nullptr; bool viewiInitStatus{false}; + + std::vector trackSegments_; }; } // namespace OHOS #endif // TraingEnddata_PRESENTER_H diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingModel.h b/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingModel.h index eb3e9f7c1..c46c6df11 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingModel.h @@ -244,6 +244,16 @@ struct SportData { } }; +//经纬度结构体 +struct GPSData { + double latitude; // 纬度 + double longitude; // 经度 +}; +//画布点位结构体 +struct CanvasPoint { + int x; + int y; +}; class TraingModel { public: TraingModel(); @@ -355,6 +365,13 @@ public: void SetUserSportdata(); void SetMaxHeart(int maxheart); + //映射经纬度数据集映射画布绘制轨迹坐标集 + void GetPointData(); + //添加经纬度数据集 + void AddGPSData(double latitude, double longitude); + //获取轨迹点集 + std::vector GetCanvasData()const; + private: TraingModel(const TraingModel &) = delete; TraingModel &operator=(const TraingModel &) = delete; @@ -400,6 +417,11 @@ private: int user_Intensity{160}; uint32_t current_goal{0}; // 当前目标 + ////////////////////GPS数据集配置///////////////// + double latitude{0}; + double longitude{0}; + std::vector canvasData; // 轨迹点集 + std::vector gpsData; // GPS数据集 }; } // namespace OHOS diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingEnddataView.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingEnddataView.cpp index 08ec1d13c..f110d272f 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingEnddataView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingEnddataView.cpp @@ -4,6 +4,8 @@ #include "UiConfig.h" #include "common/image_cache_manager.h" #include "components/ui_button.h" +#include "components/ui_canvas.h" +#include "components/ui_label.h" #include "components/ui_label_ext.h" #include "traing/Training_UiConfig.h" #include "traing/include/TraingModel.h" @@ -16,14 +18,6 @@ #include // 包含字符串处理库,用于使用 std::to_string #include -/*测试打印函数*/ -#define PRINT_LINE_INFO() \ - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "File: %s, Line: %d\r\n", __FILE__, \ - __LINE__) -#define PRINT_FUNCTION_LINE() \ - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Function: %s, Line: %d\r\n", \ - __FUNCTION__, __LINE__) - /* 普通运动: 时长,平均心率,训练强度,卡路里,目标完成度 @@ -32,19 +26,21 @@ 距离,步数,平均配速,步幅,步频,目标完成度 */ #define UI_UPDATA 0 -namespace OHOS { +#define CANVAS_SIZE 400 -static const int startY_Unit = 252; -static const int startY_Value = 292; -static const int labelHeight = 40; -static const int labelInterval = 130; -ColorType textColor = Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0x7f); +namespace OHOS { -static const int initialY = 132; +static const int initialY = 132 + CANVAS_SIZE; static const int lineHeight = 130; static const int iconHeight = 80; static const int verticalOffset = 2; -static const int baseY = 214; +static const int baseY = 214 + CANVAS_SIZE; +static const int startY_Unit = 252 + CANVAS_SIZE; +static const int startY_Value = 292 + CANVAS_SIZE; +static const int labelHeight = 40; +static const int labelInterval = 130; + +ColorType textColor = Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0x7f); static TraingEnddataView *g_pTraingEnddataView{nullptr}; @@ -52,11 +48,6 @@ TraingEnddataView::TraingEnddataView() { g_pTraingEnddataView = this; } TraingEnddataView::~TraingEnddataView() { DeInit(); - // scrollView_->RemoveAll(); - - // UIViewGroup *tmpGroup = dynamic_cast(container_); - // UIViewGroup::RemoveAndDeleteAllRecursively(tmpGroup); - g_pTraingEnddataView = nullptr; } @@ -113,10 +104,10 @@ void TraingEnddataView ::InitializeLabels() { /*title and sport*/ InitRollLabel(labeltype, 83, 50, 300, 35, "label1", STR_EXERCISE_LIST, DEFAULT_VECTOR_FONT_FILENAME, 30); - InitRollLabel(labelsport, 147, 140, 240, 35, "label6", + InitRollLabel(labelsport, 147, 140 + CANVAS_SIZE, 240, 35, "label6", STR_EXERCISE_OUTDOORRUNNING, DEFAULT_VECTOR_FONT_FILENAME, 30); - InitLabel(labelduration, 146, 179, 240, 40, "label7", "13:00:22-15:00:12", - DEFAULT_VECTOR_FONT_FILENAME, 28); + InitLabel(labelduration, 146, 179 + CANVAS_SIZE, 240, 40, "label7", + "13:00:22-15:00:12", DEFAULT_VECTOR_FONT_FILENAME, 28); // 初始化Label //时长 InitRollLabel(labelutime, 146, startY_Unit + labelInterval * 0, 240, 40, @@ -690,6 +681,16 @@ void TraingEnddataView::OnStart() { container_->SetOnDragListener(presenter_); SetKeyActListener(); + + ///////////////////////////gps轨迹测试////////////////////// + UICanvas *canvas = new UICanvas(); + canvas->SetHeight(CANVAS_SIZE); + canvas->SetWidth(CANVAS_SIZE); + canvas->SetPosition(33, 100); + scrollView_->Add(canvas); + GenerateTrackPoints(); + DrawTrackSegment(canvas); + DrawMarkers(canvas); } void TraingEnddataView::OnSetUpView() { @@ -712,5 +713,88 @@ void TraingEnddataView::OnStop() { } return; } +//////////////////////////////gps轨迹测试///////////////////////////////////// + +std::vector markers_ = {{{58, 18}, "起", Color::Green()}, + {{299, 146}, "终", Color::Blue()}}; + +void TraingEnddataView::GenerateTrackPoints() { + trackSegments_.clear(); + + TrackSegment seg1; + seg1.color = Color::Blue(); + seg1.points = { + {299, 146}, {293, 154}, {288, 149}, {281, 163}, {277, 156}, {272, 166}, + {273, 169}, {268, 168}, {266, 172}, {261, 185}, {254, 181}, {253, 191}, + {249, 196}, {247, 201}, {243, 194}, {244, 198}, {239, 204}, {237, 217}, + {234, 218}, {231, 215}, {229, 217}, {226, 219}, {224, 228}, {224, 238}, + {221, 232}, {221, 244}, {220, 238}, {220, 245}, {218, 254}, {215, 250}, + {212, 256}, {214, 265}, {210, 257}, {208, 261}, {207, 265}, {208, 268}, + {204, 278}, {206, 277}, {206, 271}, {203, 282}, {202, 275}, {202, 278}, + {198, 289}, {197, 289}, {199, 291}, {199, 291}, {194, 291}, {195, 287}, + {193, 293}, {193, 285}, {189, 292}, {191, 299}, {188, 286}, {190, 289}, + {188, 297}, {184, 294}, {181, 294}, {182, 284}, {182, 293}, {177, 284}, + {179, 283}, {175, 280}, {171, 277}, {171, 275}, {170, 280}, {164, 278}, + {165, 269}, {161, 270}, {159, 260}, {158, 267}, {156, 255}, {149, 249}, + {147, 254}, {142, 244}, {143, 238}, {137, 237}, {131, 223}, {130, 225}, + {128, 212}, {121, 201}, {117, 206}, {115, 197}, {108, 191}, {106, 174}, + {98, 171}, {92, 163}, {89, 148}, {85, 141}, {74, 131}, {73, 123}, + {64, 111}, {61, 98}, {52, 92}, {47, 84}, {36, 70}, {30, 48}, + {23, 43}, {17, 33}, {58, 18}, + }; + trackSegments_.push_back(seg1); +} +void TraingEnddataView::DrawTrackSegment(UICanvas *canvas) { + // 绘制网格 + // Paint debugPaint; + // debugPaint.SetStrokeColor(Color::Gray()); + // for (int i = 0; i < CANVAS_SIZE; i += 5) { + // canvas->DrawLine({i, 0}, {i, CANVAS_SIZE}, debugPaint); + // canvas->DrawLine({0, i}, {CANVAS_SIZE, i}, debugPaint); + // } + + // 绘制轨迹 + for (const auto &seg : trackSegments_) { + if (seg.points.size() < 3) //至少需要 3 个点位 + return; + + Paint paint; + paint.SetStyle(Paint::PaintStyle::STROKE_STYLE); + paint.SetStrokeWidth(8); + paint.SetStrokeColor(seg.color); + + canvas->BeginPath(); + canvas->MoveTo(seg.points[0]); + for (size_t i = 1; i < seg.points.size(); ++i) { + canvas->LineTo(seg.points[i]); + } + canvas->DrawPath(paint); + } +} +void TraingEnddataView::DrawMarkers(UICanvas *canvas) { + Paint circlePaint; + circlePaint.SetStyle(Paint::PaintStyle::FILL_STYLE); + + Paint textPaint; + textPaint.SetFillColor(Color::White()); + + for (const auto &marker : markers_) { + // 绘制标记点圆形 + circlePaint.SetFillColor(Color::Green()); + canvas->DrawCircle(marker.pos, 12, circlePaint); + + // 绘制文字,调整位置和排版 + UICanvas::FontStyle fontStyle; + fontStyle.align = TEXT_ALIGNMENT_LEFT; // 文字居左,避免 RTL 反向 + fontStyle.direct = TEXT_DIRECT_LTR; // 从左到右排版 + fontStyle.fontName = DEFAULT_VECTOR_FONT_FILENAME; + fontStyle.fontSize = 24; // 适配 300*300 画布 + fontStyle.letterSpace = 2; + + // 文字位置:圆点右侧偏移,避免覆盖 + canvas->DrawLabel({marker.pos.x + 18, marker.pos.y - 6}, marker.text, 80, + fontStyle, textPaint); + } +} } // namespace OHOS diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp index fb87efaa2..e0ca6f146 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp @@ -51,6 +51,7 @@ #include "bleService.h" #include "chip_system_time.h" #include +#include "cmath" extern "C" errcode_t uapi_get_timestampe_ms(uint32_t *tm); extern "C" errcode_t uapi_get_timestampe_ss(uint32_t *tm); @@ -190,8 +191,9 @@ void store_sport_data() { OHOS::TraingModel::GetInstance()->RecordSportData(); return; } -#if TIMER + namespace OHOS { +#if TIMER // 声明定时器变量 static osTimerId_t g_startCounting = NULL; // 定时器 static constexpr uint64_t MS_ONE_SECONDS = 1000; @@ -204,6 +206,9 @@ static constexpr int16 NUM_TIME_HOUR = 3600; static constexpr int32 NUM_TIME_DAY = 86400; #endif +// #define min(x, y) (((x) < (y)) ? (x) : (y)) +// #define max(x, y) (((x) > (y)) ? (x) : (y)) + SportData *sportdata = new SportData(); int shock_count{0}; //震动提醒 @@ -652,6 +657,9 @@ void TraingModel::ResetSharedTrainingData() { Openstate = true; // 开启运动开始标志位 shock_count = 0; //重置震动计数 + + gpsData.clear();// 清空gps数据 + canvasData.clear();// 清空画布数据 } uint32_t TraingModel::get_current_time() { @@ -2340,4 +2348,87 @@ bool TraingModel::LoadDataFormJson(std::vector &sportDataVector) { return true; } +//////////////////////////////////////GPS/////////////////////////////////////////////// +/* + Latitude(纬度):范围:-90° 至 +90°(或南纬 90° 至北纬 90°); + Longitude(经度):范围:-180° 至 +180°(或西经 180° 至东经 180°); + + -画布数据集最多是100个定位坐标,超过按比例进行拿取100个点位; + -通过映射关系,将经纬度转换为400*400画布上的坐标; + -但是不能靠近400,以免显示不全等问题,350*350; + -如果处理负数,需要将其转换为正数,然后再进行映射? + -如果有正数又有负数,应该怎么处理? +*/ + +static double getmin(double a, double b) +{ + return a < b ? a : b; +} + +static double getmax(double a, double b) +{ + return a > b ? a : b; +} + +// 通过经纬度数据集映射画布绘制轨迹坐标集 +void TraingModel::GetPointData() +{ + // 1. 按比例采样最多100个点位 + std::vector sampledData; + if (gpsData.size() > 100) { + double step = static_cast(gpsData.size() - 1) / 99; + for (int i = 0; i < 100; i++) { + int index = static_cast(i * step); + sampledData.push_back(gpsData[index]); + } + } else { + sampledData = gpsData; + } + + // 2. 计算经纬度的最小值和最大值 + double minLat = 90.0, maxLat = -90.0; + double minLon = 180.0, maxLon = -180.0; + for (const auto& point : sampledData) { + minLat = getmin(minLat, point.latitude); + maxLat = getmax(maxLat, point.latitude); + minLon = getmin(minLon, point.longitude); + maxLon = getmax(maxLon, point.longitude); + } + + // 3. 将经纬度映射到350×350画布区域(居中在400×400画布) + canvasData.clear(); + const double canvasSize = 350.0; + const double offset = 25.0; // 400 - 350 = 50,两边各留25的边距 + + for (const auto& point : sampledData) { + // 归一化处理(0-1范围) + double normLat = (point.latitude - minLat) / (maxLat - minLat); + double normLon = (point.longitude - minLon) / (maxLon - minLon); + + // 映射到画布坐标(考虑偏移) + double x = normLon * canvasSize + offset; + double y = (1.0 - normLat) * canvasSize + offset; // 注意:y轴需要反转(屏幕坐标系向下为正) + + canvasData.push_back({x, y}); + } +} + +// 添加经纬度数据集 +void TraingModel::AddGPSData(double latitude, double longitude) +{ + // 判断数据是否合理 + if (latitude < -90 || latitude > 90 || longitude < -180 || longitude > 180) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Invalid GPS data"); + return; + } + // 添加数据 + gpsData.push_back({latitude, longitude}); +} + +// 获取轨迹点集 +std::vector TraingModel::GetCanvasData() const +{ + return canvasData; +} + } // namespace OHOS -- 2.17.1