Pilot 1 working code (excluding new patient after calculation). %d changed in %f sensordata serial log.

Dependencies:   ADS1015 MPU6050 PixelArray mbed

Fork of Momo_New by Momo Medical

Revision:
20:ed91698725cc
Parent:
19:3b5999fa7b7e
--- a/Sensorplate/main.cpp	Thu Sep 28 20:45:47 2017 +0000
+++ b/Sensorplate/main.cpp	Fri Sep 29 13:48:57 2017 +0000
@@ -17,12 +17,12 @@
 InterruptIn reposition(p17);
 InterruptIn mute(p15);
 InterruptIn new_patient(p14);
-// Analog input between 0 and 1 (0 and 100 %) for reading batteryvoltage from accupack.
 DigitalIn   supplyvoltage(p20);                                             // Analog input between 0 and 1 for reading supplyvoltage from measuringpoint before power supply.
 
-PwmOut      LED_intern1(LED1);
+DigitalOut  LED_intern1(LED1);
 DigitalOut  LED_intern2(LED2);
 DigitalOut  LED_intern3(LED3);
+DigitalOut  button_power(p18);
 neopixel::PixelArray array(p11);
 
 Timer lock_hold_timer;
@@ -40,12 +40,12 @@
 
 
 I2C i2c(p28, p27);                  // I2C
-I2C i2cAccu(p7, p6);
+//I2C i2cAccu(p7, p6);
 MPU6050 agu(p28,p27);               // Accelerometer/Gyroscope Unit
 Adafruit_ADS1115 pr1(&i2c, 0x48);   // first PiëzoResistive ADC
 Adafruit_ADS1115 pr2(&i2c, 0x49);   // second PiëzoResistive ADC
 Adafruit_ADS1115 pel(&i2c, 0x4B);   // PiëzoElectric ADC
-Adafruit_ADS1015 adsAccu(&i2cAccu, 0x48);
+//Adafruit_ADS1015 adsAccu(&i2cAccu, 0x48);
 Serial pc(USBTX, USBRX); // tx, rx  // Serial USB connection
 Serial pi(p9, p10);      // tx, rx  // Setup serial communication for pi.
 Timer t;                            // Timer for equally time-spaced samples
@@ -165,6 +165,7 @@
     lock_hold_timer.start();
     delay.reset();
     delay.start();
+    pc.printf("Lock\n");
 }
 
 void timer_lock()                                                           // End timer lock.
@@ -176,26 +177,25 @@
 
 void trigger_reposition()
 {
+    printf("Reposition\n");
     if (lock_state == 1 | (delay.read_ms() < buttondelay_ms)) {             // Control statement for lock interface and delay for non using buttons at the same time.
     } else {
         delay.reset();
         delay.start();
 
         if (LED_intern1 == 0) {
-            LED_intern1 = 1.0;
+            LED_intern1 = 1;
         } else {
-            LED_intern1 = 0.0;
+            LED_intern1 = 0;
         }
 
         reposition_flag = 1;
-
-        reposition_LED = 1;
     }
 }
 
 void trigger_mute()
 {
-    pc.printf("Mute_triggered.\n");
+    pc.printf("Mute\n");
     if (lock_state == 1 | (delay.read_ms() < buttondelay_ms)) {             // Control statement for lock interface and delay for non using buttons at the same time.
         mute_state = 0;
     } else {
@@ -204,19 +204,18 @@
         mute_state = !mute_state;
 
         if (LED_intern1 == 0) {
-            LED_intern1 = 1.0;
+            LED_intern1 = 1;
         } else {
-            LED_intern1 = 0.0;
+            LED_intern1 = 0;
         }
 
         mute_flag = 1;
-
-        mute_LED = 1;
     }
 }
 
 void trigger_new_patient()                                                  // Function to trigger hold timer for new patient calibration function.
 {
+    pc.printf("New patient\n");
     if (lock_state == 1) {
     } else {
         calibration_hold_timer.start();
@@ -228,7 +227,7 @@
 {
     new_patient_LED = 0;
     
-    if (calibration_hold_timer.read_ms()<calibrationtime_ms) {
+    if (calibration_hold_timer.read_ms() < calibrationtime_ms) {
         new_patient_flag = 1;
     }
     
@@ -240,9 +239,9 @@
         if (calibration_flag == 0) {
 
             if (LED_intern1 == 0) {
-                LED_intern1 = 1.0;
+                LED_intern1 = 1;
             } else {
-                LED_intern1 = 0.0;
+                LED_intern1 = 0;
             }
 
         } else {
@@ -262,7 +261,7 @@
 {
     LED_intern3 = 0;
 
-    if (batteryvoltage_current > alarm_voltage) {                    // If supplyvoltage (readed from input) is greater then the setted alarmvoltage.
+    if (batteryvoltage_current > alarm_voltage) {                           // If supplyvoltage (readed from input) is greater then the setted alarmvoltage.
         alarm = 0;                                                          // Alarm is off.
         speaker_state = 0;
     } else {
@@ -294,7 +293,7 @@
         speaker_timer.reset();
     }
 
-    batteryvoltage_current = adsAccu.readADC_SingleEnded(0);                // Read channel 0
+    //batteryvoltage_current = adsAccu.readADC_SingleEnded(0);                // Read channel 0
 
     if (supplyvoltage.read() == 0) {
         power_plug_state = 1;
@@ -444,6 +443,30 @@
             power_plug_logged = power_plug_state;
         }
     }
+    
+    if (mute_flag == 1) {
+        mute_LED = 1;
+    } else {
+        mute_LED = 0;
+    }
+    
+    if (new_patient == 1) {
+        new_patient_LED = 1;   
+    } else {
+        new_patient_LED = 0;
+    }
+    
+    if (reposition == 1) {
+        reposition_LED = 1;
+    } else {
+        reposition_LED = 0;
+    } 
+    
+    if (lock_flag == 1) {
+        lock_LED = 1; 
+    } else {
+        lock_LED = 0;
+    }
 }
 
 int main()
@@ -455,7 +478,7 @@
     pr1.setGain(GAIN_TWOTHIRDS); // set range to +/-6.144V
     pr2.setGain(GAIN_TWOTHIRDS); // set range to +/-6.144V
     pel.setGain(GAIN_TWOTHIRDS); // set range to +/-6.144V
-    adsAccu.setGain(GAIN_TWOTHIRDS); // set range to +/-6.144V
+    //adsAccu.setGain(GAIN_TWOTHIRDS); // set range to +/-6.144V
     pi.format(8, SerialBase::None, 1);
 
     lock.rise(&trigger_lock);                                               // Interrupt for rising edge lock button.
@@ -466,11 +489,11 @@
     new_patient.fall(&timer_calibration);                                   // Falling edge for calibration algorithm option.
     delay.reset();                                                          // Delaytimer reset en start.
     delay.start();
-
+    button_power = 1;
+    
     sample_cycle.attach_us(&read_adc, cycle_time);
 
     while (1) {
         wait_us(cycle_time+1); // wait indefinitely because the ticker restarts every 50 ms
-        pc.printf("while\n");
     }
 }
\ No newline at end of file