Nucleo-transfer
Dependencies: ADS1015 MPU6050 PixelArray PixelArray-Nucleo mbed WS2813
Fork of Nucleo-transfer by
Diff: Sensorplate/main.cpp
- Revision:
- 44:dcbde3175a37
- Parent:
- 43:d09814c177a0
- Child:
- 45:7ebe860702b4
--- a/Sensorplate/main.cpp Fri Dec 01 10:05:01 2017 +0000 +++ b/Sensorplate/main.cpp Fri Dec 01 16:09:08 2017 +0000 @@ -101,7 +101,7 @@ float accelerometer_reference_belt[3]; // Raw accelerometer data from belt. float gyroscope_reference_belt[3]; // Raw gyroscope data from belt. int colourbuf[NUM_COLORS] = {0xff0000,0x00ff00,0x0000ff,0xffff00,0xffffff}; // hex codes for the different colours -char LED_colour = 'g'; // Variable to set LED colour (standard set to green, untill PI sends other character). Other possible colours: red ('r') & yellow ('y'). +char LED_colour = 'w'; // Variable to set LED colour (standard set to green, untill PI sends other character). Other possible colours: red ('r') & yellow ('y'). bool lock_state = false, lock_flag = 0, mute_state = 0, alarm = 0, calibration_flag = 0, intensity_select = 1; // Boolean variables for logging states. bool mute_flag = 0, new_patient_flag = 0, reposition_flag = 0; // Flag variables. bool speaker_state = 0, LED_red_state = 0, LED_yellow_state = 0, LED_green_state = 0, power_plug_state = 0; @@ -119,8 +119,8 @@ int intensity_day = 40, intensity_night = 10; // Intensity settings for LED's to wall. double intensity = 0.0, control_LED_intensity = 0.0; // Variable between 0 and 1 to set the intensity of the LED's above the buttons. Intensity change to smart name! -int colour_code; - +int colour_code = 0b00; +bool pi_active = false; /*************************** TEST ********************************/ // Verify algoritm function: for belt activation, set test_belt 1 (connect pin p20 to 3.3V). Timer test_timer; @@ -156,6 +156,8 @@ { intensity_select = intensity_code; colour_code = (colour_code_1 << 1 | colour_code_0); + if(colour_code != 0b00 && pi_active == false){pi_active = true;} + if(pi_active){ switch(colour_code){ case 0b11 : LED_colour = 'y'; @@ -169,7 +171,10 @@ case 0b00 : LED_colour = 'r'; break; - } + default : + LED_colour = 'w'; + break; + }} //bool read = pi_serial.readable(); //usb_serial.printf("Readable = %d\n", read); // if (read_done) { // Function to check if pi is readable. @@ -543,6 +548,10 @@ void timer_functions() // Function which contains statements using timers. { + if (button_lock == 1){ + button_lock_hold_timer.stop(); + button_lock_hold_timer.reset(); + } if ((button_lock_hold_timer.read_ms() > locktime_ms) && lock_flag == 0 && button_lock == 0) { // If statement for lock function. lock_flag = 1; LED_on_dev_board2 = !LED_on_dev_board2; @@ -555,6 +564,11 @@ } } + if (button_new_patient == 1){ + button_calibration_hold_timer.stop(); + button_calibration_hold_timer.reset(); + } + if ((button_calibration_hold_timer.read_ms() > calibrationtime_ms) && calibration_flag == 0 && button_new_patient == 0 && lock_state == 0) { // If statement for calibration algorithm. calibration_flag = 1; calibration_flash = 11; @@ -841,9 +855,13 @@ // 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. + if (connection_test_sensorplate == 1) { + if (test_belt == 0) { // If statement for sending serial information sensorplate data when connection test is active. + pi_serial.printf("?,%f,%f,%f,%f,%f,%f,0,0,0,0,0,0,\n", accelerometer_sensorplate[0], accelerometer_sensorplate[1], accelerometer_sensorplate[2], gyroscope_sensorplate[0], gyroscope_sensorplate[1], gyroscope_sensorplate[2]); + } else{ // 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.