diff options
author | bnewbold <bnewbold@robocracy.org> | 2010-04-27 18:48:00 -0400 |
---|---|---|
committer | bnewbold <bnewbold@robocracy.org> | 2010-04-27 18:49:57 -0400 |
commit | b9fba8a471bc570a2c20283beb60a56e242dd49d (patch) | |
tree | 1d777d23d959813e58d738779b4c56abc61cfe38 | |
parent | 434e223114b0398b92f3c027747f82bd7187569a (diff) | |
download | librambutan-b9fba8a471bc570a2c20283beb60a56e242dd49d.tar.gz librambutan-b9fba8a471bc570a2c20283beb60a56e242dd49d.zip |
updated test-session with new banner art etc
-rw-r--r-- | examples/test-session.cpp | 227 |
1 files changed, 163 insertions, 64 deletions
diff --git a/examples/test-session.cpp b/examples/test-session.cpp index 0fa7d52..b760d97 100644 --- a/examples/test-session.cpp +++ b/examples/test-session.cpp @@ -22,14 +22,7 @@ * THE SOFTWARE.
* ****************************************************************************/
-/**
- * @file example_main.cpp
- *
- * @brief Sample main.cpp file. Blinks an LED, sends a message out USART2
- * and turns on PWM on pin 2
- */
-
-#include "wiring.h"
+#include "wirish.h"
#include "HardwareSerial.h"
#include "HardwareUsb.h"
#include <math.h>
@@ -46,8 +39,9 @@ int toggle = 0; int rate = 0;
int sample = 0;
-// read off maple board rev3
+// read these off maple board rev3
const uint8 pwm_pins[] = {0,1,2,3,5,6,7,8,9,11,12,14,24,25,27,28};
+// note that 38 is just a button and 39+ aren't functional as of 04/22/2010
const uint8 adc_pins[] = {0,1,2,10,11,12,13,15,16,17,18,19,20,27,28};
#define NUM_GPIO 44 // 43 is the MAX
uint8 gpio_state[NUM_GPIO];
@@ -63,20 +57,26 @@ void setup() { /* Set up the LED to blink */
pinMode(LED_PIN, OUTPUT);
- /* Send a message out USART2 */
- //Serial2.begin(115200);
+ /* Send a message out over USART2 */
+ //Serial2.begin(115200); // 9600 is more compatible
Serial2.begin(9600);
Serial2.println("");
+ Serial2.println(" __ __ _ _");
+ Serial2.println(" | \\/ | __ _ _ __ | | ___| |");
+ Serial2.println(" | |\\/| |/ _` | '_ \\| |/ _ \\ |");
+ Serial2.println(" | | | | (_| | |_) | | __/_|");
+ Serial2.println(" |_| |_|\\__,_| .__/|_|\\___(_)");
+ Serial2.println(" |_|");
+ Serial2.println(" by leaflabs");
+ Serial2.println("");
+ Serial2.println("");
Serial2.println("Maple interactive test program (type '?' for help)");
Serial2.println("------------------------------------------------------------");
Serial2.print("> ");
- /* Turn on PWM on pin PWM_PIN */
- //pinMode(PWM_PIN, PWM);
- //pwmWrite(PWM_PIN, 0x8000);
/* Send a message out the USB virtual com port */
// TODO: this should all be over usb as well
- Usb.println("Maple test program starting; use serial port for interactivity");
+ //Usb.println("Maple test program starting; use serial port for interactivity");
}
void loop() {
@@ -84,7 +84,6 @@ void loop() { digitalWrite(LED_PIN, toggle);
delay(100);
- //Serial2.flush();
while(Serial2.available()) {
input = Serial2.read();
Serial2.println(input);
@@ -95,8 +94,6 @@ void loop() { Serial2.println("spacebar, nice!");
break;
case 63: // '?'
- print_help();
- break;
case 104: // 'h'
print_help();
break;
@@ -108,9 +105,63 @@ void loop() { Serial2.println("Hello World!");
Serial3.println("Hello World!");
break;
+ case 109: // 'm'
+ Serial2.println("Testing 57600 baud on USART1 and USART3. Press enter.");
+ Serial1.begin(57600);
+ Serial3.begin(57600);
+ while(!Serial2.available()) {
+ Serial1.println(DUMMY_DAT);
+ Serial3.println(DUMMY_DAT);
+ if(Serial1.available()) {
+ Serial1.println(Serial1.read());
+ delay(1000);
+ }
+ if(Serial3.available()) {
+ Serial3.println(Serial3.read());
+ delay(1000);
+ }
+ }
+ Serial2.read();
+ Serial2.println("Testing 115200 baud on USART1 and USART3. Press enter.");
+ Serial1.begin(115200);
+ Serial3.begin(115200);
+ while(!Serial2.available()) {
+ Serial1.println(DUMMY_DAT);
+ Serial3.println(DUMMY_DAT);
+ if(Serial1.available()) {
+ Serial1.println(Serial1.read());
+ delay(1000);
+ }
+ if(Serial3.available()) {
+ Serial3.println(Serial3.read());
+ delay(1000);
+ }
+ }
+ Serial2.read();
+ Serial2.println("Testing 9600 baud on USART1 and USART3. Press enter.");
+ Serial1.begin(9600);
+ Serial3.begin(9600);
+ while(!Serial2.available()) {
+ Serial1.println(DUMMY_DAT);
+ Serial3.println(DUMMY_DAT);
+ if(Serial1.available()) {
+ Serial1.println(Serial1.read());
+ delay(1000);
+ }
+ if(Serial3.available()) {
+ Serial3.println(Serial3.read());
+ delay(1000);
+ }
+ }
+ Serial2.read();
+ Serial2.println("Resetting USART1 and USART3...");
+ Serial1.begin(9600);
+ Serial3.begin(9600);
+ break;
case 46: // '.'
while(!Serial2.available()) {
Serial2.print(".");
+ Usb.print(".");
}
//Serial2.flush();
break;
@@ -118,8 +169,9 @@ void loop() { Serial2.println("Taking ADC noise stats...");
// turn off LED
digitalWrite(LED_PIN, 0);
- // make sure to skip the TX/RX pins
- for(int i = 2; i<sizeof(adc_pins); i++) {
+ // make sure to skip the TX/RX headers
+ for(uint32 i = 2; i<sizeof(adc_pins); i++) {
+ delay(5);
do_noise(adc_pins[i]);
}
break;
@@ -127,10 +179,10 @@ void loop() { Serial2.println("Taking ADC noise stats under duress...");
// turn off LED
digitalWrite(LED_PIN, 0);
- // make sure to skip the TX/RX pins
- for(int i = 2; i<sizeof(adc_pins); i++) {
+ // make sure to skip the TX/RX headers
+ for(uint32 i = 2; i<sizeof(adc_pins); i++) {
// spool up PWM
- for(int j = 2; j<sizeof(pwm_pins); j++) {
+ for(uint32 j = 2; j<(uint32)sizeof(pwm_pins); j++) {
if(adc_pins[i] != pwm_pins[j]) {
pinMode(pwm_pins[j],PWM);
pwmWrite(pwm_pins[j], 1000 + i);
@@ -139,7 +191,7 @@ void loop() { Usb.print(DUMMY_DAT);
Usb.print(DUMMY_DAT);
do_noise(adc_pins[i]);
- for(int j = 2; j<sizeof(pwm_pins); j++) {
+ for(uint32 j = 2; j<(uint32)sizeof(pwm_pins); j++) {
if(adc_pins[i] != pwm_pins[j]) {
pinMode(pwm_pins[j],OUTPUT);
digitalWrite(pwm_pins[j],0);
@@ -164,13 +216,13 @@ void loop() { }
break;
case 103: // 'g'
- Serial2.print("Sequentially testing GPIO write on all possible pins except 0 and 1.");
+ Serial2.print("Sequentially testing GPIO write on all possible headers except D0 and D1.");
Serial2.println("Anything for next, ESC to stop.");
// turn off LED
digitalWrite(LED_PIN, 0);
- // make sure to skip the TX/RX pins
- for(int i = 2; i<NUM_GPIO; i++) {
- Serial2.print("GPIO write out on pin ");
+ // make sure to skip the TX/RX headers
+ for(uint32 i = 2; i<NUM_GPIO; i++) {
+ Serial2.print("GPIO write out on header D");
Serial2.print(i, DEC);
Serial2.println("...");
pinMode(i, OUTPUT);
@@ -187,23 +239,23 @@ void loop() { Serial2.println("Flipping all GPIOs at the same time. Press enter.");
// turn off LED
digitalWrite(LED_PIN, 0);
- // make sure to skip the TX/RX pins
- for(int i = 2; i<NUM_GPIO; i++) {
+ // make sure to skip the TX/RX headers
+ for(uint32 i = 2; i<NUM_GPIO; i++) {
pinMode(i, OUTPUT);
}
while(!Serial2.available()) {
tiddle ^= 1;
- for(int i = 2; i<NUM_GPIO; i++) {
+ for(uint32 i = 2; i<NUM_GPIO; i++) {
digitalWrite(i, tiddle);
}
}
- for(int i = 2; i<NUM_GPIO; i++) {
+ for(uint32 i = 2; i<NUM_GPIO; i++) {
digitalWrite(i, 0);
}
if((uint8)Serial2.read() == (uint8)27) break; // ESC
break;
case 102: // 'f'
- Serial2.println("Wiggling GPIO pin D4 as fast as possible in bursts. Press enter.");
+ Serial2.println("Wiggling GPIO header D4 as fast as possible in bursts. Press enter.");
pinMode(4,OUTPUT);
while(!Serial2.available()) {
do_fast_gpio();
@@ -211,13 +263,13 @@ void loop() { }
break;
case 112: // 'p'
- Serial2.println("Sequentially testing PWM on all possible pins except 0 and 1. ");
+ Serial2.println("Sequentially testing PWM on all possible headers except D0 and D1. ");
Serial2.println("Anything for next, ESC to stop.");
// turn off LED
digitalWrite(LED_PIN, 0);
- // make sure to skip the TX/RX pins
- for(int i = 2; i<sizeof(pwm_pins); i++) {
- Serial2.print("PWM out on pin ");
+ // make sure to skip the TX/RX headers
+ for(uint32 i = 2; i<sizeof(pwm_pins); i++) {
+ Serial2.print("PWM out on header D");
Serial2.print(pwm_pins[i], DEC);
Serial2.println("...");
pinMode(pwm_pins[i], PWM);
@@ -233,19 +285,19 @@ void loop() { // turn off LED
digitalWrite(LED_PIN, 0);
// make sure to skip the TX/RX pins
- for(int i = 2; i<sizeof(pwm_pins); i++) {
+ for(uint32 i = 2; i<sizeof(pwm_pins); i++) {
pinMode(pwm_pins[i], PWM);
pwmWrite(pwm_pins[i], 4000);
}
while(!Serial2.available()) {
rate += 20;
if(rate > 65500) rate = 0;
- for(int i = 2; i<sizeof(pwm_pins); i++) {
+ for(uint32 i = 2; i<sizeof(pwm_pins); i++) {
pwmWrite(pwm_pins[i], rate);
}
delay(1);
}
- for(int i = 2; i<sizeof(pwm_pins); i++) {
+ for(uint32 i = 2; i<sizeof(pwm_pins); i++) {
pinMode(pwm_pins[i], OUTPUT);
}
break;
@@ -258,6 +310,57 @@ void loop() { case 84: // 'T'
break;
case 115: // 's'
+ Serial2.println("Testing all PWM headers with a servo sweep. Press enter.");
+ Serial2.println("");
+ // turn off LED
+ digitalWrite(LED_PIN, 0);
+ timer_init(1, 21);
+ timer_init(2, 21);
+ timer_init(3, 21);
+ timer_init(4, 21);
+ // make sure to skip the TX/RX headers
+ for(uint32 i = 2; i<sizeof(pwm_pins); i++) {
+ pinMode(pwm_pins[i], PWM);
+ pwmWrite(pwm_pins[i], 4000);
+ }
+ // 1.25ms = 4096counts = 0deg
+ // 1.50ms = 4915counts = 90deg
+ // 1.75ms = 5734counts = 180deg
+ rate = 4096;
+ while(!Serial2.available()) {
+ rate += 20;
+ if(rate > 5734) rate = 4096;
+ for(uint32 i = 2; i<sizeof(pwm_pins); i++) {
+ pwmWrite(pwm_pins[i], rate);
+ }
+ delay(20);
+ }
+ for(uint32 i = 2; i<sizeof(pwm_pins); i++) {
+ pinMode(pwm_pins[i], OUTPUT);
+ }
+ timer_init(1, 1);
+ timer_init(2, 1);
+ timer_init(3, 1);
+ timer_init(4, 1);
+ Serial2.begin(9600);
+ Serial2.println("(reset serial port)");
+ break;
+ case 100: // 'd'
+ Serial2.println("Pulling down D4, D22");
+ pinMode(22,INPUT_PULLDOWN);
+ pinMode(4,INPUT_PULLDOWN);
+ while(!Serial2.available()) {
+ delay(1);
+ }
+ Serial2.read();
+ Serial2.println("Pulling up D4, D22");
+ pinMode(22,INPUT_PULLUP);
+ pinMode(4,INPUT_PULLUP);
+ while(!Serial2.available()) {
+ delay(1);
+ }
+ Serial2.read();
+ pinMode(4,OUTPUT);
break;
case 105: // 'i'
break;
@@ -267,7 +370,7 @@ void loop() { Serial2.println("Monitoring GPIO read state changes. Press enter.");
// turn off LED
digitalWrite(LED_PIN, 0);
- // make sure to skip the TX/RX pins
+ // make sure to skip the TX/RX headers
for(int i = 2; i<NUM_GPIO; i++) {
pinMode(i, INPUT);
gpio_state[i] = (uint8)digitalRead(i);
@@ -276,10 +379,10 @@ void loop() { for(int i = 2; i<NUM_GPIO; i++) {
tiddle = (uint8)digitalRead(i);
if(tiddle != gpio_state[i]) {
- Serial2.print("State change on pin ");
+ Serial2.print("State change on header D");
Serial2.print(i,DEC);
- if(tiddle) Serial2.println(":\tLOW");
- else Serial2.println(":\tHIGH");
+ if(tiddle) Serial2.println(":\tHIGH");
+ else Serial2.println(":\tLOW");
gpio_state[i] = tiddle;
}
}
@@ -293,9 +396,9 @@ void loop() { Serial2.println("Anything for next, ESC to stop.");
// turn off LED
digitalWrite(LED_PIN, 0);
- // make sure to skip the TX/RX pins
- for(int i = 2; i<sizeof(adc_pins); i++) {
- Serial2.print("Reading on pin ");
+ // make sure to skip the TX/RX headers
+ for(uint32 i = 2; i<sizeof(adc_pins); i++) {
+ Serial2.print("Reading on header D");
Serial2.print(adc_pins[i], DEC);
Serial2.println("...");
pinMode(adc_pins[i], INPUT_ANALOG);
@@ -341,7 +444,6 @@ void print_help(void) { Serial2.println("\tN: measure noise and do statistics with background stuff");
Serial2.println("\ta: show realtime ADC info");
Serial2.println("\t.: echo '.' until new input");
- Serial2.println("\te: do everything all at once until new input");
Serial2.println("\tu: print Hello World on USB");
Serial2.println("\t_: try to do as little as possible for a couple seconds (delay)");
Serial2.println("\tp: test all PWM channels sequentially");
@@ -352,18 +454,19 @@ void print_help(void) { Serial2.println("\tf: toggle GPIO D4 as fast as possible in bursts");
Serial2.println("\tP: test all PWM channels at the same time with different speeds/sweeps");
Serial2.println("\tr: read in GPIO status changes and print them in realtime");
+ Serial2.println("\ts: output a sweeping SERVO PWM on all PWM channels");
+ Serial2.println("\tm: output serial data dumps on USART1 and USART3 with various rates");
Serial2.println("Unimplemented:");
+ Serial2.println("\te: do everything all at once until new input");
Serial2.println("\tt: output a 1khz squarewave on all GPIOs as well as possible");
Serial2.println("\tT: output a 1hz squarewave on all GPIOs as well as possible");
- Serial2.println("\ts: output a sweeping SERVO PWM on all PWM channels");
Serial2.println("\ti: print out a bunch of info about system state");
- Serial2.println("\tI: print out status of all pins");
- // uint32 digitalRead(uint8 pin)
+ Serial2.println("\tI: print out status of all headers");
}
void do_noise(uint8 pin) { // TODO
- uint16 data[64];
+ uint16 data[100];
float mean = 0;
//float stddev = 0;
float delta = 0;
@@ -372,34 +475,33 @@ void do_noise(uint8 pin) { // TODO // variance algorithm from knuth; see wikipedia
// checked against python
- for(int i = 0; i<64; i++) {
+ for(int i = 0; i<100; i++) {
data[i] = analogRead(pin);
delta = data[i] - mean;
mean = mean + delta/(i+1);
M2 = M2 + delta*(data[i] - mean);
}
- Serial2.print("pin: "); Serial2.print(pin,DEC);
- Serial2.print("\tn: "); Serial2.print(64,DEC);
- Serial2.print("\tmean: "); Serial2.print(mean);
- Serial2.print("\tvar: "); Serial2.println(M2/63.0);
//sqrt is broken?
- //stddev = M2/(63.0);
- //stddev = sqrt(stddev);
+ //stddev = sqrt(variance);
+ Serial2.print("header: D"); Serial2.print(pin,DEC);
+ Serial2.print("\tn: "); Serial2.print(100,DEC);
+ Serial2.print("\tmean: "); Serial2.print(mean);
+ Serial2.print("\tvar: "); Serial2.println(M2/99.0);
pinMode(pin, OUTPUT);
}
void do_everything(void) { // TODO
+ // TODO
// print to usart
// print to usb
// toggle gpios
// enable pwm
- do_noise(15);
Serial2.println("(unimplemented)");
}
void do_fast_gpio(void) {
- // pin 4 is on port B and is pin 5 on the uC
+ // header D4 is on port B and is pin 5 on the uC
gpio_write_bit(GPIOB_BASE, 5, 1); gpio_write_bit(GPIOB_BASE, 5, 0);
gpio_write_bit(GPIOB_BASE, 5, 1); gpio_write_bit(GPIOB_BASE, 5, 0);
gpio_write_bit(GPIOB_BASE, 5, 1); gpio_write_bit(GPIOB_BASE, 5, 0);
@@ -413,9 +515,6 @@ void do_fast_gpio(void) { gpio_write_bit(GPIOB_BASE, 5, 1); gpio_write_bit(GPIOB_BASE, 5, 0);
gpio_write_bit(GPIOB_BASE, 5, 1); gpio_write_bit(GPIOB_BASE, 5, 0);
gpio_write_bit(GPIOB_BASE, 5, 1); gpio_write_bit(GPIOB_BASE, 5, 0);
-
- // this way incurs an extra function call
- //digitalWrite(4, 1); digitalWrite(4, 0);
}
int main(void) {
|