Project

General

Profile

Revision 413

Added by Chris Mar about 16 years ago

tested/fixed new BOM code. bom_refresh() did not use the lookup table before calling analog_get8(). but now it works. run main in template directory to see new BOM buffer compared to old get_max_bom() values.

View differences:

branches/analog/trunk/code/projects/template/main.c
2 2

  
3 3
int main(void) {
4 4
	unsigned int count = 0;
5
	int count2 = 0;
6
	dragonfly_init(ALL_ON);
5
	int maxbom = -1;
6
    dragonfly_init(ALL_ON);
7 7
	range_init();
8 8
	//analog_stop_loop();
9
	usb_puts("starting");
9
	usb_puts("starting\n\r");
10 10
	while (1) {
11
		if (count == 50000) {
12
			for(int i=2; i<7; i++) {
13
				usb_puti( linearize_distance(analog8(i)) );
14
				usb_puts("  ");
15
			}
16
			usb_puts("\n\r");
17
			count = 0;
18
		}
19
		/*
20
		if (count2 == 5000) {
21
			usb_puts("Loop stopped\n\r");
22
			analog_stop_loop();
23
		}
24
		
25
		if (count2 == 10000) {
26
			usb_puts("Loop started\n\r");
27
			analog_start_loop();
28
			count2 = 0;
29
		}*/
30
		
31
		
32
		count++;
33
		//count2++;
11
        //bom_leds_on(BOM_ALL);
12
        bom_refresh(BOM_ALL);
13
        usb_puts("refreshed\n\r");
14
        maxbom = bom_get_max();
15
        usb_puts("maxbom: ");
16
        usb_puti(maxbom);
17
        usb_puts("\n\n\r");
18
        delay_ms(100);
34 19
	}
35 20
	
36 21
	return 0;
branches/analog/trunk/code/projects/template/Makefile
14 14
# USE_WIRELESS = 1
15 15

  
16 16
# com1 = serial port. Use lpt1 to connect to parallel port.
17
AVRDUDE_PORT = com8
17
AVRDUDE_PORT = com4
18 18
#
19 19
#
20 20
###################################
branches/analog/trunk/code/projects/libdragonfly/bom.c
38 38
#include "dio.h"
39 39
#include "analog.h"
40 40

  
41
//TODO: DELETE THIS
42
void printi(int i)
43
{
44
    char c3 = (i % 10) + '0';
45
    i /= 10;
46
    char c2 = (i % 10) + '0';
47
    i /= 10;
48
    char c1 = (i % 10) + '0';
49
    if (c1 == '0')
50
    {
51
        c1 = ' ';
52
        if (c2 == '0')
53
            c2 = ' ';
54
    }
55
    usb_putc(c1);
56
    usb_putc(c2);
57
    usb_putc(c3);
58
}
59

  
41 60
//constants
42 61
static const char lookup[16] = {7,6,5,0xe,1,4,3,2,0xf,0,0xd,8,0xc,0xb,9,0xa};
43 62

  
......
118 137
        break;
119 138
    case RBOM:
120 139
        break;
121
    default:
140
    //default:
122 141
    }
123 142
}
124 143

  
......
140 159
    
141 160
    for(i = 0; i < NUM_BOM_LEDS; i++) {
142 161
        if(bit_field & 0x1) {
143
            bom_select(i);
162
            bom_select(lookup[i]);
144 163
            bom_val[i] = analog_get8(MONKI);
145 164
        }
146
        bit_field = bitfield >> 1;
165
        bit_field = bit_field >> 1;
147 166
    }
148 167
    
149 168
    analog_start_loop();
......
171 190
int bom_get_max(void) {
172 191
    int i, lowest_val, lowest_i;
173 192
    
174
    lowest_val = bom_val[0];
175
    lowest_i = 0;
176
    for(i = 1; i < NUM_BOM_LEDS; i++) {
177
        if(bom_val[i] < lowest) {
193
    lowest_val = 255;
194
    for(i = 0; i < NUM_BOM_LEDS; i++) {
195
        printi(bom_val[i]);
196
        usb_puts(" ");
197
        if(bom_val[i] < lowest_val) {
178 198
            lowest_val = bom_val[i];
179 199
            lowest_i = i;
180 200
        }
181
    }
201
    }
202
    usb_puts("<<< BOM_GET_MAX\n\r");
182 203
    
183 204
    if(lowest_val < BOM_VALUE_THRESHOLD)
184 205
        return lowest_i;
......
206 227
    case RBOM:
207 228
        //add rbom code here
208 229
        break;
230
    }
209 231
}
210 232

  
211 233
/**
......
228 250
    case RBOM:
229 251
        //add rbom code here
230 252
        break;
253
    }
231 254
}
232 255

  
233 256

  
......
278 301
        output_low(MONK0);
279 302

  
280 303
      a = analog_get8(MONKI);
304
      printi(a);
305
      usb_puts(" ");
281 306
              
282 307
      if (a < h)
283 308
      {
......
286 311
      }
287 312

  
288 313
    }
289
	
314
	usb_puts("\n\r");
290 315
	//Restart loop now that we are done using analog8
291 316
	analog_start_loop();
292 317

  

Also available in: Unified diff