Project

General

Profile

Revision 336

Updated wireless to use a circular buffer instead of a queue using malloc. Tested on both the computer and robots with a token ring, and was successful.

View differences:

battery.c
1 1
/**
2 2
 * Copyright (c) 2007 Colony Project
3
 *
3
 * 
4 4
 * Permission is hereby granted, free of charge, to any person
5 5
 * obtaining a copy of this software and associated documentation
6 6
 * files (the "Software"), to deal in the Software without
......
9 9
 * copies of the Software, and to permit persons to whom the
10 10
 * Software is furnished to do so, subject to the following
11 11
 * conditions:
12
 *
12
 * 
13 13
 * The above copyright notice and this permission notice shall be
14 14
 * included in all copies or substantial portions of the Software.
15
 *
15
 * 
16 16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 17
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 18
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
......
48 48
/**
49 49
 * @defgroup battery Battery
50 50
 * @brief Functions for reading battery voltage.
51
 *
51
 * 
52 52
 * Contains functions for checking the current
53 53
 * voltage of the battery. Include battery.h to
54 54
 * access these functions.
......
82 82
int battery(void)
83 83
{
84 84
  /* 5 volts is the max, 255 is the max 8bit number , *2 for the divider */
85
  return analog8(BATT_PORT) * 500 >>7;
85
        return analog8(BATT_PORT) * 500 >>7;
86 86
}
87 87

  
88 88

  
......
99 99
{
100 100
  static char next_read = 0;
101 101
  static char ret = 0;
102

  
102
  
103 103
  int batt_reading = battery8();
104 104

  
105 105
  if(next_read == 0) {
106
    if(batt_reading > BATTERY_LOWV) {
107
      ret = 0;
108
      battery_low_count = 0;
109
    } else {
110
      battery_low_count++;
111
      if( battery_low_count >= MAX_LOW_COUNT) {
112
        ret = 1;
106
    if(batt_reading > BATTERY_LOWV)
107
    {
108
        ret = 0;
113 109
        battery_low_count = 0;
114
      }
115 110
    }
116

  
111
    else
112
    {
113
        battery_low_count++;
114
        if( battery_low_count >= MAX_LOW_COUNT )
115
        {
116
            ret = 1;
117
            battery_low_count = 0;
118
        }
119
    }
120
    
117 121
    next_read = BATTERY_NEXT_READ_PRESCALAR;
118
  } else {
119
    next_read--;
120 122
  }
121

  
123
  else next_read--;
124
  
122 125
  return ret;
123 126
}
124 127

  
......
139 142
{
140 143
  int i;
141 144
  long int sum = 0;
142

  
145
  
143 146
  for(i = 0; i < n_samples; i++) {
144 147
    sum += battery8();
145 148
  }
146

  
149
  
147 150
  return (int)(sum / n_samples);
148 151
}
149 152

  
150 153
/** @} **/ //end defgroup
154

  

Also available in: Unified diff