Nucleo-transfer
Dependencies: ADS1015 MPU6050 PixelArray PixelArray-Nucleo mbed WS2813
Fork of Nucleo-transfer by
Diff: Sensorplate/main.cpp
- Revision:
- 19:3b5999fa7b7e
- Parent:
- 18:3b2686cdbcb7
- Child:
- 20:ed91698725cc
- Child:
- 21:13e4824bc364
--- a/Sensorplate/main.cpp Thu Sep 28 20:22:37 2017 +0000 +++ b/Sensorplate/main.cpp Thu Sep 28 20:45:47 2017 +0000 @@ -17,21 +17,27 @@ InterruptIn reposition(p17); InterruptIn mute(p15); InterruptIn new_patient(p14); - // Analog input between 0 and 1 (0 and 100 %) for reading batteryvoltage from accupack. +// 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_intern2(LED2); DigitalOut LED_intern3(LED3); -DigitalOut LED_intern4(LED4); neopixel::PixelArray array(p11); -Timer hold_timer; +Timer lock_hold_timer; +Timer calibration_hold_timer; Timer delay; Timer speaker_timer; +Timer led_timer; DigitalOut speaker1(p21); DigitalOut speaker2(p22); +DigitalOut lock_LED(p23); +DigitalOut reposition_LED(p24); +DigitalOut mute_LED(p25); +DigitalOut new_patient_LED(p26); + I2C i2c(p28, p27); // I2C I2C i2cAccu(p7, p6); @@ -156,7 +162,7 @@ void trigger_lock() // If rising edge lock button is detected start locktimer. { - hold_timer.start(); + lock_hold_timer.start(); delay.reset(); delay.start(); } @@ -164,8 +170,8 @@ void timer_lock() // End timer lock. { lock_flag = 0; // Set lock_flag off. - hold_timer.stop(); // Stop and reset holdtimer - hold_timer.reset(); + lock_hold_timer.stop(); // Stop and reset holdtimer + lock_hold_timer.reset(); } void trigger_reposition() @@ -182,6 +188,8 @@ } reposition_flag = 1; + + reposition_LED = 1; } } @@ -202,6 +210,8 @@ } mute_flag = 1; + + mute_LED = 1; } } @@ -209,15 +219,21 @@ { if (lock_state == 1) { } else { - hold_timer.start(); - new_patient_flag = 1; + calibration_hold_timer.start(); + new_patient_LED = 1; } } void timer_calibration() // Timer calibration function. { - hold_timer.stop(); - hold_timer.reset(); + new_patient_LED = 0; + + if (calibration_hold_timer.read_ms()<calibrationtime_ms) { + new_patient_flag = 1; + } + + calibration_hold_timer.stop(); + calibration_hold_timer.reset(); 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 { @@ -277,7 +293,7 @@ speaker_timer.stop(); // Stop speaker timer. speaker_timer.reset(); } - + batteryvoltage_current = adsAccu.readADC_SingleEnded(0); // Read channel 0 if (supplyvoltage.read() == 0) { @@ -286,7 +302,7 @@ power_plug_state = 0; } } - + void read_adc() { pc.printf("Read_adc\n"); @@ -317,13 +333,13 @@ elec[3] = pel.readADC_SingleEnded(0); //Fourth PE readout - if ((hold_timer.read_ms() > locktime_ms) && lock_flag == 0 && lock == 1) { // If statement for lock function. + if ((lock_hold_timer.read_ms() > locktime_ms) && lock_flag == 0 && lock == 1) { // If statement for lock function. lock_flag = 1; LED_intern2 = !LED_intern2; lock_state = !lock_state; } - if ((hold_timer.read_ms() > calibrationtime_ms) && calibration_flag == 0 && new_patient == 1) { // If statement for calibration system. + if ((calibration_hold_timer.read_ms() > calibrationtime_ms) && calibration_flag == 0 && new_patient == 1) { // If statement for calibration system. calibration_flag = 1; calibration_flash = 11; pi.printf(">30\n"); // Print statement for serial communication to inform algorithm to calibrate. @@ -337,7 +353,7 @@ batteryvoltage_current = batteryvoltage_current*100; batteryvoltage_current = batteryvoltage_last; read_voltage(); // Supplyvoltage control for alarm. - + uint32_t val = 0; colour_select(LED_colour); array.update(generate, NLED, val); @@ -349,23 +365,23 @@ while(t.read_us()<(4.25*(cycle_time/5))) {} //Wait untill 85% of cycle pi.printf("!,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%f,%f,%f,%f,%f,%f,\n", res[4], res[7], res[6], res[5], res[1], res[0], res[2], res[3], elec[0], elec[1], elec[2], elec[3], elec[4], acce[0]*100, acce[1]*100, acce[2]*100, gyro[0]*100, gyro[1]*100, gyro[2]*100); // print all to serial port //receiving order: 8 resistive sensors, 5 electric readings, 3 accelerometer axes, 3 gyroscope axes - + serial_read(); if (mute_flag == 1) { - pi.printf(“>01\n”); - pc.printf(“>01\n”); + pi.printf(">01\n"); + pc.printf(">01\n"); mute_flag = 0; - } + } - if (new_patient_flag == 1) { - pi.printf(“>03\n”); - pc.printf(“>03\n”); + if (new_patient_flag == 1) { + pi.printf(">03\n"); + pc.printf(">03\n"); new_patient_flag = 0; } - if (reposition_flag == 1) { - pi.printf(“>02\n”); - pc.printf(“>02\n”); + if (reposition_flag == 1) { + pi.printf(">02\n"); + pc.printf(">02\n"); reposition_flag = 0; } @@ -451,8 +467,8 @@ delay.reset(); // Delaytimer reset en start. delay.start(); - sample_cycle.attach_us(&read_adc, cycle_time); - + 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");