I am writing code for the double-tap event but it's not working perfectly so I think that configuring the below internal registers might help to get better results:
To set the value of the registers, I'm using ADB bridge via the Movesense showcase adb bridge app. here is the Link of the APK:Showcaseapp-debug_adb-bridge-build.apk
I use the below command to read and write double-tap parameters. and it's working.
for read:
adb.exe shell am broadcast -a "android.intent.action.MOVESENSE" --es type get --es path Component/LSM6DS3/TapParams --es value '''{}'''
for write:
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}}'''
To set these parameters internally (inside code), I wrote a function DoubleTAPConfig(), which sets the value in params. But it's not working. I am not sure what I'm missing. Any help would be greatly appreciated.
Here is my code:-
#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);
// break;
}
else
{
DOUBLETAPEnabled = false;
// break;
}
}
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);
}
I am not sure what I'm missing. Any help would be greatly appreciated.
The /Component/LSM6DS3/TapParams -resource accessed the LSM6 chip registers directly, so in your firmware code the following happens:
You'll need to:
Full disclosure: I work for the Movesense team