forked from InfiniTimeOrg/InfiniTime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/develop' into pts-settings
- Loading branch information
Showing
26 changed files
with
516 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Motion Service | ||
## Introduction | ||
The motion service exposes step count and raw X/Y/Z motion value as READ and NOTIFY characteristics. | ||
|
||
## Service | ||
The service UUID is **00020000-78fc-48fe-8e23-433b3a1942d0** | ||
|
||
## Characteristics | ||
### Step count (UUID 00020001-78fc-48fe-8e23-433b3a1942d0) | ||
The current number of steps represented as a single `uint32_t` (4 bytes) value. | ||
|
||
### Raw motion values (UUID 00020002-78fc-48fe-8e23-433b3a1942d0) | ||
The current raw motion values. This is a 3 `int16_t` array: | ||
|
||
- [0] : X | ||
- [1] : Y | ||
- [2] : Z |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#pragma once | ||
|
||
namespace Pinetime { | ||
namespace Controllers { | ||
enum class ButtonActions { None, Click, DoubleClick, LongPress, LongerPress }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#include "ButtonHandler.h" | ||
|
||
using namespace Pinetime::Controllers; | ||
|
||
void ButtonTimerCallback(TimerHandle_t xTimer) { | ||
auto* sysTask = static_cast<Pinetime::System::SystemTask*>(pvTimerGetTimerID(xTimer)); | ||
sysTask->PushMessage(Pinetime::System::Messages::HandleButtonTimerEvent); | ||
} | ||
|
||
void ButtonHandler::Init(Pinetime::System::SystemTask* systemTask) { | ||
buttonTimer = xTimerCreate("buttonTimer", 0, pdFALSE, systemTask, ButtonTimerCallback); | ||
} | ||
|
||
ButtonActions ButtonHandler::HandleEvent(Events event) { | ||
static constexpr TickType_t doubleClickTime = pdMS_TO_TICKS(200); | ||
static constexpr TickType_t longPressTime = pdMS_TO_TICKS(400); | ||
static constexpr TickType_t longerPressTime = pdMS_TO_TICKS(2000); | ||
|
||
if (event == Events::Press) { | ||
buttonPressed = true; | ||
} else if (event == Events::Release) { | ||
releaseTime = xTaskGetTickCount(); | ||
buttonPressed = false; | ||
} | ||
|
||
switch (state) { | ||
case States::Idle: | ||
if (event == Events::Press) { | ||
xTimerChangePeriod(buttonTimer, doubleClickTime, 0); | ||
xTimerStart(buttonTimer, 0); | ||
state = States::Pressed; | ||
} | ||
break; | ||
case States::Pressed: | ||
if (event == Events::Press) { | ||
if (xTaskGetTickCount() - releaseTime < doubleClickTime) { | ||
xTimerStop(buttonTimer, 0); | ||
state = States::Idle; | ||
return ButtonActions::DoubleClick; | ||
} | ||
} else if (event == Events::Release) { | ||
xTimerChangePeriod(buttonTimer, doubleClickTime, 0); | ||
xTimerStart(buttonTimer, 0); | ||
} else if (event == Events::Timer) { | ||
if (buttonPressed) { | ||
xTimerChangePeriod(buttonTimer, longPressTime - doubleClickTime, 0); | ||
xTimerStart(buttonTimer, 0); | ||
state = States::Holding; | ||
} else { | ||
state = States::Idle; | ||
return ButtonActions::Click; | ||
} | ||
} | ||
break; | ||
case States::Holding: | ||
if (event == Events::Release) { | ||
xTimerStop(buttonTimer, 0); | ||
state = States::Idle; | ||
return ButtonActions::Click; | ||
} else if (event == Events::Timer) { | ||
xTimerChangePeriod(buttonTimer, longerPressTime - longPressTime - doubleClickTime, 0); | ||
xTimerStart(buttonTimer, 0); | ||
state = States::LongHeld; | ||
return ButtonActions::LongPress; | ||
} | ||
break; | ||
case States::LongHeld: | ||
if (event == Events::Release) { | ||
xTimerStop(buttonTimer, 0); | ||
state = States::Idle; | ||
} else if (event == Events::Timer) { | ||
state = States::Idle; | ||
return ButtonActions::LongerPress; | ||
} | ||
break; | ||
} | ||
return ButtonActions::None; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#pragma once | ||
|
||
#include "ButtonActions.h" | ||
#include "systemtask/SystemTask.h" | ||
#include <FreeRTOS.h> | ||
#include <timers.h> | ||
|
||
namespace Pinetime { | ||
namespace Controllers { | ||
class ButtonHandler { | ||
public: | ||
enum class Events : uint8_t { Press, Release, Timer }; | ||
void Init(Pinetime::System::SystemTask* systemTask); | ||
ButtonActions HandleEvent(Events event); | ||
|
||
private: | ||
enum class States : uint8_t { Idle, Pressed, Holding, LongHeld }; | ||
TickType_t releaseTime = 0; | ||
TimerHandle_t buttonTimer; | ||
bool buttonPressed = false; | ||
States state = States::Idle; | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.