You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法通过内部代码配置Movesense双击参数,寻求技术协助

Movesense双击事件参数配置代码失效排查

问题背景

开发Movesense设备的双击事件功能时,效果不理想,确认通过配置以下内部寄存器可优化效果:

  • doubleTapDur
  • doubleTapQuiet
  • tapThs
  • axes

通过Movesense Showcase ADB桥接APP使用ADB命令可正常读写这些参数,但自行编写的DoubleTAPConfig()函数设置参数时无法生效,需排查原因。

有效ADB命令

读取参数命令

adb.exe shell am broadcast -a "android.intent.action.MOVESENSE"  --es type get --es path Component/LSM6DS3/TapParams --es value '''{}'''

写入参数命令

adb.exe shell am broadcast -a "android.intent.action.MOVESENSE"  --es type put --es path Component/LSM6DS3/TapParams --es value '''{\"newParams\":{\"doubleTapDur\": 8, \"doubleTapQuiet\": 3, \"tapThs\": 8, \"axes\": 8}}'''

失效的代码实现

#include "DOUBLETAP.h"
#include "common/core/debug.h"
#include "component_led/resources.h"
#include "component_lsm6ds3/resources.h"
#include "movesense.h"
#include "system_mode/resources.h"
#include "system_states/resources.h"
#include "ui_ind/resources.h"

const size_t BLINK_PERIOD_MS = 1000;
#define AVAILABILITY_TIME 5000

// LED blinking period in adertsing mode
#define LED_BLINKING_PERIOD 100

const char* const DOUBLETAP::LAUNCHABLE_NAME = "DOUBLETAP";

DOUBLETAP::DOUBLETAP()
    : ResourceClient(WBDEBUG_NAME(__FUNCTION__), WB_EXEC_CTX_APPLICATION),
      LaunchableModule(LAUNCHABLE_NAME, WB_EXEC_CTX_APPLICATION),
      DOUBLETAPEnabled(false),
      mTimer(wb::ID_INVALID_TIMER),
      mCounter(0)
{
}

DOUBLETAP::~DOUBLETAP()
{
}

bool DOUBLETAP::initModule()
{
    DEBUGLOG("DOUBLETAP::initModule");
    this->mModuleState = WB_RES::ModuleStateValues::INITIALIZED;
    return true;
}

void DOUBLETAP::deinitModule()
{
    DEBUGLOG("DOUBLETAP::deinitModule");
    this->mModuleState = WB_RES::ModuleStateValues::UNINITIALIZED;
}

bool DOUBLETAP::startModule()
{
    DEBUGLOG("DOUBLETAP::startModule");
    this->mModuleState = WB_RES::ModuleStateValues::STARTED;
    this->mTimer = startTimer(BLINK_PERIOD_MS, true); // Start LED timer. true = trigger repeatedly

    // set internal resistor value for doubletap mode
    DoubleTAPConfig();
    // Subscribe to DOUBLETAP detection
    this->asyncSubscribe(WB_RES::LOCAL::SYSTEM_STATES_STATEID(), AsyncRequestOptions::Empty, WB_RES::StateIdValues::DOUBLETAP);

    return true;
}

void DOUBLETAP::stopModule()
{
    DEBUGLOG("DOUBLETAP::stopModule");
    this->stopTimer(mTimer); // Stop LED timer
    this->mTimer = wb::ID_INVALID_TIMER;

    // Unsubscribe DOUBLETAP detection
    this->asyncUnsubscribe(WB_RES::LOCAL::SYSTEM_STATES_STATEID(), AsyncRequestOptions::Empty, WB_RES::StateIdValues::DOUBLETAP);
    this->mModuleState = WB_RES::ModuleStateValues::STOPPED;
}

void DOUBLETAP::onTimer(wb::TimerId timerId)
{
    if (DOUBLETAPEnabled)
    {
        this->asyncPut(WB_RES::LOCAL::UI_IND_VISUAL(), AsyncRequestOptions::Empty, WB_RES::VisualIndTypeValues::SHORT_VISUAL_INDICATION);
    }
    else
    {
        DOUBLETAPEnabled = false;
    }
}

void DOUBLETAP::onNotify(wb::ResourceId resourceId, const wb::Value& value, const wb::ParameterList& parameters)
{
    DEBUGLOG("DOUBLETAP::onNotify");
    switch (resourceId.localResourceId)
    {
    case WB_RES::LOCAL::SYSTEM_STATES_STATEID::LID: {
        const WB_RES::StateChange& stateChange = value.convertTo<const WB_RES::StateChange&>();
        if (stateChange.stateId == WB_RES::StateIdValues::DOUBLETAP)
        {
            DEBUGLOG("Lead state updated. newState: %d", stateChange.newState);
            DOUBLETAPEnabled = !DOUBLETAPEnabled;
        }
    }
    }
}

void DOUBLETAP::DoubleTAPConfig()
{
    WB_RES::TapParams TapConfig;

    TapConfig.doubleTapDur = 8;   // set 0-15   Default:_ 0000
    TapConfig.doubleTapQuiet = 3; // set 0-3    Default value:_ 00
    TapConfig.tapThs = 8;         // set 0-31    Default value:_ 00000
    TapConfig.axes = 8;           // set 0-14   bitfield:_ x=8, y=4, z=2

    asyncPut(WB_RES::LOCAL::COMPONENT_LSM6DS3_TAPPARAMS(), AsyncRequestOptions::Empty, TapConfig);
    
    // also try with this coomund line 
   // asyncPut(WB_RES::LOCAL::COMPONENT_LSM6DS3_WAKEUP(),AsyncRequestOptions(NULL, 0, true), TapConfig);
}

排查方向

  1. 添加异步请求结果回调:当前代码仅调用asyncPut但未处理请求结果,需实现onPutResult方法捕获错误信息,排查参数是否提交成功:
void DOUBLETAP::onPutResult(wb::RequestId requestId, wb::ResourceId resourceId, const wb::Value& result, const wb::Error& error)
{
    if (error.code != wb::HTTP_CODE_OK)
    {
        DEBUGLOG("Put TapParams failed! Error code: %d, message: %s", error.code, error.message.c_str());
    }
    else
    {
        DEBUGLOG("TapParams updated successfully");
    }
}
  1. 匹配参数结构格式:ADB命令中参数包裹在newParams对象内,代码直接传递TapConfig结构体可能不符合资源要求,尝试构造包含外层newParams的Value对象:
wb::Value tapValue;
tapValue["newParams"] = TapConfig;
asyncPut(WB_RES::LOCAL::COMPONENT_LSM6DS3_TAPPARAMS(), AsyncRequestOptions::Empty, tapValue);
  1. 确认资源路径正确性:核对WB_RES::LOCAL::COMPONENT_LSM6DS3_TAPPARAMS()是否与ADB使用的Component/LSM6DS3/TapParams资源端点完全映射。

  2. 调整配置调用时机:startModule中调用DoubleTAPConfig()时传感器可能未完成初始化,尝试延迟调用或在传感器就绪事件触发后再配置参数。

  3. 移除错误的资源调用:注释中的COMPONENT_LSM6DS3_WAKEUP()资源与TapParams为不同端点,无法混用TapConfig结构体,需删除该尝试代码。

内容的提问来源于stack exchange,提问作者Govind Padhiyar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 13:35:18