Caddy
A 2005 Roborodentia entry with vision and path planning capability
 All Data Structures Files Functions Variables Typedefs Macros Pages
utility.c
1 /*
2  * This file is part of Caddy.
3  *
4  * Caddy is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * Caddy is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Caddy. If not, see <http://www.gnu.org/licenses/>.
16  */
17 #include "utility.h"
18 #include "motor_control.h"
19 #include "lcd_16x2.h"
20 
21 // AVRLIB
22 #include "timer.h"
23 
24 void myDelay(uint16_t outerDelay)
25 {
26  uint16_t i, j;
27  for (i = 0; i < outerDelay; i++)
28  for (j = 0; j < UINT16_MAX; j++) ;
29 }
30 
31 void msDelay(uint16_t ms)
32 {
33  uint16_t i;
34  for (i = 0; i < ms; i++)
35  {
36  delay(1000); // 1000 microseconds
37  }
38 }
39 
40 int8_t findValue(const uint8_t *array, const uint8_t arraySize, uint8_t value)
41 {
42  uint8_t i = 0;
43  while (i < arraySize)
44  {
45  if (array[i] == value)
46  return i;
47  i++;
48  }
49  return -1;
50 }
51 
52 void fatalError(const char *errorStr1, const char *errorStr2)
53 {
54 #if DEBUGGING
55  lcdWriteStr(errorStr1, 0, 0);
56  lcdWriteStr(errorStr2, 1, 0);
57 #endif
58  brake(BOTH_MOTORS);
59  while (1) ;
60 }