Project

General

Profile

Revision 1461

Added by Brad Neuman over 14 years ago

updated all the library code to have sensible _init behavior.
Almost all of the library components have a global variable which gets set after init and the functions inside will fail with an error code if init has not been called. Also, the init functions themselves check this variable and will bail out without doing any damage if that init has already been called

View differences:

test_rangefinder.c
30 30
    int i;  // index
31 31
    int sensor[5] = {IR4, IR3, IR2, IR1, IR5};
32 32
    int color[5] = {RED, ORANGE, YELLOW, GREEN, BLUE};
33
    int ret;
33 34

  
34 35
    // flash orbs BLUE 3 times
35 36
    for (i = 0; i < 3; i++) {
......
44 45
	orb2_set_color(color[i]);
45 46

  
46 47
	// wait for sensor interaction
47
	while (range_read_distance(sensor[i]) == -1)
48
	while ((ret = range_read_distance(sensor[i])) == -1) {
48 49
	    // stay RED until IR4 sees something
49 50
	    orb1_set_color(RED);
51
	    if(ret == -3) { //library not init'd 
52
	      while(1) {
53
		orb2_set_color(GREEN);
54
		orb1_set_color(RED);
55
		delay_ms(250);
56
		orb1_set_color(GREEN);
57
		orb2_set_color(RED);
58
		delay_ms(250);
59
	      }
60
	    }
61
	}
50 62

  
51 63
	orb1_set_color(GREEN);
52 64
	delay_ms(TEST_TIME);

Also available in: Unified diff