![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
ft. button press reset
Fork of BeaconDemo_RobotCode by
Diff: PsiSwarm/i2c.cpp
- Revision:
- 5:598298aa4900
- Parent:
- 0:8a5497a2e366
- Child:
- 6:ff3c66f7372b
--- a/PsiSwarm/i2c.cpp Mon Oct 12 12:39:35 2015 +0000 +++ b/PsiSwarm/i2c.cpp Tue Oct 13 11:47:14 2015 +0000 @@ -22,8 +22,6 @@ Timeout update_timeout; -DigitalOut test_led(LED2); - char test; void IF_set_IR_emitter_output(char emitter, char state) @@ -146,16 +144,18 @@ //Port 0 = PGDL; PGDR; PGDIR; UP; DOWN; LEFT; RIGHT; CENTER //Port 1 = ENC_LA; ENC_LB; ENC_RA; ENC_RB; ID0; ID1; ID2; ID3 char data [3]; + char okay = 1; data [0] = 0x06; //Write config registers data [1] = 0xFF; //All 8 pins in port 0 are inputs (1) data [2] = 0xFF; //All 8 pins in port 1 are inputs (1) if(primary_i2c.write(GPIO_IC_ADDRESS,data,3,false) != 0) { system_warnings += 2; + okay = 0; debug("- WARNING: No I2C acknowledge for main GPIO IC\n"); } //Set all inputs to polarity-inverted (so a logic low = 1) data [0] = 0x04; //Write to polarity inversion ports - data [1] = 0xFF; //Invert polarity of all bits in input port 0 + data [1] = 0xF8; //Invert polarity of all switch input bits in input port 0 [but not power-good inputs] data [2] = 0xFF; //Invert polarity of all bits in input port 1 primary_i2c.write(GPIO_IC_ADDRESS,data,3,false); @@ -170,8 +170,10 @@ gpio_byte0 = read_data[0]; //char ret_val = (gpio_byte0 & 0xF8) >> 3; //Returns a >0 value if a button is being pushed gpio_byte1 = read_data[1]; + if(okay && testing_voltage_regulators_flag)debug("- Checking 3.3V voltage regulators\n"); IF_parse_gpio_byte0(gpio_byte0); IF_parse_gpio_byte1(gpio_byte1); + testing_voltage_regulators_flag = 0; //Setup interrupt handler for GPIO interrupts gpio_interrupt.mode(PullUp); gpio_interrupt.rise(&IF_handle_gpio_interrupt); @@ -214,6 +216,30 @@ switch_byte = current_switch; switch_set = 1; } + if(((gpio_byte0 & 0x01)) != power_good_motor_left){ + power_good_motor_left = (gpio_byte0 & 0x01); + if(!power_good_motor_left){ + if(testing_voltage_regulators_flag || SHOW_VR_WARNINGS)debug("- WARNING: Voltage regulator left motor low\n"); + } + else if(testing_voltage_regulators_flag)debug("- Power good left motor v.reg\n"); + } + if(((gpio_byte0 & 0x02) >> 1) != power_good_motor_right){ + power_good_motor_right = (gpio_byte0 & 0x02) >> 1; + if(!power_good_motor_right){ + if(testing_voltage_regulators_flag || SHOW_VR_WARNINGS)debug("- WARNING: Voltage regulator right motor low\n"); + } + else if(testing_voltage_regulators_flag)debug("- Power good right motor v.reg\n"); + } + if(((gpio_byte0 & 0x04) >> 2) != power_good_infrared){ + power_good_infrared = (gpio_byte0 & 0x04) >> 2; + if(!power_good_infrared){ + if(testing_voltage_regulators_flag || SHOW_VR_WARNINGS)debug("- WARNING: Voltage regulator infrared low\n"); + } + else if(testing_voltage_regulators_flag)debug("- Power good infrared and aux v.reg\n"); + } + if(USE_LED4_FOR_VR_WARNINGS){ + mbed_led4 = (!power_good_motor_left || !power_good_motor_right || !power_good_infrared); + } } void IF_parse_gpio_byte1(char byte) @@ -249,7 +275,7 @@ void IF_handle_gpio_interrupt() { test = 1-test; - test_led = test; + if(USE_LED3_FOR_INTERRUPTS) mbed_led3 = test; IF_update_gpio_inputs(); }