Update
This commit is contained in:
parent
84737a1a89
commit
b9ad917346
@ -9,7 +9,7 @@ import UIKit
|
|||||||
|
|
||||||
class ViewController: UIViewController {
|
class ViewController: UIViewController {
|
||||||
var simpleBluetoothIO: SimpleBluetoothIO!
|
var simpleBluetoothIO: SimpleBluetoothIO!
|
||||||
|
|
||||||
@IBOutlet var virtualButton:UISwitch!
|
@IBOutlet var virtualButton:UISwitch!
|
||||||
@IBOutlet weak var ledToggleButton: UIButton!
|
@IBOutlet weak var ledToggleButton: UIButton!
|
||||||
@IBOutlet weak var statusLabel: UILabel!
|
@IBOutlet weak var statusLabel: UILabel!
|
||||||
@ -19,30 +19,30 @@ class ViewController: UIViewController {
|
|||||||
@IBOutlet weak var pillsTotal: UILabel!
|
@IBOutlet weak var pillsTotal: UILabel!
|
||||||
@IBOutlet weak var pillsAttached: UILabel!
|
@IBOutlet weak var pillsAttached: UILabel!
|
||||||
@IBOutlet weak var refreshToggle: UISwitch!
|
@IBOutlet weak var refreshToggle: UISwitch!
|
||||||
|
|
||||||
let totalPills: Int = 6
|
let totalPills: Int = 6
|
||||||
var usedPills: Int = 0
|
var usedPills: Int = 0
|
||||||
var remainingPills: Int = 0
|
var remainingPills: Int = 0
|
||||||
let updateFreq: Float = 2.0
|
let updateFreq: Float = 2.0
|
||||||
weak var timer: Timer?
|
weak var timer: Timer?
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
overrideUserInterfaceStyle = .light
|
overrideUserInterfaceStyle = .light
|
||||||
simpleBluetoothIO = SimpleBluetoothIO(serviceUUID: "4fafc201-1fb5-459e-8fcc-c5c9c331914b", delegate: self)
|
simpleBluetoothIO = SimpleBluetoothIO(serviceUUID: "4fafc201-1fb5-459e-8fcc-c5c9c331914b", delegate: self)
|
||||||
// startTimer()
|
// startTimer()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
deinit {
|
deinit {
|
||||||
stopTimer()
|
stopTimer()
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendUpdateCommand(){
|
func sendUpdateCommand(){
|
||||||
print("Sending update command...")
|
print("Sending update command...")
|
||||||
simpleBluetoothIO.writeValue(value: 51)
|
simpleBluetoothIO.writeValue(value: 51)
|
||||||
}
|
}
|
||||||
|
|
||||||
func startTimer() {
|
func startTimer() {
|
||||||
timer?.invalidate() // just in case you had existing `Timer`, `invalidate` it before we lose our reference to it
|
timer?.invalidate() // just in case you had existing `Timer`, `invalidate` it before we lose our reference to it
|
||||||
timer = Timer.scheduledTimer(withTimeInterval: TimeInterval(updateFreq), repeats: true) { [weak self] _ in
|
timer = Timer.scheduledTimer(withTimeInterval: TimeInterval(updateFreq), repeats: true) { [weak self] _ in
|
||||||
@ -53,15 +53,15 @@ class ViewController: UIViewController {
|
|||||||
func stopTimer() {
|
func stopTimer() {
|
||||||
timer?.invalidate()
|
timer?.invalidate()
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func ledToggleButtonDown(_ sender: UIButton) {
|
@IBAction func ledToggleButtonDown(_ sender: UIButton) {
|
||||||
simpleBluetoothIO.writeValue(value:49)
|
simpleBluetoothIO.writeValue(value:49)
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func ledToggleButtonUp(_ sender: UIButton) {
|
@IBAction func ledToggleButtonUp(_ sender: UIButton) {
|
||||||
simpleBluetoothIO.writeValue(value: 50)
|
simpleBluetoothIO.writeValue(value: 50)
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func forcePillRefresh(_ sender: UIButton) {
|
@IBAction func forcePillRefresh(_ sender: UIButton) {
|
||||||
self.sendUpdateCommand()
|
self.sendUpdateCommand()
|
||||||
}
|
}
|
||||||
@ -72,7 +72,7 @@ class ViewController: UIViewController {
|
|||||||
stopTimer()
|
stopTimer()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension ViewController: SimpleBluetoothIODelegate {
|
extension ViewController: SimpleBluetoothIODelegate {
|
||||||
@ -85,12 +85,14 @@ extension ViewController: SimpleBluetoothIODelegate {
|
|||||||
} else if value == 99 {
|
} else if value == 99 {
|
||||||
//view.backgroundColor = UIColor.black
|
//view.backgroundColor = UIColor.black
|
||||||
virtualButton.setOn(false, animated: true)
|
virtualButton.setOn(false, animated: true)
|
||||||
} else if value == 55 {
|
} else if value == 97 {
|
||||||
self.pillsConsumed.text = "X"
|
self.pillsConsumed.text = "X"
|
||||||
self.pillsRemaining.text = "X"
|
self.pillsRemaining.text = "X"
|
||||||
self.pillsTotal.text = "X"
|
self.pillsTotal.text = "X"
|
||||||
self.pillsAttached.text = "Detached"
|
self.pillsAttached.text = "Detached"
|
||||||
self.pillsAttached.textColor = UIColor.red
|
self.pillsAttached.textColor = UIColor.red
|
||||||
|
} else if value == 96 {
|
||||||
|
self.pillsAttached.text = "TODO: Battery low..."
|
||||||
} else {
|
} else {
|
||||||
self.remainingPills = Int(value)
|
self.remainingPills = Int(value)
|
||||||
self.usedPills = self.totalPills - self.remainingPills
|
self.usedPills = self.totalPills - self.remainingPills
|
||||||
@ -101,7 +103,7 @@ extension ViewController: SimpleBluetoothIODelegate {
|
|||||||
self.pillsAttached.textColor = UIColor.green
|
self.pillsAttached.textColor = UIColor.green
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func simpleBluetoothIO(simpleBluetoothIO: SimpleBluetoothIO, didConnect value: Bool) {
|
func simpleBluetoothIO(simpleBluetoothIO: SimpleBluetoothIO, didConnect value: Bool) {
|
||||||
print("VC: connect: \(value)")
|
print("VC: connect: \(value)")
|
||||||
self.cStatus.text = "Connected!"
|
self.cStatus.text = "Connected!"
|
||||||
@ -111,7 +113,7 @@ extension ViewController: SimpleBluetoothIODelegate {
|
|||||||
self.sendUpdateCommand()
|
self.sendUpdateCommand()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func simpleBluetoothIO(simpleBluetoothIO: SimpleBluetoothIO, didDisconnect value: Bool) {
|
func simpleBluetoothIO(simpleBluetoothIO: SimpleBluetoothIO, didDisconnect value: Bool) {
|
||||||
print("VC: disconnect: \(value)")
|
print("VC: disconnect: \(value)")
|
||||||
self.cStatus.text = "Disconnected..."
|
self.cStatus.text = "Disconnected..."
|
||||||
@ -119,17 +121,17 @@ extension ViewController: SimpleBluetoothIODelegate {
|
|||||||
self.pillsAttached.text = "Detached"
|
self.pillsAttached.text = "Detached"
|
||||||
self.pillsAttached.textColor = UIColor.red
|
self.pillsAttached.textColor = UIColor.red
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension String {
|
extension String {
|
||||||
|
|
||||||
func index(at position: Int, from start: Index? = nil) -> Index? {
|
func index(at position: Int, from start: Index? = nil) -> Index? {
|
||||||
let startingIndex = start ?? startIndex
|
let startingIndex = start ?? startIndex
|
||||||
return index(startingIndex, offsetBy: position, limitedBy: endIndex)
|
return index(startingIndex, offsetBy: position, limitedBy: endIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
func character(at position: Int) -> Character? {
|
func character(at position: Int) -> Character? {
|
||||||
guard position >= 0, let indexPosition = index(at: position) else {
|
guard position >= 0, let indexPosition = index(at: position) else {
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@ -1,3 +1,13 @@
|
|||||||
|
//
|
||||||
|
// main.ino
|
||||||
|
// PillTracker
|
||||||
|
//
|
||||||
|
// Created by Max Hunt on 16/01/2021.
|
||||||
|
// © Max Hunt 2021
|
||||||
|
|
||||||
|
|
||||||
|
// TODODODODODODO: SWITCH AROUND FOR PULLDOWN INPUT SYSTEM AND DEFAULT LOW RAIL OUTPUTS
|
||||||
|
|
||||||
#include <BLEDevice.h>
|
#include <BLEDevice.h>
|
||||||
#include <BLEUtils.h>
|
#include <BLEUtils.h>
|
||||||
#include <BLEServer.h>
|
#include <BLEServer.h>
|
||||||
@ -7,134 +17,250 @@
|
|||||||
#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 CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"
|
||||||
|
|
||||||
#define LED_PIN 2
|
#define LED_PIN 13
|
||||||
#define BTN_PIN 5
|
#define TEST_BTN_PIN 5
|
||||||
#define PILL_1_PIN 25
|
|
||||||
#define PILL_2_PIN 13
|
|
||||||
#define PILL_3_PIN 12
|
|
||||||
#define PILL_4_PIN 26
|
|
||||||
#define PILL_5_PIN 27
|
|
||||||
#define PILL_6_PIN 14
|
|
||||||
#define DETECT_PIN 18
|
|
||||||
|
|
||||||
int deviceConnected = false;
|
#define MUX_BIT_0 13
|
||||||
int waitingForUpdate = 0;
|
#define MUX_BIT_1 12
|
||||||
|
#define MUX_BIT_2 27
|
||||||
|
#define MUX_BIT_3 33
|
||||||
|
#define MUX_COM 32
|
||||||
|
|
||||||
|
#define RAIL_EVEN 15
|
||||||
|
#define RAIL_ODD 14
|
||||||
|
|
||||||
|
#define PILL_SENSE 21
|
||||||
|
|
||||||
|
#define BATTERY_PIN 35
|
||||||
|
|
||||||
|
// int deviceConnected = false;
|
||||||
|
bool waiting_for_update = false;
|
||||||
|
bool pills_plugged_in = false;
|
||||||
|
|
||||||
class MyCallbacks:public BLECharacteristicCallbacks {
|
class MyCallbacks:public BLECharacteristicCallbacks {
|
||||||
void onConnect(BLEServer * pServer) {
|
void onConnect(BLEServer * pServer) {
|
||||||
deviceConnected = true;
|
// deviceConnected = true;
|
||||||
Serial.println("device connected");
|
Serial.println("device connected");
|
||||||
};
|
};
|
||||||
void onDisconnect(BLEServer * pServer) {
|
void onDisconnect(BLEServer * pServer) {
|
||||||
deviceConnected = false;
|
// deviceConnected = false;
|
||||||
Serial.println("device disconnected");
|
Serial.println("device disconnected");
|
||||||
}
|
}
|
||||||
void onWrite(BLECharacteristic * pCharacteristic) {
|
void onWrite(BLECharacteristic * pCharacteristic) {
|
||||||
std::string value = pCharacteristic -> getValue();
|
std::string value = pCharacteristic -> getValue();
|
||||||
if (value.length() > 0) {
|
if (value.length() > 0) {
|
||||||
Serial.print("*********");
|
if (atoi(value.c_str()) == 1) {
|
||||||
Serial.print(value.c_str());
|
digitalWrite(LED_PIN, HIGH);
|
||||||
Serial.print("-");
|
Serial.print("LEDON");
|
||||||
Serial.print(atoi(value.c_str()));
|
|
||||||
Serial.print("-");
|
} else if (atoi(value.c_str()) == 2) {
|
||||||
if (atoi(value.c_str()) == 1) {
|
digitalWrite(LED_PIN, LOW);
|
||||||
digitalWrite(LED_PIN, HIGH);
|
Serial.print("LEDOFF");
|
||||||
Serial.print("LEDON");
|
|
||||||
} else if (atoi(value.c_str()) == 2) {
|
} else if (atoi(value.c_str()) == 3) {
|
||||||
digitalWrite(LED_PIN, LOW);
|
Serial.print("UPDATE_PILL_TRACK");
|
||||||
Serial.print("LEDOFF");
|
waiting_for_update = true;
|
||||||
} else if (atoi(value.c_str()) == 3) {
|
|
||||||
Serial.print("UPDATE_PILL_TRACK");
|
} else {
|
||||||
waitingForUpdate = 1;
|
Serial.println("****************** UNEXPECTED MESSAGE!!! ******************");
|
||||||
} else {
|
Serial.println(atoi(value.c_str()));
|
||||||
Serial.println();
|
Serial.println("****************** END UNEXPECTED MESSAGE!!! ******************");
|
||||||
Serial.println(atoi(value.c_str()));
|
}
|
||||||
Serial.println();
|
|
||||||
}
|
}
|
||||||
Serial.println("*********");
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
BLECharacteristic * pCharacteristic;
|
BLECharacteristic * pCharacteristic;
|
||||||
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
pinMode(LED_PIN, OUTPUT);
|
|
||||||
pinMode(PILL_1_PIN, INPUT_PULLUP);
|
pinMode(LED_PIN, OUTPUT);
|
||||||
pinMode(PILL_2_PIN, INPUT_PULLUP);
|
pinMode(TEST_BTN_PIN, INPUT_PULLUP);
|
||||||
pinMode(PILL_3_PIN, INPUT_PULLUP);
|
|
||||||
pinMode(PILL_4_PIN, INPUT_PULLUP);
|
pinMode(MUX_BIT_0, OUTPUT);
|
||||||
pinMode(PILL_5_PIN, INPUT_PULLUP);
|
pinMode(MUX_BIT_1, OUTPUT);
|
||||||
pinMode(PILL_6_PIN, INPUT_PULLUP);
|
pinMode(MUX_BIT_2, OUTPUT);
|
||||||
pinMode(BTN_PIN, INPUT_PULLUP);
|
pinMode(MUX_BIT_3, OUTPUT);
|
||||||
pinMode(DETECT_PIN, INPUT_PULLUP);
|
pinMode(MUX_COM, INPUT);
|
||||||
digitalWrite(LED_PIN, LOW);
|
|
||||||
Serial.println("1- Download and install an BLE scanner app in your phone");
|
pinMode(RAIL_EVEN, OUTPUT);
|
||||||
Serial.println("2- Scan for BLE devices in the app");
|
pinMode(RAIL_ODD, OUTPUT);
|
||||||
Serial.println("3- Connect to MyESP32");
|
|
||||||
Serial.println("4- Go to CUSTOM CHARACTERISTIC in CUSTOM SERVICE and write something");
|
pinMode(PILL_SENSE, INPUT_PULLUP);
|
||||||
Serial.println("5- See the magic =)");
|
pinMode(BATTERY_PIN, INPUT);
|
||||||
BLEDevice::init("PILL_TRACKER");
|
|
||||||
BLEServer * pServer = BLEDevice::createServer();
|
digitalWrite(LED_PIN, LOW);
|
||||||
BLEService * pService = pServer -> createService(SERVICE_UUID);
|
|
||||||
pCharacteristic = pService -> createCharacteristic(
|
digitalWrite(RAIL_EVEN, HIGH);
|
||||||
CHARACTERISTIC_UUID,
|
digitalWrite(RAIL_ODD, HIGH);
|
||||||
BLECharacteristic::PROPERTY_READ |
|
|
||||||
BLECharacteristic::PROPERTY_WRITE |
|
digitalWrite(MUX_BIT_0, LOW);
|
||||||
BLECharacteristic::PROPERTY_NOTIFY
|
digitalWrite(MUX_BIT_1, LOW);
|
||||||
);
|
digitalWrite(MUX_BIT_2, LOW);
|
||||||
pCharacteristic -> setCallbacks(new MyCallbacks());
|
digitalWrite(MUX_BIT_3, LOW);
|
||||||
pCharacteristic -> setValue("Hello World");
|
|
||||||
pService -> start();
|
int debug_btn_previous_value = 0;
|
||||||
BLEAdvertising * pAdvertising = pServer -> getAdvertising();
|
|
||||||
pAdvertising -> start();
|
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;
|
bool seekValueFromMatrix(int column_id, int row_id) {
|
||||||
int prevVal2 = LOW;
|
|
||||||
|
if (column_id > 1 || row_id > 15) {
|
||||||
|
Serial.println("@@@@@@@@@@@@@@@@@@@@ BINARY ERROR!!! @@@@@@@@@@@@@@@@@@@@");
|
||||||
|
}
|
||||||
|
|
||||||
|
int rail_to_GND = 0;
|
||||||
|
int rail_to_INPUT = 0;
|
||||||
|
int mux_bit_0 = 0;
|
||||||
|
int mux_bit_1 = 0;
|
||||||
|
int mux_bit_2 = 0;
|
||||||
|
int mux_bit_3 = 0;
|
||||||
|
bool is_pill_present = false;
|
||||||
|
|
||||||
|
if (column_id == 0) {
|
||||||
|
rail_to_GND = RAIL_EVEN;
|
||||||
|
rail_to_INPUT = RAIL_ODD;
|
||||||
|
} else if (column_id == 1) {
|
||||||
|
rail_to_GND = RAIL_ODD;
|
||||||
|
rail_to_INPUT = RAIL_EVEN;
|
||||||
|
} else { return -1;}
|
||||||
|
|
||||||
|
mux_bit_0 = row_id & 0b1000;
|
||||||
|
mux_bit_1 = row_id & 0b0100;
|
||||||
|
mux_bit_2 = row_id & 0b0010;
|
||||||
|
mux_bit_3 = row_id & 0b0001;
|
||||||
|
|
||||||
|
pinMode(rail_to_INPUT, INPUT);
|
||||||
|
digitalWrite(rail_to_GND, LOW);
|
||||||
|
|
||||||
|
|
||||||
|
digitalWrite(MUX_BIT_0, mux_bit_0);
|
||||||
|
digitalWrite(MUX_BIT_1, mux_bit_1);
|
||||||
|
digitalWrite(MUX_BIT_2, mux_bit_2);
|
||||||
|
digitalWrite(MUX_BIT_3, mux_bit_3);
|
||||||
|
delay(10);
|
||||||
|
if (digitalRead(PILL_SENSE) == LOW){
|
||||||
|
is_pill_present = true
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println("########## COMPUTED BINARY ##########");
|
||||||
|
Serial.print("ROW ID: ");
|
||||||
|
Serial.print(row_id);
|
||||||
|
Serial.print(" | BIT 0: ");
|
||||||
|
Serial.print(mux_bit_0);
|
||||||
|
Serial.print(" | BIT 1: ");
|
||||||
|
Serial.print(mux_bit_1);
|
||||||
|
Serial.print(" | BIT 2: ");
|
||||||
|
Serial.print(mux_bit_2);
|
||||||
|
Serial.print(" | BIT 3: ");
|
||||||
|
Serial.print(mux_bit_3);
|
||||||
|
Serial.print(" | OBTAINED RESULT: ");
|
||||||
|
Serial.println(is_pill_present);
|
||||||
|
Serial.println("########## END COMPUTED BINARY ##########");
|
||||||
|
|
||||||
|
pinMode(rail_to_INPUT, OUTPUT);
|
||||||
|
digitalWrite(RAIL_EVEN, HIGH);
|
||||||
|
digitalWrite(RAIL_ODD, HIGH);
|
||||||
|
|
||||||
|
digitalWrite(MUX_BIT_0, LOW);
|
||||||
|
digitalWrite(MUX_BIT_1, LOW);
|
||||||
|
digitalWrite(MUX_BIT_2, LOW);
|
||||||
|
digitalWrite(MUX_BIT_3, LOW);
|
||||||
|
|
||||||
|
return is_pill_present;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int getPillCount() {
|
int getPillCount() {
|
||||||
int totalCount = 0;
|
int total_pill_count = 0;
|
||||||
if (digitalRead(DETECT_PIN) == LOW) {
|
if (digitalRead(PILL_SENSE) == LOW) {
|
||||||
Serial.println("PROBE_ATTACHED");
|
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");}
|
for (int col = 0; col < 2; col++){
|
||||||
if (digitalRead(PILL_3_PIN) == LOW){totalCount++;Serial.println("12:FULL");}
|
for (int row = 0; row < 8; row++){
|
||||||
if (digitalRead(PILL_4_PIN) == LOW){totalCount++;Serial.println("26:FULL");}
|
bool is_pill_present = false
|
||||||
if (digitalRead(PILL_5_PIN) == LOW){totalCount++;Serial.println("27:FULL");}
|
is_pill_present = seekValueFromMatrix(col, row)
|
||||||
if (digitalRead(PILL_6_PIN) == LOW){totalCount++;Serial.println("14:FULL");}
|
if (is_pill_present == true){
|
||||||
} else {
|
total_pill_count++;
|
||||||
Serial.println("PROBE_DETACHED");
|
}
|
||||||
totalCount = 55;
|
}
|
||||||
}
|
}
|
||||||
return totalCount;
|
} else {
|
||||||
|
Serial.println("PROBE_DETACHED");
|
||||||
|
totalCount = 97;
|
||||||
|
}
|
||||||
|
return total_pill_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float getVoltage(){
|
||||||
|
int sensorValue = analogRead(35);
|
||||||
|
float theVoltage = (sensorValue/4095.0)*6.6*1.1;
|
||||||
|
return theVoltage;
|
||||||
|
}
|
||||||
|
|
||||||
|
void printVoltage(){
|
||||||
|
Serial.println((String)"\nBattery Voltage: "+getVoltage()+"\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void checkBatteryVoltage() {
|
||||||
|
float voltage = getVoltage();
|
||||||
|
printVoltage();
|
||||||
|
if (voltage < 3.5) {
|
||||||
|
// Automatically notify the phone that battery is low
|
||||||
|
pCharacteristic -> setValue((uint8_t *) & 96, 4); // NOTE: WTF does the 4 mean?!?
|
||||||
|
pCharacteristic -> notify();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int loopcounter = 0;
|
||||||
void loop() {
|
void loop() {
|
||||||
// put your main code here, to run repeatedly:
|
loopcounter++;
|
||||||
int currentVal = digitalRead(BTN_PIN);
|
if(loopcounter > 50000000){
|
||||||
if (currentVal != prevVal) {
|
loopcounter = 0;
|
||||||
prevVal = currentVal;
|
checkBatteryVoltage();
|
||||||
if (currentVal == HIGH) {
|
// TODO: Make a proper voltage to ios bt interface?
|
||||||
int value = 99;
|
}
|
||||||
pCharacteristic -> setValue((uint8_t *) & value, 4);
|
|
||||||
pCharacteristic -> notify();
|
int debug_btn_current_value = digitalRead(BTN_PIN);
|
||||||
}
|
if (debug_btn_current_value != debug_btn_previous_value) {
|
||||||
else {
|
debug_btn_previous_value = debug_btn_current_value;
|
||||||
int value = 98;
|
if (debug_btn_current_value == HIGH) {
|
||||||
pCharacteristic -> setValue((uint8_t *) & value, 4);
|
int debug_value = 99;
|
||||||
pCharacteristic -> notify();
|
pCharacteristic -> setValue((uint8_t *) & debug_value, 4);
|
||||||
}
|
pCharacteristic -> notify();
|
||||||
}
|
}
|
||||||
if (waitingForUpdate == 1) {
|
else {
|
||||||
Serial.println("************************************************************");
|
int debug_value = 98;
|
||||||
Serial.println("**************UPDATE AND SEND PILL COUNT********************");
|
pCharacteristic -> setValue((uint8_t *) & debug_value, 4);
|
||||||
Serial.println("************************************************************");
|
pCharacteristic -> notify();
|
||||||
waitingForUpdate = 0;
|
}
|
||||||
int value = getPillCount();
|
}
|
||||||
pCharacteristic -> setValue((uint8_t *) & value, 4);
|
if (waiting_for_update == true) {
|
||||||
pCharacteristic -> notify();
|
Serial.println("************************************************************");
|
||||||
}
|
Serial.println("**************UPDATE AND SEND PILL COUNT********************");
|
||||||
|
Serial.println("************************************************************");
|
||||||
|
waiting_for_update = false;
|
||||||
|
int pill_quantity = getPillCount();
|
||||||
|
// pCharacteristic -> setValue("Hello World"); <-- Interesting!?!
|
||||||
|
pCharacteristic -> setValue((uint8_t *) & pill_quantity, 4); // NOTE: WTF does the 4 mean?!?
|
||||||
|
pCharacteristic -> notify();
|
||||||
|
printVoltage();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user