Nucleo-transfer
Dependencies: ADS1015 MPU6050 PixelArray PixelArray-Nucleo mbed WS2813
Fork of Nucleo-transfer by
Diff: Sensorplate/main.cpp
- Revision:
- 42:673ddef4cfa4
- Parent:
- 41:5380ada94ec6
- Child:
- 43:d09814c177a0
--- a/Sensorplate/main.cpp Mon Nov 27 15:47:43 2017 +0000 +++ b/Sensorplate/main.cpp Thu Nov 30 09:02:49 2017 +0000 @@ -46,7 +46,7 @@ DigitalOut LED_on_dev_board4(LED4); DigitalOut speaker1(PC_8); // relatie aangeven! DigitalOut speaker2(PC_6); -neopixel::PixelArray indicator_LEDs(PA_7); +//neopixel::PixelArray indicator_LEDs(PA_7); PwmOut lock_feedback_LED(PB_13); // Declaration of pulse with modulation outputs. PwmOut mute_feedback_LED(PB_1); @@ -80,7 +80,7 @@ // End of commentbox related to the serial configuration/ADC reading components. int boot_delay_ms = 500; -int total_readout_cycle_time_us = 100000 * 2; // Cycle time in us. +int total_readout_cycle_time_us = 100000; // Cycle time in us. int i2c__frequency = 400000; // I2C Frequency. int baud_rate = 115200; // Baud rate. short piezo_resistive_array[8] = {0,0,0,0,0,0,0,0}; // 8 PR sensors 1 time per cycle. @@ -117,7 +117,7 @@ bool test_belt = 0; // Set test mode on (log functions to pc serial: interrupts, LED intensity and serial messages): -bool test_mode = 1; +bool test_mode = 0; // Variable for connection test (should be changed): int connection_test_sensorplate; @@ -588,6 +588,7 @@ } void read_adc() { + return; piezo_electric_sample_timer.reset(); // Clock gebruiken o.i.d.? piezo_electric_sample_timer.start(); connection_test_sensorplate = angle_device_sensorplate.testConnection(); @@ -658,7 +659,7 @@ uint32_t val = 0; colour_select_indicating_LED_wall(LED_colour); // Function to select colour. - indicator_LEDs.update(generate, NUMBER_LED_FRONT, val); // Function to set the LED's which shines to the wall (indicating change patient position). +// indicator_LEDs.update(generate, NUMBER_LED_FRONT, val); // Function to set the LED's which shines to the wall (indicating change patient position). set_userinterface_LED(); // Set LED's of user interface (LED's above buttons). while(piezo_electric_sample_timer.read_us()<(4*(total_readout_cycle_time_us/5))) {} // Wait untill 80% of cycle. Energy efficiency is not fine in this situation, correct if low energy is needed. @@ -689,7 +690,7 @@ } if (test_mode == 1) { - usb_serial.printf("Loop time: %d ms\n",piezo_electric_sample_timer.read_ms()); + usb_serial.printf("Loop time: %d ms\n", piezo_electric_sample_timer.read_ms()); } // * End of if statements for test purposal. } @@ -706,6 +707,11 @@ adsAccu.setGain(GAIN_TWOTHIRDS); // #) End of configuration ADC ranges. pi_serial.format(8, SerialBase::None, 1); // Set serial communication line with PI. + button_lock.mode(PullUp); + button_reposition.mode(PullUp); + button_mute.mode(PullUp); + button_new_patient.mode(PullUp); + button_lock.fall(&trigger_lock); // Interrupt for rising edge lock button. button_lock.rise(&end_timer_lock_button); button_reposition.fall(&reposition_button_triggered); @@ -720,9 +726,130 @@ lock_feedback_LED = control_LED_intensity; // Lock LED initialization. - total_readout_cycle.attach_us(&read_adc, total_readout_cycle_time_us); // Call function to start reading sensorplate and other functionalities. +// total_readout_cycle.attach_us(&read_adc, total_readout_cycle_time_us); // Call function to start reading sensorplate and other functionalities. while (1) { - wait_us(total_readout_cycle_time_us+1); // Wait indefinitely. +// wait_us(total_readout_cycle_time_us+1); // Wait indefinitely. + piezo_electric_sample_timer.reset(); // Clock gebruiken o.i.d.? + piezo_electric_sample_timer.start(); + connection_test_sensorplate = angle_device_sensorplate.testConnection(); + + if (test_mode == 1) { + usb_serial.printf("Connection test sensorplate = %d\n", connection_test_sensorplate); + } + if (test_mode == 0) { + usb_serial.printf("Loop time: %d ms\n",piezo_electric_sample_timer.read_ms()); + } + /* + if (connection_test_sensorplate == 0) { + lock_state = 1; + LED_on_dev_board2 = 1; + lock_feedback_LED = 0; + }*/ + + if (connection_test_sensorplate == 1) { + piezo_electric_array[0] = piezo_electric_adc.readADC_SingleEnded(0); // First PE readout. + + for (uint8_t k = 0; k < 4; ++k) { + piezo_resistive_array[k] = piezo_resistive_adc1.readADC_SingleEnded(k); // First 4 PR readout. + } + if (test_mode == 0) { + usb_serial.printf("Loop time: %d ms\n",piezo_electric_sample_timer.read_ms()); + } + while(piezo_electric_sample_timer.read_us()<(1*(total_readout_cycle_time_us/5))) {} // Wait untill 20% of cycle. Energy efficiency is not fine in this situation, correct if low energy is needed. + + piezo_electric_array[1] = piezo_electric_adc.readADC_SingleEnded(0); // Second PE readout. + + for (uint8_t k = 0; k < 4; ++k) { + piezo_resistive_array[k+4] = piezo_resistive_adc2.readADC_SingleEnded(k); // Last 4 PR readout. + } + if (test_mode == 0) { + usb_serial.printf("Loop time: %d ms\n",piezo_electric_sample_timer.read_ms()); + } + + while(piezo_electric_sample_timer.read_us()<(2*(total_readout_cycle_time_us/5))) {} // Wait untill 40% of cycle. Energy efficiency is not fine in this situation, correct if low energy is needed. + + piezo_electric_array[2] = piezo_electric_adc.readADC_SingleEnded(0); // Third PE readout. + + angle_device_sensorplate.getAccelero(accelerometer_sensorplate); // Get accelerometer data. + angle = accelerometer_sensorplate[2]*100; + if(angle == 0) { + MPU6050 angle_device_sensorplate(PB_9, PB_8); + angle_device_sensorplate.getAccelero(accelerometer_sensorplate); + angle = accelerometer_sensorplate[2]*100; + } + angle_device_sensorplate.getGyro(gyroscope_sensorplate); // Get gyroscope data. + if (test_mode == 0) { + usb_serial.printf("Loop time: %d ms\n",piezo_electric_sample_timer.read_ms()); + } + //if (test_belt == 1) { +// angle_device_reference_belt.getGyro(gyroscope_reference_belt); // Get gyroscope data from Belt. +// angle_device_reference_belt.getAccelero(accelerometer_reference_belt); // Get accelerometer data from belt. +// } + + if (connection_test_sensorplate == 1) { // If statement for sending serial information sensorplate data when connection test is active. + // Receiving order sensor information: 3 accelero sensors & 3 gyroscope sensors from sensorplate; 3 accelero sensors & 3 gyroscope sensors from belt. Is splitted in two parts - part 2/2. + pi_serial.printf("?,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,\n", accelerometer_sensorplate[0], accelerometer_sensorplate[1], accelerometer_sensorplate[2], gyroscope_sensorplate[0], gyroscope_sensorplate[1], gyroscope_sensorplate[2], accelerometer_reference_belt[0], accelerometer_reference_belt[1], accelerometer_reference_belt[2], gyroscope_reference_belt[0], gyroscope_reference_belt[1], gyroscope_reference_belt[2]); + } // binair print and convert in pi + + while(piezo_electric_sample_timer.read_us()<(3*(total_readout_cycle_time_us/5))) {} // Wait untill 60% of cycle. Energy efficiency is not fine in this situation, correct if low energy is needed. + + piezo_electric_array[3] = piezo_electric_adc.readADC_SingleEnded(0); // Fourth PE readout. + } + if (test_mode == 0) { + usb_serial.printf("Loop time: %d ms\n",piezo_electric_sample_timer.read_ms()); + } + timer_functions(); + if (test_mode == 0) { + usb_serial.printf("Loop time: %d ms\n",piezo_electric_sample_timer.read_ms()); + } + batteryvoltage_current = batteryvoltage_last; + powervoltage_current = powervoltage_last; + read_voltage(); // Read_voltage function to control alarm. + if (test_mode == 0) { + usb_serial.printf("Loop time: %d ms\n",piezo_electric_sample_timer.read_ms()); + } + if (test_mode == 1) { + usb_serial.printf("Voltage = %d , %d\n", batteryvoltage_current, powervoltage_current); + } + + uint32_t val = 0; + colour_select_indicating_LED_wall(LED_colour); // Function to select colour. +// indicator_LEDs.update(generate, NUMBER_LED_FRONT, val); // Function to set the LED's which shines to the wall (indicating change patient position). + set_userinterface_LED(); // Set LED's of user interface (LED's above buttons). + + while(piezo_electric_sample_timer.read_us()<(4*(total_readout_cycle_time_us/5))) {} // Wait untill 80% of cycle. Energy efficiency is not fine in this situation, correct if low energy is needed. + + if (test_mode == 1){ // If statement for test purposal. + usb_serial.printf("Angle device sensorplate = %d\n",angle_device_sensorplate.testConnection()); + } + + if (connection_test_sensorplate == 1) { + piezo_electric_array[4] = piezo_electric_adc.readADC_SingleEnded(0); // Fifth PE readout. + } + + while(piezo_electric_sample_timer.read_us()<(4.25*(total_readout_cycle_time_us/5))) {} // Wait untill 85% of cycle. Energy efficiency is not fine in this situation, correct if low energy is needed. + + if (test_mode == 0) { + usb_serial.printf("Loop time: %d ms\n",piezo_electric_sample_timer.read_ms()); + } + serial_read(); // Call function for reading information from PI by serial connection. + serial_log(); // Call function for logging information to PI by serial connection. + + if (test_mode == 1) { // If statements for test purposal (untill * mark). + usb_serial.printf("Loop time: %d ms\n",piezo_electric_sample_timer.read_ms()); + } + //if (test_pin == 1) { +// test_mode = 1; +// usb_serial.printf("%d\n",test_mode); +// } +// if (test_pin == 0) { +// test_mode = 0; +// usb_serial.printf("%d\n",test_mode); +// } + + if (test_mode == 0) { + usb_serial.printf("Loop time: %d ms\n",piezo_electric_sample_timer.read_ms()); + } } } \ No newline at end of file