-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added withResponse option to account for new ESP32 behavior
- Loading branch information
Laurence Bank
authored and
Laurence Bank
committed
Aug 22, 2021
1 parent
e0d51b2
commit 262d203
Showing
2 changed files
with
65 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,18 +5,18 @@ | |
// Written by Larry Bank ([email protected]) | ||
// Project started 1/6/2020 | ||
// | ||
// Copyright 2020 BitBank Software, Inc. All Rights Reserved. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
//=========================================================================== | ||
|
||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
// | ||
#include <Arduino.h> | ||
// uncomment this line to see debug info on the serial monitor | ||
|
@@ -27,7 +27,7 @@ | |
#include <BLEDevice.h> | ||
#endif | ||
|
||
#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_ARDUINO_NANO33BLE) | ||
#ifdef ARDUINO_ARDUINO_NANO33BLE | ||
#include <ArduinoBLE.h> | ||
#endif | ||
|
||
|
@@ -42,6 +42,7 @@ static int bb_width, bb_height; // back buffer width and height in pixels | |
static int tp_wrap, bb_pitch; | ||
static int iCursorX = 0; | ||
static int iCursorY = 0; | ||
static uint8_t bWithResponse = 1; // default to wait for response | ||
static uint8_t *pBackBuffer = NULL; | ||
static uint8_t bConnected = 0; | ||
static void tpWriteData(uint8_t *pData, int iLen); | ||
|
@@ -152,12 +153,17 @@ static BLEClient* pClient; | |
static char Scanned_BLE_Name[32]; | ||
#endif | ||
|
||
#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_ARDUINO_NANO33BLE) | ||
#ifdef ARDUINO_ARDUINO_NANO33BLE | ||
static BLEDevice peripheral; | ||
static BLEService prtService; | ||
static BLECharacteristic pRemoteCharacteristicData; | ||
#endif | ||
|
||
void tpSetWriteMode(uint8_t bWriteMode) | ||
{ | ||
bWithResponse = bWriteMode; | ||
} /* tpSetWriteMode() */ | ||
|
||
#ifdef HAL_ESP32_HAL_H_ | ||
// Called for each device found during a BLE scan by the client | ||
class tpAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks | ||
|
@@ -389,7 +395,22 @@ uint8_t bFlipped = false; | |
} // for y | ||
return 0; | ||
} /* tpLoadBMP() */ | ||
|
||
// | ||
// Connection status | ||
// true = connected, false = disconnected | ||
// | ||
int tpIsConnected(void) | ||
{ | ||
if (bConnected == 1) { | ||
// we are/were connected, check... | ||
#ifdef HAL_ESP32_HAL_H_ | ||
if (pClient && pClient->isConnected()) | ||
return 1; | ||
bConnected = 0; // change status to disconnected | ||
#endif // ESP32 | ||
} | ||
return 0; // not connected | ||
} /* tpIsConnected() */ | ||
// | ||
// After a successful scan, connect to the printer | ||
// returns 1 if successful, 0 for failure | ||
|
@@ -433,7 +454,7 @@ int tpConnect(void) | |
} | ||
return 0; | ||
#endif | ||
#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_ARDUINO_NANO33BLE) // Arduino BLE | ||
#ifdef ARDUINO_ARDUINO_NANO33BLE // Arduino BLE | ||
if (!peripheral) | ||
{ | ||
#ifdef DEBUG_OUTPUT | ||
|
@@ -515,7 +536,7 @@ void tpDisconnect(void) | |
bConnected = 0; | ||
} | ||
#endif | ||
#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_ARDUINO_NANO33BLE) | ||
#ifdef ARDUINO_ARDUINO_NANO33BLE | ||
if (peripheral && bConnected) | ||
{ | ||
if (peripheral.connected()) | ||
|
@@ -576,7 +597,7 @@ int iLen = strlen(szName); | |
} | ||
} | ||
#endif | ||
#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_ARDUINO_NANO33BLE) // Arduino API | ||
#ifdef ARDUINO_ARDUNIO_NANO33BLE // Arduino API | ||
// initialize the BLE hardware | ||
BLE.begin(); | ||
// start scanning for the printer service UUID | ||
|
@@ -668,10 +689,10 @@ static void tpWriteData(uint8_t *pData, int iLen) | |
// Write BLE data without response, otherwise the printer | ||
// stutters and takes much longer to print | ||
#ifdef HAL_ESP32_HAL_H_ | ||
pRemoteCharacteristicData->writeValue(pData, iLen, false); | ||
pRemoteCharacteristicData->writeValue(pData, iLen, bWithResponse); | ||
#endif | ||
#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_ARDUINO_NANO33BLE) | ||
pRemoteCharacteristicData.writeValue(pData, iLen); | ||
#ifdef ARDUINO_ARDUINO_NANO33BLE | ||
pRemoteCharacteristicData.writeValue(pData, iLen, bWithResponse); | ||
#endif | ||
#ifdef ARDUINO_NRF52_ADAFRUIT | ||
myDataChar.write((const void *)pData, (uint16_t)iLen); | ||
|
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