Revision 1366
Changed all tests and main.c to copies of those in trunk/code/projects/test
branches/library_refactor/projects/test/testeeprom.c | ||
---|---|---|
1 |
/** @file testeeprom.c |
|
2 |
* @brief tests the eeprom code |
|
3 |
* |
|
4 |
* stores and retrives a value, then sets it back to what it was |
|
5 |
*/ |
|
6 |
#include <dragonfly_lib.h> |
|
7 |
#include "eeprom.h" |
|
8 |
|
|
9 |
#define ADDR 0 |
|
10 |
|
|
11 |
int testeeprom(void) { |
|
12 |
unsigned char data, data2; |
|
13 |
int ret; |
|
14 |
int worked=1; |
|
15 |
|
|
16 |
dragonfly_init(ALL_ON); |
|
17 |
|
|
18 |
/* read whats there */ |
|
19 |
ret = eeprom_get_byte(ADDR, &data); |
|
20 |
|
|
21 |
if(ret) { |
|
22 |
usb_puts("Error reading intial value! return code: "); |
|
23 |
usb_puti(ret); |
|
24 |
usb_puts(" data: "); |
|
25 |
usb_puti(data); |
|
26 |
usb_puts("\r\n"); |
|
27 |
worked=0; |
|
28 |
} |
|
29 |
else { |
|
30 |
usb_puts("data was: "); |
|
31 |
usb_puti(data); |
|
32 |
usb_puts("\r\n"); |
|
33 |
} |
|
34 |
|
|
35 |
/* write something new */ |
|
36 |
|
|
37 |
ret = eeprom_put_byte(ADDR, 123); |
|
38 |
if(ret) { |
|
39 |
usb_puts("Error writing data! return code: "); |
|
40 |
usb_puti(ret); |
|
41 |
usb_puts("\r\n"); |
|
42 |
worked=0; |
|
43 |
} |
|
44 |
else { |
|
45 |
usb_puts("wrote 123\r\n"); |
|
46 |
} |
|
47 |
|
|
48 |
|
|
49 |
/* check if tis really there */ |
|
50 |
|
|
51 |
ret = eeprom_get_byte(ADDR, &data2); |
|
52 |
|
|
53 |
if(ret) { |
|
54 |
usb_puts("Error reading second value! return code: "); |
|
55 |
usb_puti(ret); |
|
56 |
usb_puts(" data: "); |
|
57 |
usb_puti(data2); |
|
58 |
usb_puts("\r\n"); |
|
59 |
worked=0; |
|
60 |
} |
|
61 |
else { |
|
62 |
if(data2==123) { |
|
63 |
usb_puts("data write and re-read worked!\r\n"); |
|
64 |
} |
|
65 |
else { |
|
66 |
usb_puts("data re-read returned 0 but data was "); |
|
67 |
usb_puti(data2); |
|
68 |
usb_puts("\r\n"); |
|
69 |
worked=0; |
|
70 |
} |
|
71 |
} |
|
72 |
|
|
73 |
|
|
74 |
/* restore old value */ |
|
75 |
|
|
76 |
ret = eeprom_put_byte(ADDR, 123); |
|
77 |
if(ret) { |
|
78 |
usb_puts("Error writing data the second time! return code: "); |
|
79 |
usb_puti(ret); |
|
80 |
usb_puts("\r\n"); |
|
81 |
worked=0; |
|
82 |
} |
|
83 |
else { |
|
84 |
usb_puts("re-wrote original data: "); |
|
85 |
usb_puti(data); |
|
86 |
usb_puts("\r\n"); |
|
87 |
} |
|
88 |
|
|
89 |
return worked; |
|
90 |
} |
branches/library_refactor/projects/test/testtokenring.c | ||
---|---|---|
1 |
#include <dragonfly_lib.h> |
|
2 |
#include <wireless.h> |
|
3 |
#include <wl_token_ring.h> |
|
4 |
|
|
5 |
|
|
6 |
/** |
|
7 |
* Tests the token ring and BOM |
|
8 |
* - prints table of bom values for every robot in token ring |
|
9 |
* - takes several seconds to initialize token ring |
|
10 |
*/ |
|
11 |
|
|
12 |
#define MAX_ROBOTS 16 |
|
13 |
|
|
14 |
// set a list of integers to 0 |
|
15 |
void clearRobots(int* list) { |
|
16 |
for(int i=0;i<MAX_ROBOTS;i++) |
|
17 |
list[i] = 0; |
|
18 |
} |
|
19 |
|
|
20 |
int testtokenring(void) { |
|
21 |
// initialize everything |
|
22 |
dragonfly_init(ALL_ON); |
|
23 |
usb_init(); |
|
24 |
usb_puts("usb turned on\r\n"); |
|
25 |
wl_init(); |
|
26 |
usb_puts("wireless turned on\r\n"); |
|
27 |
wl_token_ring_register(); |
|
28 |
wl_token_ring_join(); // join token ring |
|
29 |
usb_puts("token ring joined\r\n"); |
|
30 |
int* robotList = (int*)malloc(sizeof(int)*MAX_ROBOTS); |
|
31 |
int numRobots = 0; |
|
32 |
delay_ms(1000); |
|
33 |
|
|
34 |
// start testing wireless/token ring/BOM |
|
35 |
int i=0; |
|
36 |
while(1) { |
|
37 |
wl_do(); |
|
38 |
// only print table every 200 loops |
|
39 |
if (i%200==0) { |
|
40 |
// get token ring size values |
|
41 |
usb_puts("\r\nnumber of robots in token ring:"); |
|
42 |
usb_puti(wl_token_get_robots_in_ring()); |
|
43 |
usb_puts("\r\nnumber of robots in matrix:"); |
|
44 |
usb_puti(wl_token_get_num_robots()); |
|
45 |
|
|
46 |
// get list of robots |
|
47 |
numRobots = 0; |
|
48 |
clearRobots(robotList); |
|
49 |
wl_token_iterator_begin(); |
|
50 |
while(wl_token_iterator_has_next()) { |
|
51 |
int tmp = wl_token_iterator_next(); |
|
52 |
if (tmp < 0) |
|
53 |
break; |
|
54 |
robotList[tmp] = 1; |
|
55 |
numRobots++; |
|
56 |
} |
|
57 |
if (numRobots < 1) { |
|
58 |
usb_puts("\r\nNo BOM table available."); |
|
59 |
continue; // skip table printing |
|
60 |
} else { |
|
61 |
usb_puts("\r\nBOM table: (* indicates this robot)"); |
|
62 |
} |
|
63 |
|
|
64 |
// print table of bom readings between robots |
|
65 |
usb_puts("\r\ns \\ d"); |
|
66 |
// print header |
|
67 |
for(int j=0;j<MAX_ROBOTS;j++) |
|
68 |
if (robotList[j]) { |
|
69 |
usb_puts("\t|"); |
|
70 |
if (j == wl_get_xbee_id()) |
|
71 |
usb_puts("*"); // indicate that this is the current bot |
|
72 |
usb_puti(j); |
|
73 |
} |
|
74 |
usb_puts("\r\n"); |
|
75 |
// print body |
|
76 |
for(int l=0;l<MAX_ROBOTS;l++) |
|
77 |
if (robotList[l]) { |
|
78 |
if (l == wl_get_xbee_id()) |
|
79 |
usb_puts("*"); // indicate that this is the current bot |
|
80 |
usb_puti(l); // print label col |
|
81 |
for(int k=0;k<MAX_ROBOTS;k++) |
|
82 |
if (robotList[k]) { |
|
83 |
usb_puts("\t|"); |
|
84 |
if (k != l) { |
|
85 |
int bom = wl_token_get_sensor_reading(l,k); |
|
86 |
if (bom >= 0 && bom <= 15) |
|
87 |
usb_puti(bom); // print bom value |
|
88 |
} |
|
89 |
} |
|
90 |
usb_puts("\r\n"); |
|
91 |
} |
|
92 |
usb_puts("\r\n"); |
|
93 |
} |
|
94 |
} |
|
95 |
|
|
96 |
// end testing token ring and bom |
|
97 |
return 0; |
|
98 |
} |
|
99 |
|
|
100 |
|
branches/library_refactor/projects/test/testencoders.c | ||
---|---|---|
1 |
#include <dragonfly_lib.h> |
|
2 |
#include "spi.h" |
|
3 |
#include "encoders.h" |
|
4 |
|
|
5 |
#define MODE 0 |
|
6 |
#define TEST 0 |
|
7 |
|
|
8 |
extern char spi_status; |
|
9 |
|
|
10 |
int testencoders(void) |
|
11 |
{ |
|
12 |
usb_init(); |
|
13 |
encoders_init(); |
|
14 |
dragonfly_init(ALL_ON); |
|
15 |
int encoder_left,encoder_right; |
|
16 |
while(1){ |
|
17 |
|
|
18 |
encoder_left = encoder_read(LEFT); |
|
19 |
encoder_right = encoder_read(RIGHT); |
|
20 |
usb_puts("Encoder values (left, right): "); |
|
21 |
usb_puti(encoder_left); |
|
22 |
usb_puts(", "); |
|
23 |
usb_puti(encoder_right); |
|
24 |
usb_puts("\n\r"); |
|
25 |
delay_ms(500); |
|
26 |
} |
|
27 |
return 0; |
|
28 |
} |
|
29 |
|
branches/library_refactor/projects/test/eeprom.c | ||
---|---|---|
1 |
#include <avr/io.h> |
|
2 |
#include "eeprom.h" |
|
3 |
|
|
4 |
int eeprom_put_byte(unsigned int uiAddress, unsigned char ucData) { |
|
5 |
/* Wait for completion of previous write */ |
|
6 |
while(EECR & (1<<EEWE)); |
|
7 |
/* Set up address and data registers */ |
|
8 |
EEAR = uiAddress; |
|
9 |
EEDR = ucData; |
|
10 |
/* Write logical one to EEMWE */ |
|
11 |
EECR |= (1<<EEMWE); |
|
12 |
/* Start eeprom write by setting EEWE */ |
|
13 |
EECR |= (1<<EEWE); |
|
14 |
|
|
15 |
return 0; |
|
16 |
} |
|
17 |
|
|
18 |
int eeprom_get_byte(unsigned int uiAddress, unsigned char *byte) { |
|
19 |
/* Wait for completion of previous write */ |
|
20 |
while(EECR & (1<<EEWE)); |
|
21 |
/* Set up address register */ |
|
22 |
EEAR = uiAddress; |
|
23 |
/* Start eeprom read by writing EERE */ |
|
24 |
EECR |= (1<<EERE); |
|
25 |
/* get data from data register */ |
|
26 |
*byte=EEDR; |
|
27 |
|
|
28 |
return 0; |
|
29 |
} |
|
30 |
|
|
31 |
|
|
32 |
unsigned char get_robotid(void) { |
|
33 |
unsigned char ret; |
|
34 |
|
|
35 |
eeprom_get_byte(EEPROM_ROBOT_ID_ADDR, &ret); |
|
36 |
|
|
37 |
return ret; |
|
38 |
} |
branches/library_refactor/projects/test/testanalog.c | ||
---|---|---|
1 |
#include <dragonfly_lib.h> |
|
2 |
|
|
3 |
/* |
|
4 |
* This function outputs to TeraTerm a table which displays the values currently |
|
5 |
* stored in the analog table |
|
6 |
*/ |
|
7 |
|
|
8 |
int testanalog(void) { |
|
9 |
|
|
10 |
dragonfly_init(ANALOG); |
|
11 |
|
|
12 |
usb_init(); |
|
13 |
usb_puts("usb turned on\r\n"); |
|
14 |
|
|
15 |
range_init(); |
|
16 |
usb_puts("rangefinders initialized\r\n"); |
|
17 |
|
|
18 |
usb_puts("\r\n\n"); |
|
19 |
delay_ms(1000); |
|
20 |
|
|
21 |
while (1) { |
|
22 |
|
|
23 |
for (int i = 0; i < 20; i++) { |
|
24 |
|
|
25 |
usb_puts("\r\n"); |
|
26 |
|
|
27 |
} |
|
28 |
|
|
29 |
usb_puts("port# |\tvalue\r\n"); |
|
30 |
|
|
31 |
for (int j = 1; j < 16; j++) { |
|
32 |
|
|
33 |
usb_puti(j); |
|
34 |
usb_puts("\t"); |
|
35 |
usb_puti(analog10(j)); |
|
36 |
usb_puts("\r\n"); |
|
37 |
|
|
38 |
} |
|
39 |
|
|
40 |
delay_ms(575); |
|
41 |
|
|
42 |
} |
|
43 |
|
|
44 |
return 0; |
|
45 |
} |
branches/library_refactor/projects/test/testlights.c | ||
---|---|---|
1 |
#include <dragonfly_lib.h> |
|
2 |
|
|
3 |
int testlights(void) { |
|
4 |
dragonfly_init(ALL_ON); // orbs will work if you only init ORBS |
|
5 |
//usb_init(); |
|
6 |
usb_puts("usb turned on\n"); |
|
7 |
delay_ms(1000); |
|
8 |
|
|
9 |
orb_set_color(RED); |
|
10 |
delay_ms(1000); |
|
11 |
orb_set_color(ORANGE); |
|
12 |
delay_ms(1000); |
|
13 |
orb_set_color(YELLOW); |
|
14 |
delay_ms(1000); |
|
15 |
orb_set_color(GREEN); |
|
16 |
delay_ms(1000); |
|
17 |
orb_set_color(BLUE); |
|
18 |
delay_ms(1000); |
|
19 |
orb_set_color(PURPLE); |
|
20 |
delay_ms(1000); |
|
21 |
|
|
22 |
return 0; |
|
23 |
} |
|
24 |
|
|
25 |
|
branches/library_refactor/projects/test/testmotors.c | ||
---|---|---|
1 |
#include <dragonfly_lib.h> |
|
2 |
|
|
3 |
int testmotors(void) { |
|
4 |
dragonfly_init(ALL_ON); // orbs will work if you only init ORBS |
|
5 |
//usb_init(); |
|
6 |
usb_puts("usb turned on\n"); |
|
7 |
delay_ms(1000); |
|
8 |
|
|
9 |
motor1_set(1, 220); |
|
10 |
motor2_set(1, 220); |
|
11 |
delay_ms(1000); |
|
12 |
|
|
13 |
return 0; |
|
14 |
} |
|
15 |
|
|
16 |
|
branches/library_refactor/projects/test/testrangefinders.c | ||
---|---|---|
1 |
#include <dragonfly_lib.h> |
|
2 |
|
|
3 |
|
|
4 |
/** |
|
5 |
* RangeFinder Rules |
|
6 |
* - analog_init() is needed |
|
7 |
* - value 100 - under 5cm is not detected |
|
8 |
* - value 800 - over ~30cm is not detected |
|
9 |
* - at ~20cm values become increasingly erroneous |
|
10 |
* |
|
11 |
*/ |
|
12 |
|
|
13 |
int to_mm(int rangeFinder) |
|
14 |
{ |
|
15 |
|
|
16 |
if(rangeFinder != -1) |
|
17 |
return (int)(rangeFinder/15.112*10); |
|
18 |
else |
|
19 |
return -1; |
|
20 |
|
|
21 |
} |
|
22 |
|
|
23 |
int testrangefinders(void) { |
|
24 |
dragonfly_init(ANALOG); |
|
25 |
usb_init(); |
|
26 |
usb_puts("usb turned on\r\n"); |
|
27 |
range_init(); |
|
28 |
usb_puts("rangefinders turned on\r\n"); |
|
29 |
int d1,d2,d3,d4,d5; |
|
30 |
delay_ms(1000); |
|
31 |
|
|
32 |
//int sum = 0; |
|
33 |
//int count = 0; |
|
34 |
//int average = 0; |
|
35 |
|
|
36 |
// start testing rangefinders |
|
37 |
while(1) { |
|
38 |
//if(count == 10000) |
|
39 |
//{ |
|
40 |
// average = sum/count; |
|
41 |
// count = 0; |
|
42 |
//} |
|
43 |
|
|
44 |
// get ranges |
|
45 |
//d1 = range_read_distance(IR1); |
|
46 |
d2 = range_read_distance(IR2); |
|
47 |
//d3 = range_read_distance(IR3); |
|
48 |
//d4 = range_read_distance(IR4); |
|
49 |
//d5 = range_read_distance(IR5); |
|
50 |
//usb_puts("d1="); |
|
51 |
//usb_puti(d1); |
|
52 |
|
|
53 |
//sum += d2; |
|
54 |
|
|
55 |
//usb_puts("\taverage of 10000="); |
|
56 |
//usb_puti(d2); |
|
57 |
|
|
58 |
//usb_puts("\td3="); |
|
59 |
//usb_puti(d3); |
|
60 |
//usb_puts("\td4="); |
|
61 |
//usb_puti(d4); |
|
62 |
//usb_puts("\td5="); |
|
63 |
//usb_puti(d5); |
|
64 |
|
|
65 |
usb_puts("\tIn mm="); |
|
66 |
usb_puti(to_mm(d2)); |
|
67 |
usb_puts("\r\n"); |
|
68 |
|
|
69 |
//count++; |
|
70 |
|
|
71 |
delay_ms(100); |
|
72 |
} |
|
73 |
|
|
74 |
// end testing rangefinders |
|
75 |
return 0; |
|
76 |
} |
|
77 |
|
|
78 |
|
branches/library_refactor/projects/test/testlcd.c | ||
---|---|---|
1 |
#include <dragonfly_lib.h> |
|
2 |
|
|
3 |
|
|
4 |
/** |
|
5 |
* LCD Rules |
|
6 |
* - when changing put formats (from string to int or back) |
|
7 |
* the screen will clear and start printing at beginning |
|
8 |
* - when outputting again in same format, an append op is performed |
|
9 |
* - text wraps to next line, and to beginning |
|
10 |
* - when wrapping to beginning, screen is not cleared |
|
11 |
* - puti only does signed ints |
|
12 |
*/ |
|
13 |
|
|
14 |
int testlcd(void) { |
|
15 |
usb_init(); |
|
16 |
usb_puts("usb turned on\n"); |
|
17 |
lcd_init(); |
|
18 |
usb_puts("lcd turned on\n"); |
|
19 |
lcd_clear_screen(); |
|
20 |
usb_puts("lcd screen cleared\n"); |
|
21 |
delay_ms(1000); |
|
22 |
|
|
23 |
// start testing lcd |
|
24 |
lcd_puts("this is a test, a really long test"); |
|
25 |
lcd_puts("this is a test, a really long test. this is a test, a really long test"); |
|
26 |
usb_puts("test writing string to lcd: 'this is a test, a really long test'\n"); |
|
27 |
delay_ms(10000); |
|
28 |
|
|
29 |
/*lcd_clear_screen(); |
|
30 |
usb_puts("lcd screen cleared\n"); |
|
31 |
lcd_puti(1000000); |
|
32 |
lcd_puti(100000); |
|
33 |
lcd_puti(10000); |
|
34 |
lcd_puti(1000); |
|
35 |
lcd_puti(100); |
|
36 |
lcd_puti(10); |
|
37 |
lcd_puti(1); |
|
38 |
usb_puts("test writing int to lcd: 1000000,100000, 10000, 1000, 100, 10, 1\n"); |
|
39 |
delay_ms(10000); |
|
40 |
*/ |
|
41 |
// end testing lcd |
|
42 |
return 0; |
|
43 |
} |
|
44 |
|
|
45 |
|
branches/library_refactor/projects/test/test_tokenring.c | ||
---|---|---|
1 |
#include <dragonfly_lib.h> |
|
2 |
#include <wireless.h> |
|
3 |
#include <wl_token_ring.h> |
|
4 |
|
|
5 |
|
|
6 |
/** |
|
7 |
* Tests the token ring and BOM |
|
8 |
* - prints table of bom values for every robot in token ring |
|
9 |
* - takes several seconds to initialize token ring |
|
10 |
*/ |
|
11 |
|
|
12 |
#define MAX_ROBOTS 16 |
|
13 |
|
|
14 |
// set a list of integers to 0 |
|
15 |
void clearRobots(int* list) { |
|
16 |
for(int i=0;i<MAX_ROBOTS;i++) |
|
17 |
list[i] = 0; |
|
18 |
} |
|
19 |
|
|
20 |
int testtokenring(void) { |
|
21 |
usb_init(); |
|
22 |
usb_puts("usb turned on\r\n"); |
|
23 |
wl_init(); |
|
24 |
usb_puts("wireless turned on\r\n"); |
|
25 |
wl_token_ring_register(); |
|
26 |
wl_token_ring_join(); // join token ring |
|
27 |
usb_puts("token ring joined\r\n"); |
|
28 |
int* robotList = (int*)malloc(sizeof(int)*MAX_ROBOTS); |
|
29 |
int numRobots = 0; |
|
30 |
delay_ms(1000); |
|
31 |
|
|
32 |
// start testing wireless/token ring/BOM |
|
33 |
int i=0; |
|
34 |
while(1) { |
|
35 |
wl_do(); |
|
36 |
// only print table every 200 loops |
|
37 |
if (i%200==0) { |
|
38 |
// get token ring size values |
|
39 |
usb_puts("\r\nnumber of robots in token ring:"); |
|
40 |
usb_puti(wl_token_get_robots_in_ring()); |
|
41 |
usb_puts("\r\nnumber of robots in matrix:"); |
|
42 |
usb_puti(wl_token_get_num_robots()); |
|
43 |
|
|
44 |
// get list of robots |
|
45 |
numRobots = 0; |
|
46 |
clearRobots(robotList); |
|
47 |
wl_token_iterator_begin(); |
|
48 |
while(wl_token_iterator_has_next()) { |
|
49 |
int tmp = wl_token_iterator_next(); |
|
50 |
if (tmp < 0) |
|
51 |
break; |
|
52 |
robotList[tmp] = 1; |
|
53 |
numRobots++; |
|
54 |
} |
|
55 |
if (numRobots < 1) { |
|
56 |
usb_puts("\r\nNo BOM table available."); |
|
57 |
continue; // skip table printing |
|
58 |
} else { |
|
59 |
usb_puts("\r\nBOM table: (* indicates this robot)"); |
|
60 |
} |
|
61 |
|
|
62 |
// print table of bom readings between robots |
|
63 |
usb_puts("\r\ns \\ d"); |
|
64 |
// print header |
|
65 |
for(int j=0;j<MAX_ROBOTS;j++) |
|
66 |
if (robotList[j]) { |
|
67 |
usb_puts("\t|"); |
|
68 |
if (j == wl_get_xbee_id()) |
|
69 |
usb_puts("*"); // indicate that this is the current bot |
|
70 |
usb_puti(j); |
|
71 |
} |
|
72 |
usb_puts("\r\n"); |
|
73 |
// print body |
|
74 |
for(int l=0;l<MAX_ROBOTS;l++) |
|
75 |
if (robotList[l]) { |
|
76 |
if (l == wl_get_xbee_id()) |
|
77 |
usb_puts("*"); // indicate that this is the current bot |
|
78 |
usb_puti(l); // print label col |
|
79 |
for(int k=0;k<MAX_ROBOTS;k++) |
|
80 |
if (robotList[k]) { |
|
81 |
usb_puts("\t|"); |
|
82 |
if (k != l) { |
|
83 |
int bom = wl_token_get_sensor_reading(l,k); |
|
84 |
if (bom >= 0 && bom <= 15) |
|
85 |
usb_puti(bom); // print bom value |
|
86 |
} |
|
87 |
} |
|
88 |
usb_puts("\r\n"); |
|
89 |
} |
|
90 |
usb_puts("\r\n"); |
|
91 |
} |
|
92 |
} |
|
93 |
|
|
94 |
// end testing token ring and bom |
|
95 |
return 0; |
|
96 |
} |
|
97 |
|
|
98 |
|
branches/library_refactor/projects/test/test_analog.c | ||
---|---|---|
1 |
#include <dragonfly_lib.h> |
|
2 |
|
|
3 |
/* |
|
4 |
* This function outputs to TeraTerm a table which displays the values currently |
|
5 |
* stored in the analog table |
|
6 |
*/ |
|
7 |
|
|
8 |
int testanalog(void) { |
|
9 |
|
|
10 |
|
|
11 |
usb_init(); |
|
12 |
usb_puts("usb turned on\r\n"); |
|
13 |
|
|
14 |
range_init(); |
|
15 |
usb_puts("rangefinders initialized\r\n"); |
|
16 |
|
|
17 |
usb_puts("\r\n\n"); |
|
18 |
delay_ms(1000); |
|
19 |
|
|
20 |
while (1) { |
|
21 |
|
|
22 |
for (int i = 0; i < 20; i++) { |
|
23 |
|
|
24 |
usb_puts("\r\n"); |
|
25 |
|
|
26 |
} |
|
27 |
|
|
28 |
usb_puts("port# |\tvalue\r\n"); |
|
29 |
|
|
30 |
for (int j = 1; j < 16; j++) { |
|
31 |
|
|
32 |
usb_puti(j); |
|
33 |
usb_puts("\t"); |
|
34 |
usb_puti(analog10(j)); |
|
35 |
usb_puts("\r\n"); |
|
36 |
|
|
37 |
} |
|
38 |
|
|
39 |
delay_ms(575); |
|
40 |
|
|
41 |
} |
|
42 |
|
|
43 |
return 0; |
|
44 |
} |
branches/library_refactor/projects/test/test_lcd.c | ||
---|---|---|
1 |
#include <dragonfly_lib.h> |
|
2 |
|
|
3 |
|
|
4 |
/** |
|
5 |
* LCD Rules |
|
6 |
* - when changing put formats (from string to int or back) |
|
7 |
* the screen will clear and start printing at beginning |
|
8 |
* - when outputting again in same format, an append op is performed |
|
9 |
* - text wraps to next line, and to beginning |
|
10 |
* - when wrapping to beginning, screen is not cleared |
|
11 |
* - puti only does signed ints |
|
12 |
*/ |
|
13 |
|
|
14 |
int testlcd(void) { |
|
15 |
usb_init(); |
|
16 |
usb_puts("usb turned on\n"); |
|
17 |
lcd_init(); |
|
18 |
usb_puts("lcd turned on\n"); |
|
19 |
lcd_clear_screen(); |
|
20 |
usb_puts("lcd screen cleared\n"); |
|
21 |
delay_ms(1000); |
|
22 |
|
|
23 |
// start testing lcd |
|
24 |
lcd_puts("this is a test, a really long test"); |
|
25 |
lcd_puts("this is a test, a really long test. this is a test, a really long test"); |
|
26 |
usb_puts("test writing string to lcd: 'this is a test, a really long test'\n"); |
|
27 |
delay_ms(10000); |
|
28 |
|
|
29 |
/*lcd_clear_screen(); |
|
30 |
usb_puts("lcd screen cleared\n"); |
|
31 |
lcd_puti(1000000); |
|
32 |
lcd_puti(100000); |
|
33 |
lcd_puti(10000); |
|
34 |
lcd_puti(1000); |
|
35 |
lcd_puti(100); |
|
36 |
lcd_puti(10); |
|
37 |
lcd_puti(1); |
|
38 |
usb_puts("test writing int to lcd: 1000000,100000, 10000, 1000, 100, 10, 1\n"); |
|
39 |
delay_ms(10000); |
|
40 |
*/ |
|
41 |
// end testing lcd |
|
42 |
return 0; |
|
43 |
} |
|
44 |
|
|
45 |
|
branches/library_refactor/projects/test/test_encoders.c | ||
---|---|---|
1 |
#include <dragonfly_lib.h> |
|
2 |
#include "spi.h" |
|
3 |
#include "encoders.h" |
|
4 |
|
|
5 |
#define MODE 0 |
|
6 |
#define TEST 0 |
|
7 |
|
|
8 |
extern char spi_status; |
|
9 |
|
|
10 |
int testencoders(void) |
|
11 |
{ |
|
12 |
usb_init(); |
|
13 |
encoders_init(); |
|
14 |
int encoder_left,encoder_right; |
|
15 |
while(1){ |
|
16 |
|
|
17 |
encoder_left = encoder_read(LEFT); |
|
18 |
encoder_right = encoder_read(RIGHT); |
|
19 |
usb_puts("Encoder values (left, right): "); |
|
20 |
usb_puti(encoder_left); |
|
21 |
usb_puts(", "); |
|
22 |
usb_puti(encoder_right); |
|
23 |
usb_puts("\n\r"); |
|
24 |
delay_ms(500); |
|
25 |
} |
|
26 |
return 0; |
|
27 |
} |
|
28 |
|
branches/library_refactor/projects/test/test_motors.c | ||
---|---|---|
1 |
#include <dragonfly_lib.h> |
|
2 |
|
|
3 |
int testmotors(void) { |
|
4 |
//usb_init(); |
|
5 |
usb_puts("usb turned on\n"); |
|
6 |
delay_ms(1000); |
|
7 |
|
|
8 |
motor1_set(1, 220); |
|
9 |
motor2_set(1, 220); |
|
10 |
delay_ms(1000); |
|
11 |
|
|
12 |
return 0; |
|
13 |
} |
|
14 |
|
|
15 |
|
branches/library_refactor/projects/test/main.c | ||
---|---|---|
6 | 6 |
|
7 | 7 |
int main(void) { |
8 | 8 |
//testlcd(); |
9 |
//testrangefinders();
|
|
9 |
testrangefinders(); |
|
10 | 10 |
//testanalog(); |
11 | 11 |
//testtokenring(); |
12 |
<<<<<<< .mine |
|
12 | 13 |
//testencoders(); |
14 |
======= |
|
15 |
//testencoders(); |
|
13 | 16 |
//testlights(); |
14 | 17 |
testmotors(); |
18 |
>>>>>>> .r995 |
|
15 | 19 |
|
16 | 20 |
return 0; |
17 | 21 |
} |
branches/library_refactor/projects/test/test_rangefinders.c | ||
---|---|---|
1 |
#include <dragonfly_lib.h> |
|
2 |
|
|
3 |
|
|
4 |
/** |
|
5 |
* RangeFinder Rules |
|
6 |
* - analog_init() is needed |
|
7 |
* - value 100 - under 5cm is not detected |
|
8 |
* - value 800 - over ~30cm is not detected |
|
9 |
* - at ~20cm values become increasingly erroneous |
|
10 |
* |
|
11 |
*/ |
|
12 |
|
|
13 |
int to_mm(int rangeFinder) |
|
14 |
{ |
|
15 |
|
|
16 |
if(rangeFinder != -1) |
|
17 |
return (int)(rangeFinder/15.112*10); |
|
18 |
else |
|
19 |
return -1; |
|
20 |
|
|
21 |
} |
|
22 |
|
|
23 |
int testrangefinders(void) { |
|
24 |
usb_init(); |
|
25 |
usb_puts("usb turned on\r\n"); |
|
26 |
range_init(); |
|
27 |
usb_puts("rangefinders turned on\r\n"); |
|
28 |
int d1,d2,d3,d4,d5; |
|
29 |
delay_ms(1000); |
|
30 |
|
|
31 |
//int sum = 0; |
|
32 |
//int count = 0; |
|
33 |
//int average = 0; |
|
34 |
|
|
35 |
// start testing rangefinders |
|
36 |
while(1) { |
|
37 |
//if(count == 10000) |
|
38 |
//{ |
|
39 |
// average = sum/count; |
|
40 |
// count = 0; |
|
41 |
//} |
|
42 |
|
|
43 |
// get ranges |
|
44 |
//d1 = range_read_distance(IR1); |
|
45 |
d2 = range_read_distance(IR2); |
|
46 |
//d3 = range_read_distance(IR3); |
|
47 |
//d4 = range_read_distance(IR4); |
|
48 |
//d5 = range_read_distance(IR5); |
|
49 |
//usb_puts("d1="); |
|
50 |
//usb_puti(d1); |
|
51 |
|
|
52 |
//sum += d2; |
|
53 |
|
|
54 |
//usb_puts("\taverage of 10000="); |
|
55 |
//usb_puti(d2); |
|
56 |
|
|
57 |
//usb_puts("\td3="); |
|
58 |
//usb_puti(d3); |
|
59 |
//usb_puts("\td4="); |
|
60 |
//usb_puti(d4); |
|
61 |
//usb_puts("\td5="); |
|
62 |
//usb_puti(d5); |
|
63 |
|
|
64 |
usb_puts("\tIn mm="); |
|
65 |
usb_puti(to_mm(d2)); |
|
66 |
usb_puts("\r\n"); |
|
67 |
|
|
68 |
//count++; |
|
69 |
|
|
70 |
delay_ms(100); |
|
71 |
} |
|
72 |
|
|
73 |
// end testing rangefinders |
|
74 |
return 0; |
|
75 |
} |
|
76 |
|
|
77 |
|
branches/library_refactor/projects/test/test_eeprom.c | ||
---|---|---|
1 |
/** @file testeeprom.c |
|
2 |
* @brief tests the eeprom code |
|
3 |
* |
|
4 |
* stores and retrives a value, then sets it back to what it was |
|
5 |
*/ |
|
6 |
#include <dragonfly_lib.h> |
|
7 |
#include "eeprom.h" |
|
8 |
|
|
9 |
#define ADDR 0 |
|
10 |
|
|
11 |
int testeeprom(void) { |
|
12 |
unsigned char data, data2; |
|
13 |
int ret; |
|
14 |
int worked=1; |
|
15 |
|
|
16 |
|
|
17 |
/* read whats there */ |
|
18 |
ret = eeprom_get_byte(ADDR, &data); |
|
19 |
|
|
20 |
if(ret) { |
|
21 |
usb_puts("Error reading intial value! return code: "); |
|
22 |
usb_puti(ret); |
|
23 |
usb_puts(" data: "); |
|
24 |
usb_puti(data); |
|
25 |
usb_puts("\r\n"); |
|
26 |
worked=0; |
|
27 |
} |
|
28 |
else { |
|
29 |
usb_puts("data was: "); |
|
30 |
usb_puti(data); |
|
31 |
usb_puts("\r\n"); |
|
32 |
} |
|
33 |
|
|
34 |
/* write something new */ |
|
35 |
|
|
36 |
ret = eeprom_put_byte(ADDR, 123); |
|
37 |
if(ret) { |
|
38 |
usb_puts("Error writing data! return code: "); |
|
39 |
usb_puti(ret); |
|
40 |
usb_puts("\r\n"); |
|
41 |
worked=0; |
|
42 |
} |
|
43 |
else { |
|
44 |
usb_puts("wrote 123\r\n"); |
|
45 |
} |
|
46 |
|
|
47 |
|
|
48 |
/* check if tis really there */ |
|
49 |
|
|
50 |
ret = eeprom_get_byte(ADDR, &data2); |
|
51 |
|
|
52 |
if(ret) { |
|
53 |
usb_puts("Error reading second value! return code: "); |
|
54 |
usb_puti(ret); |
|
55 |
usb_puts(" data: "); |
|
56 |
usb_puti(data2); |
|
57 |
usb_puts("\r\n"); |
|
58 |
worked=0; |
|
59 |
} |
|
60 |
else { |
|
61 |
if(data2==123) { |
|
62 |
usb_puts("data write and re-read worked!\r\n"); |
|
63 |
} |
|
64 |
else { |
|
65 |
usb_puts("data re-read returned 0 but data was "); |
|
66 |
usb_puti(data2); |
|
67 |
usb_puts("\r\n"); |
|
68 |
worked=0; |
|
69 |
} |
|
70 |
} |
|
71 |
|
|
72 |
|
|
73 |
/* restore old value */ |
|
74 |
|
|
75 |
ret = eeprom_put_byte(ADDR, 123); |
|
76 |
if(ret) { |
|
77 |
usb_puts("Error writing data the second time! return code: "); |
|
78 |
usb_puti(ret); |
|
79 |
usb_puts("\r\n"); |
|
80 |
worked=0; |
|
81 |
} |
|
82 |
else { |
|
83 |
usb_puts("re-wrote original data: "); |
|
84 |
usb_puti(data); |
|
85 |
usb_puts("\r\n"); |
|
86 |
} |
|
87 |
|
|
88 |
return worked; |
|
89 |
} |
branches/library_refactor/projects/test/test_usb.c | ||
---|---|---|
1 |
#include <dragonfly_lib.h> |
|
2 |
|
|
3 |
/* |
|
4 |
* This function outputs to TeraTerm the following: |
|
5 |
* |
|
6 |
* Testing... |
|
7 |
* 1, 2, 3 |
|
8 |
* 2A, F4, C8E1 |
|
9 |
* done. |
|
10 |
* |
|
11 |
*/ |
|
12 |
|
|
13 |
int testusb(void) { |
|
14 |
|
|
15 |
usb_init(); |
|
16 |
usb_puts("usb turned on, test starting:\r\n"); |
|
17 |
|
|
18 |
usb_puts("\r\n\n"); |
|
19 |
delay_ms(1000); |
|
20 |
|
|
21 |
// print some values to usb |
|
22 |
usb_puts("Testing...\n"); |
|
23 |
usb_puti(1); |
|
24 |
usb_putc(','); |
|
25 |
usb_putc(' '); |
|
26 |
usb_puti(2); |
|
27 |
usb_putc(','); |
|
28 |
usb_putc(' '); |
|
29 |
usb_puti(3); |
|
30 |
usb_putc('\n'); |
|
31 |
usb_puth8(0x2A); |
|
32 |
usb_putc(','); |
|
33 |
usb_putc(' '); |
|
34 |
usb_puth16(0xF4); |
|
35 |
usb_putc(','); |
|
36 |
usb_putc(' '); |
|
37 |
usb_puth(0xC8E1); |
|
38 |
usb_putc('\n'); |
|
39 |
usb_puts("done.\n"); |
|
40 |
|
|
41 |
|
|
42 |
/* TODO: add test for getting values from usb */ |
|
43 |
|
|
44 |
|
|
45 |
return 0; |
|
46 |
} |
branches/library_refactor/projects/test/test_lights.c | ||
---|---|---|
1 |
#include <dragonfly_lib.h> |
|
2 |
|
|
3 |
int testlights(void) { |
|
4 |
//usb_init(); |
|
5 |
usb_puts("usb turned on\n"); |
|
6 |
delay_ms(1000); |
|
7 |
|
|
8 |
orb_set_color(RED); |
|
9 |
delay_ms(1000); |
|
10 |
orb_set_color(ORANGE); |
|
11 |
delay_ms(1000); |
|
12 |
orb_set_color(YELLOW); |
|
13 |
delay_ms(1000); |
|
14 |
orb_set_color(GREEN); |
|
15 |
delay_ms(1000); |
|
16 |
orb_set_color(BLUE); |
|
17 |
delay_ms(1000); |
|
18 |
orb_set_color(PURPLE); |
|
19 |
delay_ms(1000); |
|
20 |
|
|
21 |
return 0; |
|
22 |
} |
|
23 |
|
|
24 |
|
Also available in: Unified diff