323e64266b2b687ed69bb6877e29ed377e64e02f
[matches/honours.git] / commands.c
1 #include "commands.h"\r
2 \r
3 /* \r
4  * @file commands.c\r
5  * @author Sam Moore\r
6  * @purpose Implementation of commands for Datalogger\r
7  */\r
8 \r
9 \r
10 \r
11 #include "usart.h"\r
12 #include "dac.h"\r
13 #include "adc.h"\r
14 \r
15 #include "setup.h"\r
16 #include "main.h"\r
17 #include "LCD_functions.h"\r
18 \r
19 #include <string.h>\r
20 #include <stdlib.h>\r
21 \r
22 \r
23 uint8 read_adc(char * arg)\r
24 {\r
25         if (arg[0] == '\0')\r
26         {\r
27                 for (uint8 i=0; i < 8; ++i)\r
28                 {\r
29                         USART_printf("%i ", ADC_read(i));\r
30                 }\r
31         }\r
32         else\r
33         {\r
34                 for (char * a = arg; *a != '\0'; ++a)\r
35                 {\r
36                         //uint8 channel = *a - '0';\r
37                         //if (channel >= 0 && channel <= 7)     \r
38                         USART_printf("%f %f ", ADC_read(*a - '0'), sqrt(setup.adc_variance[(*a - '0')]));\r
39                 }\r
40                 LCD_printf("%i", (uint)(setup.adc_values[(int)(arg[0] - '0')]));\r
41         }\r
42         USART_printf("\r\n");\r
43 \r
44         return 0;\r
45 }\r
46 \r
47 uint8 poll_adc(char * arg)\r
48 {\r
49         uint32 tmr = 0;\r
50         //USART_printf("# poll\r\n");\r
51         LCD_puts("poll");\r
52         //USART_printf("#t      ADC0    ADC1    ADC2    ADC3    ADC4    ADC5    ADC6    ADC7\r\n);      \r
53         do\r
54         {\r
55                 setup.elapsed_time = 0;\r
56                 USART_printf("%l ", tmr);\r
57                 read_adc(arg);\r
58                 if (arg[0] == '\0' || arg[1] == 't')\r
59                 {\r
60                         LCD_Colon(1);\r
61                         LCD_ShowTime(tmr);\r
62                 }\r
63 \r
64                 //if (setup.elapsed_time > setup.poll_delay)\r
65                 //{\r
66                 //      USART_printf("# tmr>delay\r\n");\r
67                 //      return 255;\r
68                 //}\r
69 \r
70                 while (setup.elapsed_time < setup.poll_delay)\r
71                 {\r
72                         if (USART_Poll() != '\0')\r
73                         {\r
74                                 //USART_printf("# STOP %i\r\n", tmr+setup.elapsed_time);\r
75                                 LCD_Colon(0);\r
76                                 return 0;\r
77                         }\r
78                 }\r
79                 tmr += setup.elapsed_time;\r
80         }\r
81         while (tmr < setup.poll_timeout);\r
82         //USART_printf("# done.\r\n");\r
83         LCD_Colon(0);\r
84         return 0;\r
85 }\r
86 \r
87 uint8 set_dac(char * arg)\r
88 {\r
89         if (arg[0] != '\0')\r
90         {\r
91                 setup.dac_value = atoi(arg);\r
92                 DAC_Set(setup.dac_value);\r
93         }\r
94         USART_printf("# DAC %i\r\n", setup.dac_value);\r
95         LCD_printf("D %i", setup.dac_value);\r
96         return 0;\r
97 }\r
98 \r
99 uint8 set_averages(char * arg)\r
100 {\r
101         if (arg[0] != '\0')\r
102         {\r
103                 setup.adc_averages = atoi(arg);\r
104         }\r
105         USART_printf("# Avgs %i\r\n", setup.adc_averages);\r
106         LCD_printf("Avgs %i", setup.adc_averages);\r
107         return 0;\r
108 }\r
109 \r
110 uint8 set_timeout(char * arg)\r
111 {\r
112         if (arg[0] != '\0')\r
113         {\r
114                 setup.poll_timeout = atoi(arg);\r
115         }\r
116         USART_printf("# timeout %i\r\n", setup.poll_timeout);\r
117         LCD_printf("timeout %i", setup.poll_timeout);\r
118         return 0;\r
119 }\r
120 \r
121 uint8 set_delay(char * arg)\r
122 {\r
123         if (arg[0] != '\0')\r
124         {\r
125                 setup.poll_delay = atoi(arg);\r
126         }\r
127         USART_printf("# delay %i\r\n", setup.poll_delay);\r
128         LCD_printf("delay %i", setup.poll_delay);\r
129         return 0;\r
130 }\r
131 \r
132 uint8 reset(char * arg)\r
133 {\r
134         Initialization();\r
135         return 0;\r
136 }\r
137 \r
138 /*\r
139 uint8 config(char * arg)\r
140 {\r
141         if (arg[0] == '\0')\r
142         {\r
143                 return 1;\r
144         }\r
145 \r
146         switch (arg[0])\r
147         {\r
148                 case 'd':\r
149                         setup.poll_delay = (uint)atoi(arg+1);\r
150                         break;\r
151                 case 'a':\r
152                         setup.adc_averages = (uint)atoi(arg+1);\r
153                         break;\r
154                 case 't':\r
155                         setup.poll_timeout = (uint)atoi(arg+1);\r
156                         break;\r
157                 default:\r
158                         return 255;\r
159         }\r
160         return 0;\r
161 }\r
162 */\r

UCC git Repository :: git.ucc.asn.au