Skip to content

Commit

Permalink
Improve library functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesSmartCell committed May 14, 2023
1 parent e062ff9 commit 12214b4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "AugustESP32",
"version": "1.0.1",
"version": "1.1",
"description": "August Lock Bluetooth interface for ESP32 family",
"repository": {
"url": "https://github.com/JamesSmartCell/AugustESP32.git",
Expand Down
21 changes: 17 additions & 4 deletions src/august.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ void AugustLock::lockAction(LockAction action)

void AugustLock::closeConnection()
{
AUGUST_LOG("Close Connection");
if (pWriteHandshake->canWrite())
{
uint8_t *cmd = BuildCommand(0x05);
Expand All @@ -98,6 +99,7 @@ void AugustLock::closeConnection()
}
else
{
AUGUST_LOG("Call disconnect");
pClient->disconnect();
}

Expand Down Expand Up @@ -131,6 +133,7 @@ void AugustLock::lockCommand(LockAction action)
}
else
{
AUGUST_LOG("Call disconnect");
pClient->disconnect();
}
}
Expand Down Expand Up @@ -158,6 +161,7 @@ void AugustLock::getStatus()
}
else
{
AUGUST_LOG("Call disconnect");
pClient->disconnect();
}
}
Expand Down Expand Up @@ -290,6 +294,7 @@ bool AugustLock::connectToServer()
}
else
{
AUGUST_LOG("Call disconnect");
pClient->disconnect();
return false;
}
Expand Down Expand Up @@ -437,6 +442,7 @@ void AugustLock::_notifyCB(NimBLERemoteCharacteristic *pRemoteCharacteristic, ui
}
else
{
AUGUST_LOG("Call disconnect");
pClient->disconnect();
}
}
Expand All @@ -456,6 +462,10 @@ void AugustLock::_notifyCB(NimBLERemoteCharacteristic *pRemoteCharacteristic, ui
case TOGGLE_LOCK:
getStatus();
break;
case ESTABLISH_CONNECTION:
connectCallback("Connected", false);
//Wait for further instructions
break;
}
}
else
Expand All @@ -481,19 +491,22 @@ void AugustLock::_secureLockCallback(NimBLERemoteCharacteristic *pRemoteCharacte
connectCallback("Unlocked", false);
if (actionAfterSync == TOGGLE_LOCK)
lockCommand(LOCK);
else
else if (!actionAfterSync == ESTABLISH_CONNECTION)
closeConnection();
}
else if (status == 0x05)
{
connectCallback("Locked", true);
if (actionAfterSync == TOGGLE_LOCK)
lockCommand(UNLOCK);
else
else if (!actionAfterSync == ESTABLISH_CONNECTION)
closeConnection();
}

actionAfterSync = GET_STATUS;
else if (status == 0xEF)
{
if (actionAfterSync == ESTABLISH_CONNECTION)
getStatus();
}
}

//
Expand Down
8 changes: 5 additions & 3 deletions src/august.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ typedef enum LockAction
GET_STATUS,
LOCK,
UNLOCK,
TOGGLE_LOCK
TOGGLE_LOCK,
ESTABLISH_CONNECTION
} LockAction;

class AugustLock
Expand All @@ -49,10 +50,11 @@ class AugustLock
void setDiscoveredLock(NimBLEAdvertisedDevice *advDev) { advDevice = advDev; doConnect = true; }
void blankClient() { pClient = nullptr; }

private:
void resetCrypto();
void lockCommand(LockAction action);
void closeConnection();

private:
void resetCrypto();
bool connectToServer();
void scanForService();

Expand Down

0 comments on commit 12214b4

Please sign in to comment.