Nucleo-transfer
Dependencies: ADS1015 MPU6050 PixelArray PixelArray-Nucleo mbed WS2813
Fork of Nucleo-transfer by
Revision 70:204686903e4c, committed 2018-06-05
- Comitter:
- deldering95
- Date:
- Tue Jun 05 16:12:08 2018 +0000
- Parent:
- 69:98db4df7278f
- Child:
- 71:040674ed2ce1
- Commit message:
- I2C freeze, button freeze and button press time fixed
Changed in this revision
| Sensorplate/main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/Sensorplate/main.cpp Tue Jun 05 12:20:42 2018 +0000
+++ b/Sensorplate/main.cpp Tue Jun 05 16:12:08 2018 +0000
@@ -151,7 +151,7 @@
float percentage_tester=0;
// Variable to set if belt is used to test algorithm:
-bool test_belt = 1;
+bool test_belt = 0;
// Set test mode on (log functions to pc serial: interrupts, LED intensity and serial messages):
bool test_mode = 0;
@@ -451,7 +451,7 @@
px.Set(((16-leds_on)%16),ring_colour);
px.SetI(((16-leds_on)%16),int(0.01*led_partly*intensity*2.55));
}
- usb_serial.printf("percentage in %d,%d\n",percentage_in,leds_on);
+ //usb_serial.printf("percentage in %d,%d\n",percentage_in,leds_on);
if(patient_present==4) {
//if(mixer>20)mixer=20;
@@ -472,18 +472,18 @@
if(reposition_button_hold_timer.read_ms()) {
- //usb_serial.printf("filling circle\n");
+ usb_serial.printf("filling circle repo\n");
circle_filling_reposition = true;
- colour_wheel_filler = reposition_button_hold_timer.read_ms()/250;
- if(colour_wheel_filler>=8) {
- colour_wheel_filler=8;
+ colour_wheel_filler = reposition_button_hold_timer.read_ms()/250+1;
+ if(colour_wheel_filler>=9) {
+ colour_wheel_filler=9;
circle_filled_reposition = 15;
circle_filling_reposition = false;
colour_wheel_drain_reposition = false;
reposition_flag = 1;
}
px.SetAll(colourbuf[6]);
- for(int k =0; k<=colour_wheel_filler; k++) {
+ for(int k =0; k<colour_wheel_filler; k++) {
px.Set(k,colourbuf[5]);
px.Set(16-k,colourbuf[5]);
}
@@ -491,80 +491,83 @@
}
if(new_patient_button_hold_timer.read_ms()) {
- //usb_serial.printf("filling circle\n");
+ usb_serial.printf("filling circle patient\n");
circle_filling_new_patient = true;
- colour_wheel_filler = new_patient_button_hold_timer.read_ms()/250;
- if(colour_wheel_filler>=8) {
- colour_wheel_filler=8;
+ colour_wheel_filler = new_patient_button_hold_timer.read_ms()/250+1;
+ usb_serial.printf("Hold %d\n",colour_wheel_filler);
+ if(colour_wheel_filler>=9) {
+ colour_wheel_filler=9;
circle_filled_new_patient = 10;
circle_filling_new_patient = false;
colour_wheel_drain_new_patient = false;
new_patient_flag = 1;
+ //usb_serial.printf("patient filled");
}
px.SetAll(colourbuf[6]);
- for(int k =0; k<=colour_wheel_filler; k++) {
+ for(int k =0; k<colour_wheel_filler; k++) {
px.Set((k+8)%16,colourbuf[5]);
px.Set((16-k+8)%16,colourbuf[5]);
+ //usb_serial.printf("counter %d\n",k);
}
px.SetAllI(int(intensity*2.55));
}
if(!reposition_button_hold_timer.read_ms()&&circle_filling_reposition&&!colour_wheel_drain_reposition) {
- //usb_serial.printf("Short hold\n");
+ //usb_serial.printf("Short hold repo\n");
px.SetAll(colourbuf[6]);
- for(int k =0; k<=colour_wheel_filler; k++) {
+ for(int k =0; k<colour_wheel_filler; k++) {
px.Set(k,colourbuf[5]);
px.Set(16-k,colourbuf[5]);
}
px.SetAllI(int(intensity*2.55));
- colour_wheel_filler++;
if(colour_wheel_filler>=5) {
colour_wheel_drain_reposition=true;
circle_filling_reposition=false;
- }
+ } else colour_wheel_filler++;
}
if(!new_patient_button_hold_timer.read_ms()&&circle_filling_new_patient&&!colour_wheel_drain_new_patient) {
- //usb_serial.printf("Short hold\n");
+ //usb_serial.printf("Short hold patient\n");
px.SetAll(colourbuf[6]);
- for(int k =0; k<=colour_wheel_filler; k++) {
+ for(int k =0; k<colour_wheel_filler; k++) {
px.Set((k+8)%16,colourbuf[5]);
px.Set((16-k+8)%16,colourbuf[5]);
}
px.SetAllI(int(intensity*2.55));
- colour_wheel_filler++;
if(colour_wheel_filler>=5) {
colour_wheel_drain_new_patient=true;
circle_filling_new_patient=false;
- }
+ } else colour_wheel_filler++;
}
-
+ //usb_serial.printf("pre drain %d\n",colour_wheel_filler);
if(colour_wheel_drain_reposition) {
- //usb_serial.printf("drain\n");
+ //usb_serial.printf("drain_repo\n");
px.SetAll(colourbuf[6]);
- for(int k =0; k<=colour_wheel_filler; k++) {
+ for(int k =0; k<colour_wheel_filler; k++) {
px.Set(k,colourbuf[5]);
px.Set(16-k,colourbuf[5]);
}
px.SetAllI(int(intensity*2.55));
colour_wheel_filler--;
+ if(colour_wheel_filler<0)colour_wheel_filler=0;
if(!colour_wheel_filler)colour_wheel_drain_reposition=false;
}
-
+ //usb_serial.printf("post repo %d\n",colour_wheel_filler);
if(colour_wheel_drain_new_patient) {
- //usb_serial.printf("drain\n");
+ //usb_serial.printf("drain_patient\n");
px.SetAll(colourbuf[6]);
- for(int k =0; k<=colour_wheel_filler; k++) {
+ for(int k =0; k<colour_wheel_filler; k++) {
px.Set((k+8)%16,colourbuf[5]);
px.Set((16-k+8)%16,colourbuf[5]);
}
px.SetAllI(int(intensity*2.55));
colour_wheel_filler--;
+ if(colour_wheel_filler<0)colour_wheel_filler=0;
if(!colour_wheel_filler)colour_wheel_drain_new_patient=false;
}
-
+ //usb_serial.printf("post drain %d\n",colour_wheel_filler);
if(circle_filled_reposition) {
- //usb_serial.printf("circle_filled_repo\n");
+ usb_serial.printf("circle_filled_repo\n");
px.SetAll(colourbuf[6]);
for(int k =0; k<=circle_filled_reposition; k++) {
px.Set((16-k)%16,colourbuf[5]);
@@ -576,7 +579,7 @@
}
if(circle_filled_new_patient) {
- //usb_serial.printf("circle_filled_new_patient\n");
+ usb_serial.printf("circle_filled_new_patient\n");
px.SetAll(colourbuf[5]);
px.SetAllI(int(intensity*2.55*(7-(circle_filled_new_patient%5))/7));
circle_filled_new_patient--;
@@ -834,6 +837,11 @@
button_calibration_hold_timer.reset();
}
+ if (button_new_patient == 1) {
+ new_patient_button_hold_timer.stop();
+ new_patient_button_hold_timer.reset();
+ }
+
if (button_reposition == 1) {
reposition_button_hold_timer.stop();
reposition_button_hold_timer.reset();
@@ -899,9 +907,13 @@
void sensorplate_detached()
{
- if(piezo_electric_sample_timer.read_us() > total_readout_cycle_time_us) {
- NVIC_SystemReset();
- }
+ //NVIC_SystemReset();
+I2C i2c_sensorplate_adc(PB_9, PB_8); // I2C for sensorplate.
+MPU6050_belt angle_device_sensorplate(PB_9, PB_8); // i2c pins // i2c address hardcoded 0x68.
+MPU6050 angle_device_reference_belt(PB_9, PB_8); // i2c pins // i2c address hardcoded 0x69.
+Adafruit_ADS1115 piezo_resistive_adc1(&i2c_sensorplate_adc, 0x48); // i2c pins, i2c address.
+Adafruit_ADS1115 piezo_resistive_adc2(&i2c_sensorplate_adc, 0x49); // i2c pins, i2c address.
+Adafruit_ADS1115 piezo_electric_adc(&i2c_sensorplate_adc, 0x4B); // i2c pins, i2c address.
}
@@ -931,7 +943,8 @@
button_mute.mode(PullUp);
button_new_patient.mode(PullUp);
- testpin_sensorplate.fall(&sensorplate_detached);
+ testpin_sensorplate.rise(&sensorplate_detached);
+ testpin_sensorplate.fall(&sensorplate_detached);
button_lock.fall(&trigger_lock); // Interrupt for rising edge lock button.
button_lock.rise(&end_timer_lock_button);
button_reposition.fall(&reposition_button_triggered);
@@ -1019,7 +1032,7 @@
piezo_electric_sample_timer.reset(); // Clock gebruiken o.i.d.?
piezo_electric_sample_timer.start();
connection_test_sensorplate = !testpin_sensorplate && pi_active;
- //usb_serial.printf("Loop\n");
+ usb_serial.printf("Loop %d\n",connection_test_sensorplate);
if (test_mode == 1) {
// usb_serial.printf("Connection test sensorplate = %d\n", connection_test_sensorplate);
@@ -1028,8 +1041,10 @@
// usb_serial.printf("Loop time: %d ms\n",piezo_electric_sample_timer.read_ms());
}
- if (connection_test_sensorplate == 1) {
+ if (!testpin_sensorplate) {
+ usb_serial.printf("%d\n",piezo_electric_sample_timer.read_us());
piezo_electric_array[0] = piezo_electric_adc.readADC_Differential_0_3(); // First PE readout.
+ usb_serial.printf("%d\n",piezo_electric_sample_timer.read_us());
piezo_electric_array[3] = piezo_electric_adc.readADC_Differential_1_3(); // First PE readout.
for (uint8_t k = 0; k < 4; ++k) {
@@ -1103,7 +1118,7 @@
if(uart_input_buffer[i]=='='&&(uart_input_buffer[(i+2)%4]=='{'||uart_input_buffer[(i+2)%4]=='='))patient_present=uart_input_buffer[(i+1)];
if(uart_input_buffer[i]=='{'&&(uart_input_buffer[(i+2)%4]=='='||uart_input_buffer[(i+2)%4]=='{'))LED_colour_wheel_percentage=uart_input_buffer[(i+1)];
if((patient_present_old==4&&patient_present!=4)||(patient_present_old!=4&&patient_present==4))mixer=0;
- usb_serial.putc(uart_input_buffer[i]);
+ //usb_serial.putc(uart_input_buffer[i]);
}
patient_present_old=patient_present;
buffer_counter=0;
