Update
This commit is contained in:
parent
b9ad917346
commit
4dd88b17f8
@ -20,7 +20,7 @@ class ViewController: UIViewController {
|
||||
@IBOutlet weak var pillsAttached: UILabel!
|
||||
@IBOutlet weak var refreshToggle: UISwitch!
|
||||
|
||||
let totalPills: Int = 6
|
||||
let totalPills: Int = 16
|
||||
var usedPills: Int = 0
|
||||
var remainingPills: Int = 0
|
||||
let updateFreq: Float = 2.0
|
||||
@ -109,7 +109,7 @@ extension ViewController: SimpleBluetoothIODelegate {
|
||||
self.cStatus.text = "Connected!"
|
||||
self.cStatus.textColor = UIColor.green
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
|
||||
print("Sending update commend")
|
||||
print("Sending update command")
|
||||
self.sendUpdateCommand()
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,6 +36,8 @@
|
||||
// int deviceConnected = false;
|
||||
bool waiting_for_update = false;
|
||||
bool pills_plugged_in = false;
|
||||
int debug_btn_previous_value = 0;
|
||||
|
||||
|
||||
class MyCallbacks:public BLECharacteristicCallbacks {
|
||||
void onConnect(BLEServer * pServer) {
|
||||
@ -84,7 +86,7 @@ void setup() {
|
||||
pinMode(MUX_BIT_1, OUTPUT);
|
||||
pinMode(MUX_BIT_2, OUTPUT);
|
||||
pinMode(MUX_BIT_3, OUTPUT);
|
||||
pinMode(MUX_COM, INPUT);
|
||||
pinMode(MUX_COM, INPUT_PULLUP);
|
||||
|
||||
pinMode(RAIL_EVEN, OUTPUT);
|
||||
pinMode(RAIL_ODD, OUTPUT);
|
||||
@ -102,8 +104,6 @@ void setup() {
|
||||
digitalWrite(MUX_BIT_2, LOW);
|
||||
digitalWrite(MUX_BIT_3, LOW);
|
||||
|
||||
int debug_btn_previous_value = 0;
|
||||
|
||||
BLEDevice::init("PILL_TRACKER");
|
||||
BLEServer * pServer = BLEDevice::createServer();
|
||||
BLEService * pService = pServer -> createService(SERVICE_UUID);
|
||||
@ -128,10 +128,10 @@ bool seekValueFromMatrix(int column_id, int row_id) {
|
||||
|
||||
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;
|
||||
// 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) {
|
||||
@ -142,22 +142,46 @@ bool seekValueFromMatrix(int column_id, int row_id) {
|
||||
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;
|
||||
// mux_bit_0 = row_id & 0b0001;
|
||||
// mux_bit_1 = row_id & 0b0010;
|
||||
// mux_bit_2 = row_id & 0b0100;
|
||||
// mux_bit_3 = row_id & 0b1000;
|
||||
|
||||
pinMode(rail_to_INPUT, INPUT);
|
||||
pinMode(rail_to_INPUT, INPUT_PULLUP);
|
||||
digitalWrite(rail_to_GND, LOW);
|
||||
|
||||
digitalWrite(MUX_BIT_0, row_id & 0b0001);
|
||||
digitalWrite(MUX_BIT_1, row_id & 0b0010);
|
||||
digitalWrite(MUX_BIT_2, row_id & 0b0100);
|
||||
digitalWrite(MUX_BIT_3, row_id & 0b1000);
|
||||
|
||||
// if (mux_bit_0 > 0) {
|
||||
// digitalWrite(MUX_BIT_0, LOW);
|
||||
// } else {
|
||||
// digitalWrite(MUX_BIT_0, HIGH);
|
||||
// }
|
||||
|
||||
// if (mux_bit_1 > 0) {
|
||||
// digitalWrite(MUX_BIT_1, LOW);
|
||||
// } else {
|
||||
// digitalWrite(MUX_BIT_1, HIGH);
|
||||
// }
|
||||
|
||||
// if (mux_bit_2 > 0) {
|
||||
// digitalWrite(MUX_BIT_2, LOW);
|
||||
// } else {
|
||||
// digitalWrite(MUX_BIT_2, HIGH);
|
||||
// }
|
||||
|
||||
// if (mux_bit_3 > 0) {
|
||||
// digitalWrite(MUX_BIT_3, LOW);
|
||||
// } else {
|
||||
// digitalWrite(MUX_BIT_3, HIGH);
|
||||
// }
|
||||
|
||||
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
|
||||
is_pill_present = true;
|
||||
}
|
||||
|
||||
Serial.println("########## COMPUTED BINARY ##########");
|
||||
@ -195,8 +219,8 @@ int getPillCount() {
|
||||
|
||||
for (int col = 0; col < 2; col++){
|
||||
for (int row = 0; row < 8; row++){
|
||||
bool is_pill_present = false
|
||||
is_pill_present = seekValueFromMatrix(col, row)
|
||||
bool is_pill_present = false;
|
||||
is_pill_present = seekValueFromMatrix(col, row);
|
||||
if (is_pill_present == true){
|
||||
total_pill_count++;
|
||||
}
|
||||
@ -204,7 +228,7 @@ int getPillCount() {
|
||||
}
|
||||
} else {
|
||||
Serial.println("PROBE_DETACHED");
|
||||
totalCount = 97;
|
||||
total_pill_count = 97;
|
||||
}
|
||||
return total_pill_count;
|
||||
}
|
||||
@ -224,7 +248,8 @@ void checkBatteryVoltage() {
|
||||
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?!?
|
||||
int low_battery_warning_code = 96;
|
||||
pCharacteristic -> setValue((uint8_t *) & low_battery_warning_code, 4); // NOTE: WTF does the 4 mean?!?
|
||||
pCharacteristic -> notify();
|
||||
}
|
||||
}
|
||||
@ -238,7 +263,7 @@ void loop() {
|
||||
// TODO: Make a proper voltage to ios bt interface?
|
||||
}
|
||||
|
||||
int debug_btn_current_value = digitalRead(BTN_PIN);
|
||||
int debug_btn_current_value = digitalRead(TEST_BTN_PIN);
|
||||
if (debug_btn_current_value != debug_btn_previous_value) {
|
||||
debug_btn_previous_value = debug_btn_current_value;
|
||||
if (debug_btn_current_value == HIGH) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user