From c56c4ae24083a9871b2c724069018471cc0308b8 Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Thu, 11 Oct 2012 10:52:52 -0700 Subject: [PATCH] Various example sketches: hal.uart0->begin(115200) is redundant. use console. just assume uart0 is initialized by the HAL, because it is. DRY. also, don't ever use uart0 explicitly in example sketches, use console and let the hal figure it out. --- .../AC_PID/examples/AC_PID_test/AC_PID_test.pde | 1 - .../AP_GPS/examples/GPS_AUTO_test/GPS_AUTO_test.pde | 1 - libraries/AP_HAL_AVR/examples/APM1/APM1.pde | 5 ++--- libraries/AP_HAL_AVR/examples/Console/Console.pde | 4 ---- .../examples/DataflashTest/DataflashTest.pde | 1 - .../AP_HAL_AVR/examples/FastSerial/FastSerial.pde | 4 ++-- .../I2CDriver_HMC5883L/I2CDriver_HMC5883L.pde | 12 +++++------- .../AP_HAL_AVR/examples/RCInputTest/RCInputTest.pde | 9 +++++---- .../examples/RCPassthroughTest/RCPassthroughTest.pde | 9 +++++---- .../examples/SPIDriver_MPU6000/SPIDriver_MPU6000.pde | 8 ++++---- libraries/Filter/examples/Derivative/Derivative.pde | 6 +----- libraries/Filter/examples/Filter/Filter.pde | 3 --- .../Filter/examples/LowPassFilter/LowPassFilter.pde | 3 --- 13 files changed, 24 insertions(+), 42 deletions(-) diff --git a/libraries/AC_PID/examples/AC_PID_test/AC_PID_test.pde b/libraries/AC_PID/examples/AC_PID_test/AC_PID_test.pde index 2c751b410c..2140b694e7 100644 --- a/libraries/AC_PID/examples/AC_PID_test/AC_PID_test.pde +++ b/libraries/AC_PID/examples/AC_PID_test/AC_PID_test.pde @@ -22,7 +22,6 @@ const AP_HAL::HAL& hal = AP_HAL_AVR_APM2; // setup function void setup() { - hal.uart0->begin(115200); hal.console->println("ArduPilot Mega AC_PID library test"); hal.scheduler->delay(1000); diff --git a/libraries/AP_GPS/examples/GPS_AUTO_test/GPS_AUTO_test.pde b/libraries/AP_GPS/examples/GPS_AUTO_test/GPS_AUTO_test.pde index 9574bcbc35..07aaaa263d 100644 --- a/libraries/AP_GPS/examples/GPS_AUTO_test/GPS_AUTO_test.pde +++ b/libraries/AP_GPS/examples/GPS_AUTO_test/GPS_AUTO_test.pde @@ -42,7 +42,6 @@ void print_latlon(AP_HAL::BetterStream *s, int32_t lat_or_lon) void setup() { - hal.uart0->begin(115200); hal.uart1->begin(38400); hal.uart0->println("GPS AUTO library test"); diff --git a/libraries/AP_HAL_AVR/examples/APM1/APM1.pde b/libraries/AP_HAL_AVR/examples/APM1/APM1.pde index 7e7c7ee016..2a408cde77 100644 --- a/libraries/AP_HAL_AVR/examples/APM1/APM1.pde +++ b/libraries/AP_HAL_AVR/examples/APM1/APM1.pde @@ -6,7 +6,7 @@ const AP_HAL::HAL& hal = AP_HAL_AVR_APM1; void loop (void) { - hal.uart0->println("."); + hal.console->println("."); hal.gpio->write(3, 0); hal.scheduler->delay(1000); hal.gpio->write(3, 1); @@ -33,9 +33,8 @@ void setup (void) { hal.gpio->write(13, 1); - hal.uart0->begin(115200); hal.gpio->write(1, 0); - hal.uart0->println("Hello World"); + hal.console->println("Hello World"); hal.gpio->write(2, 0); } diff --git a/libraries/AP_HAL_AVR/examples/Console/Console.pde b/libraries/AP_HAL_AVR/examples/Console/Console.pde index 0712f7f7c3..e44771bfe0 100644 --- a/libraries/AP_HAL_AVR/examples/Console/Console.pde +++ b/libraries/AP_HAL_AVR/examples/Console/Console.pde @@ -70,10 +70,6 @@ void stream_console_loopback(AP_HAL::Stream* s, AP_HAL::ConsoleDriver* c, } void setup(void) { - // - // Set the speed for our replacement serial port. - // - hal.uart0->begin(115200); // // Test printing things // diff --git a/libraries/AP_HAL_AVR/examples/DataflashTest/DataflashTest.pde b/libraries/AP_HAL_AVR/examples/DataflashTest/DataflashTest.pde index 764aad9117..e0593c25b6 100644 --- a/libraries/AP_HAL_AVR/examples/DataflashTest/DataflashTest.pde +++ b/libraries/AP_HAL_AVR/examples/DataflashTest/DataflashTest.pde @@ -159,7 +159,6 @@ void longtest_readback() void setup() { - hal.uart0->begin(115200); hal.dataflash->init(NULL); hal.uart0->println("Dataflash Log Test 1.0"); diff --git a/libraries/AP_HAL_AVR/examples/FastSerial/FastSerial.pde b/libraries/AP_HAL_AVR/examples/FastSerial/FastSerial.pde index 94a59164d4..caca01b70a 100644 --- a/libraries/AP_HAL_AVR/examples/FastSerial/FastSerial.pde +++ b/libraries/AP_HAL_AVR/examples/FastSerial/FastSerial.pde @@ -15,9 +15,9 @@ const AP_HAL::HAL& hal = AP_HAL_AVR_APM1; void setup(void) { // - // Set the speed for our replacement serial port. + // HAL will start serial port at 115200. // - hal.uart0->begin(115200); + // // Test printing things // diff --git a/libraries/AP_HAL_AVR/examples/I2CDriver_HMC5883L/I2CDriver_HMC5883L.pde b/libraries/AP_HAL_AVR/examples/I2CDriver_HMC5883L/I2CDriver_HMC5883L.pde index 027aafe352..048e08e64d 100644 --- a/libraries/AP_HAL_AVR/examples/I2CDriver_HMC5883L/I2CDriver_HMC5883L.pde +++ b/libraries/AP_HAL_AVR/examples/I2CDriver_HMC5883L/I2CDriver_HMC5883L.pde @@ -13,16 +13,14 @@ const AP_HAL_AVR::HAL_AVR& hal = AP_HAL_AVR_APM2; #define HMC5883L 0x1E void setup() { - hal.uart0->begin(115200); - hal.uart0->printf_P(PSTR("Initializing HMC5883L at address %x\r\n"), + hal.console->printf_P(PSTR("Initializing HMC5883L at address %x\r\n"), HMC5883L); - uint8_t stat = hal.i2c->writeRegister(HMC5883L,0x02,0x00); if (stat == 0) { - hal.uart0->printf_P(PSTR("successful init\r\n")); + hal.console->printf_P(PSTR("successful init\r\n")); } else { - hal.uart0->printf_P(PSTR("failed init: return status %d\r\n"), + hal.console->printf_P(PSTR("failed init: return status %d\r\n"), (int)stat); for(;;); } @@ -41,9 +39,9 @@ void loop() { y |= data[3]; z = data[4] << 8; z |= data[5]; - hal.uart0->printf_P(PSTR("x: %d y: %d z: %d \r\n"), x, y, z); + hal.console->printf_P(PSTR("x: %d y: %d z: %d \r\n"), x, y, z); } else { - hal.uart0->printf_P(PSTR("i2c error: status %d\r\n"), (int)stat); + hal.console->printf_P(PSTR("i2c error: status %d\r\n"), (int)stat); } } diff --git a/libraries/AP_HAL_AVR/examples/RCInputTest/RCInputTest.pde b/libraries/AP_HAL_AVR/examples/RCInputTest/RCInputTest.pde index 3cd17d8fa9..42dc19bdc7 100644 --- a/libraries/AP_HAL_AVR/examples/RCInputTest/RCInputTest.pde +++ b/libraries/AP_HAL_AVR/examples/RCInputTest/RCInputTest.pde @@ -10,7 +10,8 @@ void multiread(AP_HAL::RCInput* in) { uint16_t channels[8]; uint8_t valid; valid = in->read(channels, 8); - hal.uart0->printf_P(PSTR("multi read %d: %d %d %d %d %d %d %d %d\r\n"), + hal.console->printf_P( + PSTR("multi read %d: %d %d %d %d %d %d %d %d\r\n"), (int) valid, channels[0], channels[1], channels[2], channels[3], channels[4], channels[5], channels[6], channels[7]); @@ -24,7 +25,8 @@ void individualread(AP_HAL::RCInput* in) { for (int i = 0; i < 8; i++) { channels[i] = in->read(i); } - hal.uart0->printf_P(PSTR("individual read %d: %d %d %d %d %d %d %d %d\r\n"), + hal.console->printf_P( + PSTR("individual read %d: %d %d %d %d %d %d %d %d\r\n"), (int) valid, channels[0], channels[1], channels[2], channels[3], channels[4], channels[5], channels[6], channels[7]); @@ -50,8 +52,7 @@ void loop (void) { } void setup (void) { - hal.uart0->begin(115200); - hal.uart0->printf_P(PSTR("reading rc in:")); + hal.console->printf_P(PSTR("reading rc in:")); hal.gpio->pinMode(27, GPIO_OUTPUT); hal.gpio->write(27, 0); } diff --git a/libraries/AP_HAL_AVR/examples/RCPassthroughTest/RCPassthroughTest.pde b/libraries/AP_HAL_AVR/examples/RCPassthroughTest/RCPassthroughTest.pde index 82b8be8452..769657c50d 100644 --- a/libraries/AP_HAL_AVR/examples/RCPassthroughTest/RCPassthroughTest.pde +++ b/libraries/AP_HAL_AVR/examples/RCPassthroughTest/RCPassthroughTest.pde @@ -9,7 +9,8 @@ void multiread(AP_HAL::RCInput* in, uint16_t* channels) { /* Multi-channel read method: */ uint8_t valid; valid = in->read(channels, 8); - hal.uart0->printf_P(PSTR("multi read %d: %d %d %d %d %d %d %d %d\r\n"), + hal.console->printf_P( + PSTR("multi read %d: %d %d %d %d %d %d %d %d\r\n"), (int) valid, channels[0], channels[1], channels[2], channels[3], channels[4], channels[5], channels[6], channels[7]); @@ -22,7 +23,8 @@ void individualread(AP_HAL::RCInput* in, uint16_t* channels) { for (int i = 0; i < 8; i++) { channels[i] = in->read(i); } - hal.uart0->printf_P(PSTR("individual read %d: %d %d %d %d %d %d %d %d\r\n"), + hal.console->printf_P( + PSTR("individual read %d: %d %d %d %d %d %d %d %d\r\n"), (int) valid, channels[0], channels[1], channels[2], channels[3], channels[4], channels[5], channels[6], channels[7]); @@ -71,7 +73,6 @@ void loop (void) { } void setup (void) { - hal.uart0->begin(115200); hal.gpio->pinMode(27, GPIO_OUTPUT); hal.gpio->write(27, 0); hal.rcout->enable_mask(0x000000FF); @@ -79,7 +80,7 @@ void setup (void) { /* Bottom 4 channels at 400hz (like on a quad) */ hal.rcout->set_freq(0x0000000F, 400); for(int i = 0; i < 12; i++) { - hal.uart0->printf_P(PSTR("rcout ch %d has frequency %d\r\n"), + hal.console->printf_P(PSTR("rcout ch %d has frequency %d\r\n"), i, hal.rcout->get_freq(i)); } /* Delay to let the user see the above printouts on the terminal */ diff --git a/libraries/AP_HAL_AVR/examples/SPIDriver_MPU6000/SPIDriver_MPU6000.pde b/libraries/AP_HAL_AVR/examples/SPIDriver_MPU6000/SPIDriver_MPU6000.pde index 50d3f4993d..599b9c3b7b 100644 --- a/libraries/AP_HAL_AVR/examples/SPIDriver_MPU6000/SPIDriver_MPU6000.pde +++ b/libraries/AP_HAL_AVR/examples/SPIDriver_MPU6000/SPIDriver_MPU6000.pde @@ -103,8 +103,7 @@ static void mpu6k_read(int16_t* data) { } static void setup() { - hal.uart0->begin(115200); - hal.uart0->printf_P(PSTR("Initializing MPU6000\r\n")); + hal.console->printf_P(PSTR("Initializing MPU6000\r\n")); /* Setup the barometer cs to stop it from holding the bus */ hal.gpio->pinMode(_baro_cs_pin, GPIO_OUTPUT); @@ -117,7 +116,8 @@ static void setup() { uint8_t spcr = SPCR; uint8_t spsr = SPSR; - hal.uart0->printf_P(PSTR("SPCR 0x%x, SPSR 0x%x\r\n"), (int)spcr, (int)spsr); + hal.console->printf_P(PSTR("SPCR 0x%x, SPSR 0x%x\r\n"), + (int)spcr, (int)spsr); mpu6k_init(); } @@ -125,7 +125,7 @@ static void setup() { static void loop() { int16_t sensors[7]; mpu6k_read(sensors); - hal.uart0->printf_P(PSTR("mpu6k: %d %d %d %d %d %d %d\r\n"), + hal.console->printf_P(PSTR("mpu6k: %d %d %d %d %d %d %d\r\n"), sensors[0], sensors[1], sensors[2], sensors[3], sensors[4], sensors[5], sensors[6]); hal.scheduler->delay(10); diff --git a/libraries/Filter/examples/Derivative/Derivative.pde b/libraries/Filter/examples/Derivative/Derivative.pde index e164a425e3..e3fec5b6b9 100644 --- a/libraries/Filter/examples/Derivative/Derivative.pde +++ b/libraries/Filter/examples/Derivative/Derivative.pde @@ -22,11 +22,7 @@ const AP_HAL::HAL& hal = AP_HAL_AVR_APM2; DerivativeFilter derivative; // setup routine -void setup() -{ - // Open up a serial connection - hal.uart0->begin(115200); -} +void setup(){} static float noise(void) { diff --git a/libraries/Filter/examples/Filter/Filter.pde b/libraries/Filter/examples/Filter/Filter.pde index 47b4d4df93..3177b82a52 100644 --- a/libraries/Filter/examples/Filter/Filter.pde +++ b/libraries/Filter/examples/Filter/Filter.pde @@ -26,9 +26,6 @@ AverageFilterUInt16_Size4 _temp_filter; void setup() { - // Open up a serial connection - hal.uart0->begin(115200); - // introduction hal.console->printf("ArduPilot ModeFilter library test ver 1.0\n\n"); diff --git a/libraries/Filter/examples/LowPassFilter/LowPassFilter.pde b/libraries/Filter/examples/LowPassFilter/LowPassFilter.pde index 3dbae6cbb8..8f0d90a71a 100644 --- a/libraries/Filter/examples/LowPassFilter/LowPassFilter.pde +++ b/libraries/Filter/examples/LowPassFilter/LowPassFilter.pde @@ -20,9 +20,6 @@ LowPassFilterFloat low_pass_filter; // setup routine void setup() { - // Open up a serial connection - hal.uart0->begin(115200); - // introduction hal.console->printf("ArduPilot LowPassFilter test ver 1.0\n\n");