- const static uint8_t lookup[] = {
- 0x01, 0x03, 0x02, 0x06, 0x04, 0x0c, 0x08, 0x18,
- 0x10, 0x30, 0x20, 0x60, 0x40, 0xc0, 0x80, 0x81
- };
- uint8_t wind;
- uint8_t i = 0;
-
- wind = call Vane.get();
- for (i = 0; i < sizeof(lookup); i++) {
- if (lookup[i] == wind) {
- compass[i]++;
- return;
- }
+ post startRead();
+ }
+
+ event void Vane.readDone(error_t error, uint16_t value)
+ {
+ if (error == SUCCESS) {
+ /* Convert the adc value (0...4095) to a compass heading
+ * (0...COMPASS_COUNT - 1).
+ */
+ value = (value + ADC_OFFSET) / ADC_PER_HEADING;
+ while (value >= COMPASS_COUNT)
+ value -= COMPASS_COUNT;
+ compass[value]++;