Skip to content

Commit

Permalink
Address review comments cleaning up code
Browse files Browse the repository at this point in the history
  • Loading branch information
praveenCY committed Aug 9, 2021
1 parent 19f3348 commit fe3f6ae
Show file tree
Hide file tree
Showing 21 changed files with 198 additions and 410 deletions.
3 changes: 3 additions & 0 deletions examples/lock-app/p6/include/AppConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,7 @@ void P6Log(const char * aFormat, ...);

#ifdef __cplusplus
}

#include <core/CHIPError.h>
void appError(CHIP_ERROR error);
#endif
36 changes: 22 additions & 14 deletions examples/lock-app/p6/include/AppTask.h
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,22 @@
#include <ble/BLEEndPoint.h>
#include <platform/CHIPDeviceLayer.h>

// Application-defined error codes in the CHIP_ERROR space.
#define APP_ERROR_EVENT_QUEUE_FAILED CHIP_APPLICATION_ERROR(0x01)
#define APP_ERROR_CREATE_TASK_FAILED CHIP_APPLICATION_ERROR(0x02)
#define APP_ERROR_UNHANDLED_EVENT CHIP_APPLICATION_ERROR(0x03)
#define APP_ERROR_CREATE_TIMER_FAILED CHIP_APPLICATION_ERROR(0x04)
#define APP_ERROR_START_TIMER_FAILED CHIP_APPLICATION_ERROR(0x05)
#define APP_ERROR_STOP_TIMER_FAILED CHIP_APPLICATION_ERROR(0x06)

class AppTask
{

public:
int StartAppTask();
CHIP_ERROR StartAppTask();
static void AppTaskMain(void * pvParameter);

void PostLockActionRequest(int32_t aActor, BoltLockManager::Action_t aAction);
void PostLockActionRequest(int32_t actor, BoltLockManager::Action action);
void PostEvent(const AppEvent * event);

void ButtonEventHandler(uint8_t btnIdx, uint8_t btnAction);
Expand All @@ -46,35 +54,35 @@ class AppTask
private:
friend AppTask & GetAppTask(void);

int Init();
CHIP_ERROR Init();

static void ActionInitiated(BoltLockManager::Action_t aAction, int32_t aActor);
static void ActionCompleted(BoltLockManager::Action_t aAction);
static void ActionInitiated(BoltLockManager::Action action, int32_t actor);
static void ActionCompleted(BoltLockManager::Action action);

void CancelTimer(void);

void DispatchEvent(AppEvent * event);

static void FunctionTimerEventHandler(AppEvent * aEvent);
static void FunctionHandler(AppEvent * aEvent);
static void LockActionEventHandler(AppEvent * aEvent);
static void TimerEventHandler(TimerHandle_t xTimer);
static void FunctionTimerEventHandler(AppEvent * event);
static void FunctionHandler(AppEvent * event);
static void LockActionEventHandler(AppEvent * event);
static void TimerEventHandler(TimerHandle_t timer);

void StartTimer(uint32_t aTimeoutMs);

enum Function_t
enum class Function
{
kFunction_NoneSelected = 0,
kFunction_SoftwareUpdate = 0,
kFunction_StartBleAdv = 1,
kFunction_FactoryReset = 2,

kFunction_Invalid
} Function;
};

Function_t mFunction;
bool mFunctionTimerActive;
bool mSyncClusterToButtonAction;
Function mFunction = Function::kFunction_Invalid;
bool mFunctionTimerActive = false;
bool mSyncClusterToButtonAction = false;

static AppTask sAppTask;
};
Expand Down
32 changes: 17 additions & 15 deletions examples/lock-app/p6/include/BoltLockManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,46 +27,48 @@
#include "FreeRTOS.h"
#include "timers.h" // provides FreeRTOS timer support

#include <core/CHIPError.h>

class BoltLockManager
{
public:
enum Action_t
enum class Action
{
LOCK_ACTION = 0,
UNLOCK_ACTION,
kLock = 0,
kUnlock,

INVALID_ACTION
} Action;
KInvalid
};

enum State_t
enum class State
{
kState_LockingInitiated = 0,
kState_LockingCompleted,
kState_UnlockingInitiated,
kState_UnlockingCompleted,
} State;
};

int Init();
CHIP_ERROR Init();
bool IsUnlocked();
void EnableAutoRelock(bool aOn);
void SetAutoLockDuration(uint32_t aDurationInSecs);
bool IsActionInProgress();
bool InitiateAction(int32_t aActor, Action_t aAction);
bool InitiateAction(int32_t aActor, Action aAction);

typedef void (*Callback_fn_initiated)(Action_t, int32_t aActor);
typedef void (*Callback_fn_completed)(Action_t);
typedef void (*Callback_fn_initiated)(Action, int32_t aActor);
typedef void (*Callback_fn_completed)(Action);
void SetCallbacks(Callback_fn_initiated aActionInitiated_CB, Callback_fn_completed aActionCompleted_CB);

private:
friend BoltLockManager & BoltLockMgr(void);
State_t mState;
State mState = State::kState_LockingCompleted;

Callback_fn_initiated mActionInitiated_CB;
Callback_fn_completed mActionCompleted_CB;

bool mAutoRelock;
uint32_t mAutoLockDuration;
bool mAutoLockTimerArmed;
bool mAutoRelock = false;
uint32_t mAutoLockDuration = 0;
bool mAutoLockTimerArmed = false;

void CancelTimer(void);
void StartTimer(uint32_t aTimeoutMs);
Expand Down
Loading

0 comments on commit fe3f6ae

Please sign in to comment.