237 lines
6.1 KiB
C++
237 lines
6.1 KiB
C++
#include "TjdUiAppProductModel.h"
|
|
#include "TjdUiScreenManage.h"
|
|
#include "motor.h"
|
|
#include "player_sample_wrapper.h"
|
|
#include "rtc_api.h"
|
|
// #include "sample_audio_api.h"
|
|
#include "service_charger.h"
|
|
#include "service_gps.h"
|
|
#include "service_gsensor.h"
|
|
#include "service_hrsensor.h"
|
|
#include "service_pgnss.h"
|
|
#include "sql_fit.h"
|
|
#include "sys_config.h"
|
|
|
|
extern "C"
|
|
{
|
|
#include "task_ancillary.h"
|
|
}
|
|
|
|
namespace TJD {
|
|
|
|
#ifndef ARRAY_SIZE
|
|
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
|
#endif
|
|
|
|
struct ProductEventInfo
|
|
{
|
|
signed int (*func_event_handler)(void *param); // 事件处理函数
|
|
void *param; // 事件处理函数入参
|
|
void (*func_event_debug)(char *str, ...); // 打印
|
|
void *payload;
|
|
};
|
|
|
|
void TjdUiAppProductModel::SetKeepScreenOn(bool keepScreenOn)
|
|
{
|
|
const power_display_svr_api_t *display_api = power_display_svr_get_api();
|
|
display_api->set_auto_timeout_function(!keepScreenOn);
|
|
}
|
|
|
|
uint32_t TjdUiAppProductModel::HeartRateOperate(InterfaceType type, void *param)
|
|
{
|
|
hr_api_info_t hr_api_info = {HR_SERVICE_UI_PRODUCTION, 0xffffffff};
|
|
switch (type) {
|
|
case InterfaceType::OPEN:
|
|
tjd_service_hrs_get_ops()->open(hr_api_info);
|
|
break;
|
|
case InterfaceType::GET_DATA:
|
|
*(uint8_t *)param = tjd_service_hrsensor_get_cur_hrvalue();
|
|
break;
|
|
case InterfaceType::CLOSE:
|
|
tjd_service_hrs_get_ops()->close();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
uint32_t TjdUiAppProductModel::GsensorOperate(InterfaceType type, void *param)
|
|
{
|
|
struct rtc_time localTime;
|
|
tjd_driver_rtc_get_ops()->get_rtc_time(&localTime);
|
|
gsensor_xyz_info xyzInfo = {};
|
|
uint16_t step = sql_fit_get_day_step(localTime.tm_wday);
|
|
switch (type) {
|
|
case InterfaceType::OPEN:
|
|
break;
|
|
case InterfaceType::GET_DATA:
|
|
tjd_service_gs_get_xyz_fifo(GSEN_SERVICE_PRODUCTION, &xyzInfo, 1);
|
|
*(GSensorInfo *)param = {step, xyzInfo.gsensor_x.raw_data, xyzInfo.gsensor_y.raw_data,
|
|
xyzInfo.gsensor_z.raw_data};
|
|
break;
|
|
case InterfaceType::CLOSE:
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
uint32_t TjdUiAppProductModel::SpeakerOperate(InterfaceType type, void *param)
|
|
{
|
|
bool redo = *(bool *)param;
|
|
PlayerStop();
|
|
switch (type) {
|
|
case InterfaceType::OPEN:
|
|
PlayerStart();
|
|
osDelay(100);
|
|
if (redo) {
|
|
SingLoopEnable();
|
|
} else {
|
|
SingLoopDisable();
|
|
}
|
|
break;
|
|
case InterfaceType::CLOSE:
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
uint32_t TjdUiAppProductModel::MotorOperate(InterfaceType type, void *param)
|
|
{
|
|
static bool record = false;
|
|
bool redo = *(bool *)param;
|
|
motor_param_t motorParam = {.cycle1_on = 500, .cycle1_off = 500, .cycle1_cnt = 1, .duty = 100};
|
|
|
|
switch (type) {
|
|
case InterfaceType::OPEN:
|
|
record = redo;
|
|
if (redo) {
|
|
motorParam.cycle1_on = 60000;
|
|
motorParam.cycle1_off = 1, motorParam.cycle1_cnt = UINT16_MAX;
|
|
}
|
|
tjd_driver_motor_user_start(&motorParam);
|
|
break;
|
|
case InterfaceType::CLOSE:
|
|
if (record) {
|
|
motor_param_t tmpParam = {.cycle1_on = 50, .cycle1_off = 950, .cycle1_cnt = 1, .duty = 100};
|
|
tjd_driver_motor_user_start(&tmpParam);
|
|
} else {
|
|
tjd_driver_motor_user_stop();
|
|
}
|
|
record = false;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
uint32_t TjdUiAppProductModel::MicrophoneOperate(InterfaceType type, void *param)
|
|
{
|
|
int ret = 0;
|
|
// switch (type) {
|
|
// case InterfaceType::OPEN: {
|
|
// char *argv[] = {"sample_ai_ao", "-s", "16000", "-c", "1", "-b", "16", "-p", "adc0", "-o", "i2s0", "-v",
|
|
// "38"}; sample_ai_ao(ARRAY_SIZE(argv), argv);
|
|
// } break;
|
|
// case InterfaceType::CLOSE: {
|
|
// char *argv[] = {"sample_ai_ao", "q"};
|
|
// sample_ai_ao(ARRAY_SIZE(argv), argv);
|
|
// } break;
|
|
// default:
|
|
// break;
|
|
// }
|
|
return 0;
|
|
}
|
|
|
|
uint32_t TjdUiAppProductModel::GPSOperate(InterfaceType type, void *param)
|
|
{
|
|
int ret = 0;
|
|
switch (type) {
|
|
case InterfaceType::OPEN:
|
|
GnssServiceOpen();
|
|
// ret = tjd_service_gps_open();
|
|
// ret = tjd_service_gnss_open();
|
|
break;
|
|
case InterfaceType::CLOSE:
|
|
GnssServiceClose();
|
|
// tjd_service_gps_close();
|
|
// tjd_service_gnss_close();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
uint8_t TjdUiAppProductModel::GetPower(void) { return tjd_service_charger_get_battery(); }
|
|
|
|
bool TjdUiAppProductModel::GPSIsNormal(void) { return tjd_service_gps_ephemer_is_valid(); }
|
|
|
|
typedef void (*PostEventHandleFunction)(void);
|
|
|
|
static PostEventHandleFunction g_postEventCallback = nullptr;
|
|
static signed int EventHandler(void *param)
|
|
{
|
|
if (g_postEventCallback != nullptr) {
|
|
g_postEventCallback();
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static void PostEventHandle(PostEventHandleFunction event)
|
|
{
|
|
ProductEventInfo g_msg_data = {
|
|
.func_event_handler = EventHandler,
|
|
.param = NULL,
|
|
.func_event_debug = NULL,
|
|
.payload = NULL,
|
|
};
|
|
g_postEventCallback = event;
|
|
static unsigned int g_msg_size = sizeof(ProductEventInfo);
|
|
osal_msg_queue_write_copy(tjd_task_ancillary_get_queue_id(), &g_msg_data, g_msg_size, 0);
|
|
}
|
|
|
|
int TjdUiAppProductModel::PlayerStart()
|
|
{
|
|
PostEventHandle([]() {
|
|
const char *argv[] = {"xx", "/user/call_music.mp3", "1", "0"};
|
|
PlayerSample(ARRAY_SIZE(argv), argv);
|
|
});
|
|
return 0;
|
|
}
|
|
|
|
int TjdUiAppProductModel::PlayerStop()
|
|
{
|
|
PostEventHandle([]() {
|
|
const char *argv[] = {"stop"};
|
|
PlayerSample(ARRAY_SIZE(argv), argv);
|
|
});
|
|
return 0;
|
|
}
|
|
|
|
int TjdUiAppProductModel::SingLoopEnable()
|
|
{
|
|
PostEventHandle([]() {
|
|
const char *argv[] = {"loopon"};
|
|
PlayerSample(ARRAY_SIZE(argv), argv);
|
|
});
|
|
return 0;
|
|
}
|
|
|
|
int TjdUiAppProductModel::SingLoopDisable()
|
|
{
|
|
PostEventHandle([]() {
|
|
const char *argv[] = {"loopoff"};
|
|
PlayerSample(ARRAY_SIZE(argv), argv);
|
|
});
|
|
return 0;
|
|
}
|
|
|
|
} // namespace TJD
|