Update
This commit is contained in:
parent
6bb4845930
commit
c968213ec9
@ -17,7 +17,7 @@
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="gsL-Nw-5C6">
|
||||
<rect key="frame" x="161" y="145" width="91" height="30"/>
|
||||
<rect key="frame" x="303" y="44" width="91" height="30"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<state key="normal" title="TOGGLE LED"/>
|
||||
<connections>
|
||||
@ -26,61 +26,61 @@
|
||||
</connections>
|
||||
</button>
|
||||
<switch opaque="NO" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="dHC-eT-3y1">
|
||||
<rect key="frame" x="217" y="44" width="49" height="31"/>
|
||||
<rect key="frame" x="86" y="44" width="49" height="31"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
</switch>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Debug" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="l2I-9J-rAh">
|
||||
<rect key="frame" x="151" y="49" width="58" height="21"/>
|
||||
<rect key="frame" x="20" y="48" width="58" height="21"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||
<color key="textColor" white="0.63153754340000001" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Pills remaining:" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="eKc-uP-L0m">
|
||||
<rect key="frame" x="78" y="494" width="131" height="24"/>
|
||||
<rect key="frame" x="67" y="572" width="131" height="24"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="20"/>
|
||||
<color key="textColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Pills consumed: " textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="llf-Dy-Aua">
|
||||
<rect key="frame" x="67" y="444" width="142" height="24"/>
|
||||
<rect key="frame" x="56" y="522" width="142" height="24"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="20"/>
|
||||
<color key="textColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="?" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="SZM-0X-3rS">
|
||||
<rect key="frame" x="235" y="444" width="29" height="24"/>
|
||||
<rect key="frame" x="224" y="522" width="58" height="24"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="20"/>
|
||||
<color key="textColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="?" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Sjf-mb-Bwa">
|
||||
<rect key="frame" x="235" y="494" width="29" height="24"/>
|
||||
<rect key="frame" x="224" y="572" width="58" height="24"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="20"/>
|
||||
<color key="textColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="egw-kZ-OI5">
|
||||
<rect key="frame" x="155" y="317" width="102" height="30"/>
|
||||
<rect key="frame" x="162" y="406" width="91" height="30"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<state key="normal" title="Debug: update"/>
|
||||
<state key="normal" title="Force update"/>
|
||||
<connections>
|
||||
<action selector="forcePillRefresh:" destination="BYZ-38-t0r" eventType="touchUpInside" id="UQT-N9-laF"/>
|
||||
</connections>
|
||||
</button>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Total pills" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="enT-hS-KDW">
|
||||
<rect key="frame" x="127" y="402" width="82" height="24"/>
|
||||
<rect key="frame" x="116" y="480" width="82" height="24"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="20"/>
|
||||
<color key="textColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="?" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="RoE-tt-hdb">
|
||||
<rect key="frame" x="235" y="402" width="29" height="24"/>
|
||||
<rect key="frame" x="224" y="480" width="58" height="24"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="20"/>
|
||||
<color key="textColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
@ -100,13 +100,6 @@
|
||||
<color key="textColor" white="0.63153754340000001" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="null" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Ypx-xB-OqG">
|
||||
<rect key="frame" x="179" y="562" width="58" height="21"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||
<color key="textColor" white="0.63153754340000001" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="QDW-f0-1g2">
|
||||
<rect key="frame" x="335" y="831" width="49" height="31"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
@ -121,6 +114,13 @@
|
||||
<color key="textColor" white="0.63153754340000001" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="null" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Ypx-xB-OqG">
|
||||
<rect key="frame" x="178" y="44" width="58" height="21"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||
<color key="textColor" white="0.63153754340000001" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
</subviews>
|
||||
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
|
||||
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
|
||||
@ -139,7 +139,7 @@
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="122" y="119"/>
|
||||
<point key="canvasLocation" x="121.73913043478262" y="118.52678571428571"/>
|
||||
</scene>
|
||||
</scenes>
|
||||
<resources>
|
||||
|
||||
@ -48,14 +48,14 @@ extension SimpleBluetoothIO: CBCentralManagerDelegate {
|
||||
func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
|
||||
peripheral.discoverServices(nil)
|
||||
self.connected = true
|
||||
print("Connected! With \(peripheral.name)")
|
||||
print("Connected! With \(String(describing: peripheral.name))")
|
||||
delegate?.simpleBluetoothIO(simpleBluetoothIO: self, didConnect: true)
|
||||
}
|
||||
|
||||
func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
|
||||
connectedPeripheral = peripheral
|
||||
if (peripheral.name != "[TV] Samsung Q7 Series (55)" && peripheral.name != "MacDeMax"){
|
||||
print("Discovered \(peripheral.name)")
|
||||
print("Discovered \(String(describing: peripheral.name))")
|
||||
}
|
||||
if (peripheral.name != nil) {
|
||||
if(((peripheral.name?.contains("PILL_TRACKER"))!))
|
||||
@ -114,7 +114,7 @@ extension SimpleBluetoothIO: CBPeripheralDelegate {
|
||||
}
|
||||
|
||||
func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: Error?) {
|
||||
print("Disconnected: \(peripheral.name)")
|
||||
print("Disconnected: \(String(describing: peripheral.name))")
|
||||
print("Restarting scan...")
|
||||
centralManager.scanForPeripherals(withServices: nil, options: nil)
|
||||
delegate?.simpleBluetoothIO(simpleBluetoothIO: self, didDisconnect: true)
|
||||
|
||||
@ -21,9 +21,10 @@ class ViewController: UIViewController {
|
||||
@IBOutlet weak var refreshToggle: UISwitch!
|
||||
|
||||
let totalPills: Int = 6
|
||||
var usedPills: Int = 0
|
||||
var remainingPills: Int = 0
|
||||
let updateFreq: Float = 2.0
|
||||
weak var timer: Timer?
|
||||
var pillIndex = [3, 3, 3, 3, 3, 3]
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
@ -53,20 +54,6 @@ class ViewController: UIViewController {
|
||||
timer?.invalidate()
|
||||
}
|
||||
|
||||
func updatePillArray(data: String) {
|
||||
for i in 0...5 {
|
||||
let dataSlice = String(data.character(at: i) ?? "3")
|
||||
let isIntact = Int(dataSlice) ?? 3
|
||||
print("Index: \(i) and value: \(isIntact)")
|
||||
self.pillIndex[i] = isIntact
|
||||
}
|
||||
print("PillIndex: \(self.pillIndex)")
|
||||
}
|
||||
|
||||
func updatePillArrayUI() {
|
||||
|
||||
}
|
||||
|
||||
@IBAction func ledToggleButtonDown(_ sender: UIButton) {
|
||||
simpleBluetoothIO.writeValue(value:49)
|
||||
}
|
||||
@ -104,16 +91,14 @@ extension ViewController: SimpleBluetoothIODelegate {
|
||||
self.pillsTotal.text = "X"
|
||||
self.pillsAttached.text = "Detached"
|
||||
self.pillsAttached.textColor = UIColor.red
|
||||
} else if String(value).prefix(2) == "7" {
|
||||
let remainingPills = Int(value)
|
||||
let usedPills = self.totalPills - remainingPills
|
||||
} else {
|
||||
self.remainingPills = Int(value)
|
||||
self.usedPills = self.totalPills - self.remainingPills
|
||||
self.pillsConsumed.text = String(usedPills)
|
||||
self.pillsRemaining.text = String(remainingPills)
|
||||
self.pillsTotal.text = String(self.totalPills)
|
||||
self.pillsAttached.text = "Attached"
|
||||
self.pillsAttached.textColor = UIColor.green
|
||||
self.updatePillArray(data: String(value))
|
||||
self.updatePillArrayUI()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,16 +1,14 @@
|
||||
#include <BLEDevice.h>
|
||||
#include <BLEUtils.h>
|
||||
#include <BLEServer.h>
|
||||
|
||||
// See the following for generating UUIDs:
|
||||
// https://www.uuidgenerator.net/
|
||||
|
||||
#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
|
||||
#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
|
||||
#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"
|
||||
|
||||
#define LED_PIN 2
|
||||
#define BTN_PIN 5
|
||||
|
||||
#define PILL_1_PIN 25
|
||||
#define PILL_2_PIN 13
|
||||
#define PILL_3_PIN 12
|
||||
@ -19,162 +17,124 @@
|
||||
#define PILL_6_PIN 14
|
||||
#define DETECT_PIN 18
|
||||
|
||||
|
||||
int deviceConnected = false;
|
||||
|
||||
int waitingForUpdate = 0;
|
||||
|
||||
|
||||
class MyCallbacks: public BLECharacteristicCallbacks {
|
||||
void onConnect(BLEServer* pServer) {
|
||||
deviceConnected = true;
|
||||
Serial.println("device connected");
|
||||
};
|
||||
|
||||
void onDisconnect(BLEServer* pServer) {
|
||||
deviceConnected = false;
|
||||
Serial.println("device disconnected");
|
||||
}
|
||||
void onWrite(BLECharacteristic *pCharacteristic) {
|
||||
std::string value = pCharacteristic->getValue();
|
||||
|
||||
if (value.length() > 0) {
|
||||
Serial.print("*********");
|
||||
Serial.print(value.c_str());
|
||||
Serial.print("-");
|
||||
Serial.print(atoi(value.c_str()));
|
||||
Serial.print("-");
|
||||
if(atoi(value.c_str())==1)
|
||||
{
|
||||
digitalWrite(LED_PIN,HIGH);
|
||||
Serial.print("LEDON");
|
||||
}
|
||||
else if (atoi(value.c_str())==2)
|
||||
{
|
||||
digitalWrite(LED_PIN,LOW);
|
||||
Serial.print("LEDOFF");
|
||||
}
|
||||
else if (atoi(value.c_str())==3)
|
||||
{
|
||||
Serial.print("UPDATE_PILL_TRACK");
|
||||
waitingForUpdate = 1;
|
||||
}
|
||||
else {
|
||||
Serial.println();
|
||||
Serial.println(atoi(value.c_str()));
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
Serial.println("*********");
|
||||
}
|
||||
}
|
||||
class MyCallbacks:public BLECharacteristicCallbacks {
|
||||
void onConnect(BLEServer * pServer) {
|
||||
deviceConnected = true;
|
||||
Serial.println("device connected");
|
||||
};
|
||||
void onDisconnect(BLEServer * pServer) {
|
||||
deviceConnected = false;
|
||||
Serial.println("device disconnected");
|
||||
}
|
||||
void onWrite(BLECharacteristic * pCharacteristic) {
|
||||
std::string value = pCharacteristic -> getValue();
|
||||
if (value.length() > 0) {
|
||||
Serial.print("*********");
|
||||
Serial.print(value.c_str());
|
||||
Serial.print("-");
|
||||
Serial.print(atoi(value.c_str()));
|
||||
Serial.print("-");
|
||||
if (atoi(value.c_str()) == 1) {
|
||||
digitalWrite(LED_PIN, HIGH);
|
||||
Serial.print("LEDON");
|
||||
} else if (atoi(value.c_str()) == 2) {
|
||||
digitalWrite(LED_PIN, LOW);
|
||||
Serial.print("LEDOFF");
|
||||
} else if (atoi(value.c_str()) == 3) {
|
||||
Serial.print("UPDATE_PILL_TRACK");
|
||||
waitingForUpdate = 1;
|
||||
} else {
|
||||
Serial.println();
|
||||
Serial.println(atoi(value.c_str()));
|
||||
Serial.println();
|
||||
}
|
||||
Serial.println("*********");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
BLECharacteristic *pCharacteristic;
|
||||
BLECharacteristic * pCharacteristic;
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
pinMode(LED_PIN,OUTPUT);
|
||||
|
||||
pinMode(PILL_1_PIN,INPUT_PULLUP);
|
||||
pinMode(PILL_2_PIN,INPUT_PULLUP);
|
||||
pinMode(PILL_3_PIN,INPUT_PULLUP);
|
||||
pinMode(PILL_4_PIN,INPUT_PULLUP);
|
||||
pinMode(PILL_5_PIN,INPUT_PULLUP);
|
||||
pinMode(PILL_6_PIN,INPUT_PULLUP);
|
||||
|
||||
pinMode(BTN_PIN,INPUT_PULLUP);
|
||||
pinMode(DETECT_PIN,INPUT_PULLUP);
|
||||
|
||||
|
||||
digitalWrite(LED_PIN,LOW);
|
||||
Serial.println("1- Download and install an BLE scanner app in your phone");
|
||||
Serial.println("2- Scan for BLE devices in the app");
|
||||
Serial.println("3- Connect to MyESP32");
|
||||
Serial.println("4- Go to CUSTOM CHARACTERISTIC in CUSTOM SERVICE and write something");
|
||||
Serial.println("5- See the magic =)");
|
||||
|
||||
BLEDevice::init("PILL_TRACKER");
|
||||
BLEServer *pServer = BLEDevice::createServer();
|
||||
|
||||
BLEService *pService = pServer->createService(SERVICE_UUID);
|
||||
|
||||
pCharacteristic= pService->createCharacteristic(
|
||||
CHARACTERISTIC_UUID,
|
||||
BLECharacteristic::PROPERTY_READ |
|
||||
BLECharacteristic::PROPERTY_WRITE |
|
||||
BLECharacteristic::PROPERTY_NOTIFY
|
||||
);
|
||||
|
||||
pCharacteristic->setCallbacks(new MyCallbacks());
|
||||
|
||||
pCharacteristic->setValue("Hello World");
|
||||
pService->start();
|
||||
|
||||
BLEAdvertising *pAdvertising = pServer->getAdvertising();
|
||||
pAdvertising->start();
|
||||
Serial.begin(115200);
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
pinMode(PILL_1_PIN, INPUT_PULLUP);
|
||||
pinMode(PILL_2_PIN, INPUT_PULLUP);
|
||||
pinMode(PILL_3_PIN, INPUT_PULLUP);
|
||||
pinMode(PILL_4_PIN, INPUT_PULLUP);
|
||||
pinMode(PILL_5_PIN, INPUT_PULLUP);
|
||||
pinMode(PILL_6_PIN, INPUT_PULLUP);
|
||||
pinMode(BTN_PIN, INPUT_PULLUP);
|
||||
pinMode(DETECT_PIN, INPUT_PULLUP);
|
||||
digitalWrite(LED_PIN, LOW);
|
||||
Serial.println("1- Download and install an BLE scanner app in your phone");
|
||||
Serial.println("2- Scan for BLE devices in the app");
|
||||
Serial.println("3- Connect to MyESP32");
|
||||
Serial.println("4- Go to CUSTOM CHARACTERISTIC in CUSTOM SERVICE and write something");
|
||||
Serial.println("5- See the magic =)");
|
||||
BLEDevice::init("PILL_TRACKER");
|
||||
BLEServer * pServer = BLEDevice::createServer();
|
||||
BLEService * pService = pServer -> createService(SERVICE_UUID);
|
||||
pCharacteristic = pService -> createCharacteristic(
|
||||
CHARACTERISTIC_UUID,
|
||||
BLECharacteristic::PROPERTY_READ |
|
||||
BLECharacteristic::PROPERTY_WRITE |
|
||||
BLECharacteristic::PROPERTY_NOTIFY
|
||||
);
|
||||
pCharacteristic -> setCallbacks(new MyCallbacks());
|
||||
pCharacteristic -> setValue("Hello World");
|
||||
pService -> start();
|
||||
BLEAdvertising * pAdvertising = pServer -> getAdvertising();
|
||||
pAdvertising -> start();
|
||||
}
|
||||
|
||||
int prevVal = LOW;
|
||||
int prevVal2 = LOW;
|
||||
|
||||
int getPillCount() {
|
||||
String bay0Intact = "0";
|
||||
String bay1Intact = "0";
|
||||
String bay2Intact = "0";
|
||||
String bay3Intact = "0";
|
||||
String bay4Intact = "0";
|
||||
String bay5Intact = "0";
|
||||
String result = "7";
|
||||
|
||||
if(digitalRead(DETECT_PIN) == LOW) {
|
||||
Serial.println("PROBE_ATTACHED");
|
||||
if(digitalRead(PILL_1_PIN) == LOW){bay0Intact = "1";Serial.println("25:FULL");}
|
||||
if(digitalRead(PILL_2_PIN) == LOW){bay1Intact = "1";Serial.println("13:FULL");}
|
||||
if(digitalRead(PILL_3_PIN) == LOW){bay2Intact = "1";Serial.println("12:FULL");}
|
||||
if(digitalRead(PILL_4_PIN) == LOW){bay3Intact = "1";Serial.println("26:FULL");}
|
||||
if(digitalRead(PILL_5_PIN) == LOW){bay4Intact = "1";Serial.println("27:FULL");}
|
||||
if(digitalRead(PILL_6_PIN) == LOW){bay5Intact = "1";Serial.println("14:FULL");}
|
||||
result = result + bay0Intact + bay1Intact + bay2Intact + bay3Intact + bay4Intact + bay5Intact;
|
||||
Serial.println("**********RESULT**********");
|
||||
Serial.println(result);
|
||||
Serial.println("**********RESULT**********");
|
||||
}
|
||||
else {
|
||||
Serial.println("PROBE_DETACHED");
|
||||
result = "55";
|
||||
}
|
||||
Serial.print("#########################################Sending: ");
|
||||
Serial.println(result.toInt());
|
||||
return result.toInt();
|
||||
int totalCount = 0;
|
||||
if (digitalRead(DETECT_PIN) == LOW) {
|
||||
Serial.println("PROBE_ATTACHED");
|
||||
if (digitalRead(PILL_1_PIN) == LOW){totalCount++;Serial.println("25:FULL");}
|
||||
if (digitalRead(PILL_2_PIN) == LOW){totalCount++;Serial.println("13:FULL");}
|
||||
if (digitalRead(PILL_3_PIN) == LOW){totalCount++;Serial.println("12:FULL");}
|
||||
if (digitalRead(PILL_4_PIN) == LOW){totalCount++;Serial.println("26:FULL");}
|
||||
if (digitalRead(PILL_5_PIN) == LOW){totalCount++;Serial.println("27:FULL");}
|
||||
if (digitalRead(PILL_6_PIN) == LOW){totalCount++;Serial.println("14:FULL");}
|
||||
} else {
|
||||
Serial.println("PROBE_DETACHED");
|
||||
totalCount = 55;
|
||||
}
|
||||
return totalCount;
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly:
|
||||
|
||||
int currentVal = digitalRead(BTN_PIN);
|
||||
if(currentVal!=prevVal)
|
||||
{
|
||||
prevVal=currentVal;
|
||||
if(currentVal==HIGH)
|
||||
{
|
||||
int value = 99;
|
||||
pCharacteristic->setValue((uint8_t*)&value, 4);
|
||||
pCharacteristic->notify();
|
||||
}
|
||||
else
|
||||
{
|
||||
int value = 98;
|
||||
pCharacteristic->setValue((uint8_t*)&value, 4);
|
||||
pCharacteristic->notify();
|
||||
}
|
||||
}
|
||||
|
||||
if(waitingForUpdate == 1){
|
||||
Serial.println("**********************************");
|
||||
Serial.println("**************UPDATE AND SEND PILL COUNT********************");
|
||||
Serial.println("**********************************");
|
||||
waitingForUpdate = 0;
|
||||
int value = getPillCount();
|
||||
pCharacteristic->setValue((uint8_t*)&value, 4);
|
||||
pCharacteristic->notify();
|
||||
}
|
||||
// put your main code here, to run repeatedly:
|
||||
int currentVal = digitalRead(BTN_PIN);
|
||||
if (currentVal != prevVal) {
|
||||
prevVal = currentVal;
|
||||
if (currentVal == HIGH) {
|
||||
int value = 99;
|
||||
pCharacteristic -> setValue((uint8_t *) & value, 4);
|
||||
pCharacteristic -> notify();
|
||||
}
|
||||
else {
|
||||
int value = 98;
|
||||
pCharacteristic -> setValue((uint8_t *) & value, 4);
|
||||
pCharacteristic -> notify();
|
||||
}
|
||||
}
|
||||
if (waitingForUpdate == 1) {
|
||||
Serial.println("************************************************************");
|
||||
Serial.println("**************UPDATE AND SEND PILL COUNT********************");
|
||||
Serial.println("************************************************************");
|
||||
waitingForUpdate = 0;
|
||||
int value = getPillCount();
|
||||
pCharacteristic -> setValue((uint8_t *) & value, 4);
|
||||
pCharacteristic -> notify();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user