Carmel (MAXREFDES18#) Code Documentation  V01.00
High Accuracy Analog Current/Voltage Output
 All Files Functions Variables Macros Pages
menu.c
Go to the documentation of this file.
1 
29 /*
30  * Copyright (C) 2012 Maxim Integrated Products, Inc., All Rights Reserved.
31  *
32  * Permission is hereby granted, free of charge, to any person obtaining a
33  * copy of this software and associated documentation files (the "Software"),
34  * to deal in the Software without restriction, including without limitation
35  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
36  * and/or sell copies of the Software, and to permit persons to whom the
37  * Software is furnished to do so, subject to the following conditions:
38  *
39  * The above copyright notice and this permission notice shall be included
40  * in all copies or substantial portions of the Software.
41  *
42  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
43  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
45  * IN NO EVENT SHALL MAXIM INTEGRATED PRODUCTS BE LIABLE FOR ANY CLAIM, DAMAGES
46  * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
47  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
48  * OTHER DEALINGS IN THE SOFTWARE.
49  *
50  * Except as contained in this notice, the name of Maxim Integrated Products
51  * shall not be used except as stated in the Maxim Integrated Products
52  * Branding Policy.
53  *
54  * The mere transfer of this software does not imply any licenses
55  * of trade secrets, proprietary technology, copyrights, patents,
56  * trademarks, maskwork rights, or any other form of intellectual
57  * property whatsoever. Maxim Integrated Products retains all ownership rights.
58  *
59  ***************************************************************************/
60 
61 #include <stdio.h>
62 #include "platform.h"
63 #include "xgpio.h"
64 #include "xgpio_l.h"
65 #include "xparameters.h"
66 #include "xuartlite.h"
67 #include "xspi_l.h"
68 #include "xspi.h"
69 #include "xiic_l.h"
70 #include "utilities.h"
71 #include "string.h"
72 #include "MAXREFDES18.h"
73 #include "menu.h"
74 
75 void menu_cls()
83 {
84  // The following code will cause a clear screen event on Hyperterminal and many other terminal emulators
85  printf("\033[2J");
86 }
87 
96 {
97  printf( "\r\n");
98  printf( "///////////////////////////////////////////////////////////////////\r\n");
99  printf( "// _____ _____ //\r\n");
100  printf( "// / __ \\ / __ \\ //\r\n");
101  printf( "// | | \\/ / / | | //\r\n");
102  printf( "// | | / / | | //\r\n");
103  printf( "// | | / \\ | | //\r\n");
104  printf( "// | | / /\\ \\ | | //\r\n");
105  printf( "// |_| /_/ \\_\\ |_| //\r\n");
106  printf( "// //\r\n");
107  printf( "///////////////////////////////////////////////////////////////////\r\n");
108  printf("\r\n");
109 }
110 
111 
120 {
121  printf( "\r\n");
122  printf( "///////////////////////////////////////////////////////////////////\r\n");
123  printf( "// ### ### //\r\n");
124  printf( "// ## ## //\r\n");
125  printf( "// //\r\n");
126  printf( "// ## _____ _____ ## //\r\n");
127  printf( "// / __ \\ / __ \\ //\r\n");
128  printf( "// ## | | \\/ / / | | ## //\r\n");
129  printf( "// | | / / | | //\r\n");
130  printf( "// | | / \\ | | //\r\n");
131  printf( "// ## | | / /\\ \\ | | ## //\r\n");
132  printf( "// |_| /_/ \\_\\ |_| //\r\n");
133  printf( "// ## ## //\r\n");
134  printf( "// //\r\n");
135  printf( "// ## ## //\r\n");
136  printf( "// ### ### //\r\n");
137  printf( "// //\r\n");
138  printf( "// M A X I M I N T E G R A T E D //\r\n");
139  printf( "// //\r\n");
140  printf( "///////////////////////////////////////////////////////////////////\r\n");
141 
142  printf("\r\n\r\n");
143 }
144 
153 {
154  printf("\r\n>> ");
155  fflush(stdout);
156 }
157 
158 
167 {
168  printf("----------------------------------------------------\r\n\r\n");
169 }
170 
171 unsigned int menu_get_direct_entry(u32 nUartAddress, int nNumberBits)
184 {
185  int nTemp;
186  int i;
187  u8 uchInput=0;
188  int nNumberCharactersReceived=0;
189  u8 auchInput[8];
190  unsigned int nReturnVal=0;
191 
192  //menu_cls();
193  nTemp = number_raised_to_power(2,nNumberBits) - 1;
194  printf("Enter a DAC_CODE and then press enter (DAC_CODE = %d..%d)\r\n",0, nTemp);
196  fflush(stdout);
197 
198  while(uchInput!=13)
199  {
200  uchInput = XUartLite_RecvByte(nUartAddress);
201  if(uchInput>=48 && uchInput <=57) // digits 0..9
202  {
203  uchInput -=48; // subtract 48 to get the real number converted from the ASCII digit
204  auchInput[nNumberCharactersReceived] = uchInput;
205  nNumberCharactersReceived++;
206  printf("%d",uchInput);
207  fflush(stdout);
208  }
209  else if(uchInput==13) // carriage return
210  {
211  for(i=0;i<nNumberCharactersReceived;i++)
212  {
213  nReturnVal += auchInput[i] * number_raised_to_power(10,nNumberCharactersReceived-i-1);
214  }
215  if(nReturnVal > nTemp)
216  nReturnVal=nTemp;
217  }
218  }
219  //printf("\r\nValue is %d\r\n",nReturnVal);
220  //delay(ABOUT_ONE_SECOND * 2);
221  printf("\n");
222  return(nReturnVal);
223 }
224 
225 u8 menu_retrieve_keypress(u32 nUartAddress)
238 {
239  u8 uchInput;
240 
241  uchInput = XUartLite_RecvByte(nUartAddress);
242 
243  if(uchInput==27) // Escape sequence (likely an arrow key)
244  {
245  uchInput = XUartLite_RecvByte(nUartAddress);
246  if(uchInput==91) // Left bracket (part #2 of the 3 part escape sequence)
247  {
248  uchInput = XUartLite_RecvByte(nUartAddress);
249  if(uchInput==65)
250  uchInput = KEYPRESS_ARROW_UP-10;
251  if(uchInput==66)
252  uchInput = KEYPRESS_ARROW_DOWN-10;
253  if(uchInput==67)
254  uchInput = KEYPRESS_ARROW_RIGHT-10;
255  if(uchInput==68)
256  uchInput = KEYPRESS_ARROW_LEFT-10;
257  if(uchInput==75)
258  uchInput = KEYPRESS_END - 10;
259  }
260  }
261  else if(uchInput>=48 && uchInput <=57) // digits 0..9
262  uchInput -=48; // subtract 48 to get the real number converted from the ASCII digit
263  else if(uchInput>=97 && uchInput<=122)
264  uchInput -=32; // convert lowercase to uppercase
265 
266  return(uchInput);
267 }
268 
277 {
278  //menu_print_maxim_banner();
279 
280  printf("Press a number to select output mode:\r\n\n");
281 
282  printf("{0} Current Mode \n"\
283  "{1} Voltage Mode\n");
285 }
286 
295 {
296  //menu_print_maxim_banner();
297 
298  printf("Press a number to select current range:\r\n\n");
299 
300  printf("{0} -20mA ~ +20mA \n"\
301  "{1} 0mA ~ +20mA \n"\
302  "{2} 4mA ~ +20mA \n"\
303  "{3} Go To Output Mode Select Menu \n");
305 }
306 
315 {
316  //menu_print_maxim_banner();
317 
318  printf("Press a number to select voltage range:\r\n\n");
319 
320  printf("{0} -10V ~ +10V \n"\
321  "{1} 0V ~ +10V \n"\
322  "{2} 0V ~ +5V \n"\
323  "{3} Go To Output Mode Select Menu \n");
325 }