Stashing seemingly useless changes
This commit is contained in:
parent
eab090470e
commit
6bb4845930
@ -23,6 +23,7 @@ class ViewController: UIViewController {
|
|||||||
let totalPills: Int = 6
|
let totalPills: Int = 6
|
||||||
let updateFreq: Float = 2.0
|
let updateFreq: Float = 2.0
|
||||||
weak var timer: Timer?
|
weak var timer: Timer?
|
||||||
|
var pillIndex = [3, 3, 3, 3, 3, 3]
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
@ -52,6 +53,20 @@ class ViewController: UIViewController {
|
|||||||
timer?.invalidate()
|
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) {
|
@IBAction func ledToggleButtonDown(_ sender: UIButton) {
|
||||||
simpleBluetoothIO.writeValue(value:49)
|
simpleBluetoothIO.writeValue(value:49)
|
||||||
}
|
}
|
||||||
@ -76,7 +91,7 @@ class ViewController: UIViewController {
|
|||||||
extension ViewController: SimpleBluetoothIODelegate {
|
extension ViewController: SimpleBluetoothIODelegate {
|
||||||
func simpleBluetoothIO(simpleBluetoothIO: SimpleBluetoothIO, didReceiveValue value: Int8) {
|
func simpleBluetoothIO(simpleBluetoothIO: SimpleBluetoothIO, didReceiveValue value: Int8) {
|
||||||
self.statusLabel.text = String(value)
|
self.statusLabel.text = String(value)
|
||||||
print(value)
|
print("GOT: \(value)")
|
||||||
if value == 98 {
|
if value == 98 {
|
||||||
//view.backgroundColor = UIColor.yellow
|
//view.backgroundColor = UIColor.yellow
|
||||||
virtualButton.setOn(true, animated: true)
|
virtualButton.setOn(true, animated: true)
|
||||||
@ -89,7 +104,7 @@ extension ViewController: SimpleBluetoothIODelegate {
|
|||||||
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 {
|
} else if String(value).prefix(2) == "7" {
|
||||||
let remainingPills = Int(value)
|
let remainingPills = Int(value)
|
||||||
let usedPills = self.totalPills - remainingPills
|
let usedPills = self.totalPills - remainingPills
|
||||||
self.pillsConsumed.text = String(usedPills)
|
self.pillsConsumed.text = String(usedPills)
|
||||||
@ -97,6 +112,8 @@ extension ViewController: SimpleBluetoothIODelegate {
|
|||||||
self.pillsTotal.text = String(self.totalPills)
|
self.pillsTotal.text = String(self.totalPills)
|
||||||
self.pillsAttached.text = "Attached"
|
self.pillsAttached.text = "Attached"
|
||||||
self.pillsAttached.textColor = UIColor.green
|
self.pillsAttached.textColor = UIColor.green
|
||||||
|
self.updatePillArray(data: String(value))
|
||||||
|
self.updatePillArrayUI()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,3 +137,18 @@ extension ViewController: SimpleBluetoothIODelegate {
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension String {
|
||||||
|
|
||||||
|
func index(at position: Int, from start: Index? = nil) -> Index? {
|
||||||
|
let startingIndex = start ?? startIndex
|
||||||
|
return index(startingIndex, offsetBy: position, limitedBy: endIndex)
|
||||||
|
}
|
||||||
|
|
||||||
|
func character(at position: Int) -> Character? {
|
||||||
|
guard position >= 0, let indexPosition = index(at: position) else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return self[indexPosition]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -117,21 +117,34 @@ int prevVal = LOW;
|
|||||||
int prevVal2 = LOW;
|
int prevVal2 = LOW;
|
||||||
|
|
||||||
int getPillCount() {
|
int getPillCount() {
|
||||||
int totalIntact = 0;
|
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) {
|
if(digitalRead(DETECT_PIN) == LOW) {
|
||||||
Serial.println("PROBE_ATTACHED");
|
Serial.println("PROBE_ATTACHED");
|
||||||
if(digitalRead(PILL_1_PIN) == LOW){totalIntact++;Serial.println("25:FULL");}
|
if(digitalRead(PILL_1_PIN) == LOW){bay0Intact = "1";Serial.println("25:FULL");}
|
||||||
if(digitalRead(PILL_2_PIN) == LOW){totalIntact++;Serial.println("13:FULL");}
|
if(digitalRead(PILL_2_PIN) == LOW){bay1Intact = "1";Serial.println("13:FULL");}
|
||||||
if(digitalRead(PILL_3_PIN) == LOW){totalIntact++;Serial.println("12:FULL");}
|
if(digitalRead(PILL_3_PIN) == LOW){bay2Intact = "1";Serial.println("12:FULL");}
|
||||||
if(digitalRead(PILL_4_PIN) == LOW){totalIntact++;Serial.println("26:FULL");}
|
if(digitalRead(PILL_4_PIN) == LOW){bay3Intact = "1";Serial.println("26:FULL");}
|
||||||
if(digitalRead(PILL_5_PIN) == LOW){totalIntact++;Serial.println("27:FULL");}
|
if(digitalRead(PILL_5_PIN) == LOW){bay4Intact = "1";Serial.println("27:FULL");}
|
||||||
if(digitalRead(PILL_6_PIN) == LOW){totalIntact++;Serial.println("14: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 {
|
else {
|
||||||
Serial.println("PROBE_DETACHED");
|
Serial.println("PROBE_DETACHED");
|
||||||
totalIntact = 55;
|
result = "55";
|
||||||
}
|
}
|
||||||
return totalIntact;
|
Serial.print("#########################################Sending: ");
|
||||||
|
Serial.println(result.toInt());
|
||||||
|
return result.toInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user