diff options
author | Michael J. Chudobiak <mjc@avtechpulse.com> | 2012-08-30 11:38:48 -0400 |
---|---|---|
committer | Michael J. Chudobiak <mjc@avtechpulse.com> | 2012-08-30 11:38:48 -0400 |
commit | d6c71646ddc4a34293bb5cadde78a30806d8eace (patch) | |
tree | 11ab0d737aca55ccf3e96df40cd8624f75c85dfd | |
parent | 996f3d52275475f2478f377f12f0ef7571ecc795 (diff) |
first attempt at lcd menus
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | device-functions.c | 1 | ||||
-rw-r--r-- | dummy_functions.c | 8 | ||||
-rw-r--r-- | dummy_functions.h | 5 | ||||
-rw-r--r-- | error_utils.c | 1 | ||||
-rw-r--r-- | globals.c | 14 | ||||
-rw-r--r-- | globals.h | 15 | ||||
-rw-r--r-- | lcd.h | 7 | ||||
-rw-r--r-- | monitor.c | 1 | ||||
-rw-r--r-- | parser.c | 2 | ||||
-rw-r--r-- | parser.h | 3 | ||||
-rw-r--r-- | string_utils.c | 138 | ||||
-rw-r--r-- | string_utils.h | 2 |
13 files changed, 172 insertions, 26 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ee6e81..e4656a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,7 @@ add_executable(instr-daemon instr-daemon.c nicutils.c bus.c monitor.c + menus.c dummy_functions.c ) add_executable(instr-client instr-client.c) diff --git a/device-functions.c b/device-functions.c index a7d2adc..41c62a5 100644 --- a/device-functions.c +++ b/device-functions.c @@ -7,6 +7,7 @@ #include "bus.h" #include "lcd.h" #include "flash.h" +#include "menus.h" #include <math.h> #include <glib.h> diff --git a/dummy_functions.c b/dummy_functions.c index 3cb6039..4760c0a 100644 --- a/dummy_functions.c +++ b/dummy_functions.c @@ -1,13 +1,6 @@ #include "dummy_functions.h" #include "globals.h" -void Menu_Refresh() {} -void Menu_Update_Display() {} -int Menu_Clear_Buttons(void) -{ - return 0; -} - int IO_Setup_RS232() { return 0; @@ -40,4 +33,5 @@ void GPIB_clear_events () {} void GPIB_change_address(int new_address) {} void Main_update_shift_registers() { } +void Main_return_to_local() {} diff --git a/dummy_functions.h b/dummy_functions.h index a7dd896..38e5542 100644 --- a/dummy_functions.h +++ b/dummy_functions.h @@ -3,10 +3,6 @@ #include "globals.h" -void Menu_Refresh(); -void Menu_Update_Display(); -int Menu_Clear_Buttons(void); - int IO_Setup_RS232(); void GPIB_Set_Command_Error(); @@ -24,6 +20,7 @@ void GPIB_clear_events (); void GPIB_change_address(int new_address); void Main_update_shift_registers(); +void Main_return_to_local(); #endif diff --git a/error_utils.c b/error_utils.c index 4481205..fa676c9 100644 --- a/error_utils.c +++ b/error_utils.c @@ -19,6 +19,7 @@ END DESCRIPTION **********************************************************/ #include "dummy_functions.h" #include "lcd.h" #include "error_utils.h" +#include "menus.h" /*** EndHeader */ @@ -1,5 +1,6 @@ #include "globals.h" #include <time.h> +#include <sys/time.h> GlobalStruct globals = { @@ -19,3 +20,16 @@ long sec_timer (void) { return (long)time(NULL); } + + +unsigned long long ms_timer (void) +{ + struct timeval tv; + gettimeofday(&tv, NULL); + + unsigned long long millisecondsSinceEpoch = + (unsigned long long)(tv.tv_sec) * 1000 + + (unsigned long long)(tv.tv_usec) / 1000; + + return millisecondsSinceEpoch; +} @@ -92,6 +92,15 @@ #define NO 0 +#define LOCS_ctrl 0 +#define LWLS_ctrl 1 +#define REMS_ctrl 2 +#define RWLS_ctrl 3 +#define RS232_ctrl 4 +#define TELNET_ctrl 5 +#define WEB_ctrl 6 // FIXME + + #define max_commands_in_input 12 #define max_output_length 512 #define max_channels 2 @@ -209,6 +218,10 @@ #define max_v_dymanic_range 1e6 +/* general formatting */ +#define remote_digits_after_decimal 4 /* how many digits are returned after decimal by query commands */ + + // self-cal configs #define NOT_ENABLE_COUNT 0x01 #define ENABLE_COUNT 0x00 @@ -272,6 +285,7 @@ long sec_timer (void); +unsigned long long ms_timer (void); typedef struct { int PRIMARY_ADDRESS; /* GPIB chip's GPIB primary address */ @@ -807,6 +821,7 @@ typedef struct { FlagStruct DefaultFlags; TimeStruct Timers; MenuStatusStruct MenuStatus; + int control_mode; // FIXME and all instances of control_mode } GlobalStruct; @@ -4,6 +4,13 @@ #define LCD_cols 40 #define LCD_rows 4 /* 4x40 LCD */ +#define LCD_chars_total 160 + +/* LCD menu hardware definitions - FIXME */ + +#define LCD_col_width 13 /* characters per LCD column */ +#define LCD_max_entries_per_page 12 /* how many items fit on one LCD screen at a time */ +#define LCD_max_entries 24 /* upper limit for menu arrays */ void LCD_display_extended_message(char *response, gboolean show_change_message, gboolean is_error_screen); void LCD_clear(); @@ -5,6 +5,7 @@ #include "monitor.h" #include "error_utils.h" #include "dummy_functions.h" +#include "menus.h" #include <glib.h> #include <math.h> @@ -17,6 +17,8 @@ END DESCRIPTION **********************************************************/ #include "dummy_functions.h" #include "i2c.h" #include "lcd.h" +#include "menus.h" + #include <glib/gprintf.h> //STATICS @@ -20,9 +20,6 @@ #define query_simple 4 #define query_param 6 -/* general formatting */ -#define remote_digits_after_decimal 4 /* how many digits are returned after decimal by query commands */ - #define NORMAL_ZERO 0 #define ALLOW_NEG_ZERO 1 diff --git a/string_utils.c b/string_utils.c index db077a7..95c643e 100644 --- a/string_utils.c +++ b/string_utils.c @@ -1,14 +1,3 @@ -/* START LIBRARY DESCRIPTION ********************************************* -FLOAT.LIB - Copyright (c) 2006, Avtech Electrosystems Ltd. - -DESCRIPTION: - Functions that deal with strings and floating point numbers. - -SUPPORT LIB'S: -END DESCRIPTION **********************************************************/ - - #include <string.h> #include <ctype.h> #include <math.h> @@ -16,6 +5,9 @@ END DESCRIPTION **********************************************************/ #include "globals.h" #include "string_utils.h" +#include "lcd.h" // FIXME + + void Float_To_Text(int decimal_digits,float number_in, gchar ** text_out) { g_assert (*text_out == NULL); @@ -33,7 +25,6 @@ void Float_To_Text(int decimal_digits,float number_in, gchar ** text_out) } -/*----------------------------------------------------------------------------------------------------------*/ gboolean String_is_it_numeric(char *parameter) { @@ -46,3 +37,126 @@ gboolean String_is_it_numeric(char *parameter) g_regex_unref (numeric_regex); return match; } + + +void String_Parameter_To_Text(float Float_To_Convert,int Int_To_Convert, int significant_digits, + char *start_string,char *units,char *LCD_string,int show_plus_sign) +{ + // FIXME - crappy string func + char out_val[LCD_col_width+1]; + char floating_val[32]; + char String_of_spaces[LCD_col_width+1]; + char unit_mult[10]; /* units multiplier, eg. M, k, u */ + + int i; /* just a counter */ + int shift_decimal_by; /* if the exponent isn't a multiple of 3, the decimal point will be moved */ + int decimal_location; /* where the decimal is in the number string */ + int chars_processed; /* how many characters are in the parsed number string so far */ + + int exponent_val; /* the exponent, in integer form */ + + /* Copy the floating point value to a string. Do not multiply to accomodate units; the roundoff */ + /* is annoying. (e.g. 1.000 -> 0.999) */ + /* Move the decimal with string manipulations instead. */ + + strcpy(LCD_string,start_string); + + /* if significant_digits is zero, used the supplied integer rather than the floating number */ + + if (!significant_digits) { + sprintf(out_val, "%d", (int) Float_To_Convert); + strcat(LCD_string,out_val); + } else { + Float_To_Text(remote_digits_after_decimal,Float_To_Convert,floating_val); + + /* -- COPY FIRST ONE OR TWO CHARACTERS -- */ + if (floating_val[0]=='-') { /* if it's negative ... */ + decimal_location=2; /* decimal at position two (e.g.: -2.23e-9) */ + chars_processed=2; /* two characters so far (e.g.: -2) */ + out_val[0]='-'; /* copy minus sign */ + out_val[1]=floating_val[1]; /* copy first digit */ + } else if (show_plus_sign==YES) { /* if it's positive and plus sign required ... */ + decimal_location=1; /* decimal at position one (e.g.: 2.23e-9) */ + chars_processed=2; /* two characters so far (e.g.: +2) */ + out_val[0]='+'; /* add plus sign */ + out_val[1]=floating_val[0]; /* copy first digit */ + } else { /* if it's positive and plus sign not required ... */ + decimal_location=1; /* decimal at position one (e.g.: 2.23e-9) */ + chars_processed=1; /* one character so far (e.g.: 2) */ + out_val[0]=floating_val[0]; /* copy first digit */ + } + + /* -- FIND EXPONENT -- */ + /* find how much the decimal has to be moved, by examining the exponent in the string and */ + /* modding it by 3 */ + exponent_val = atoi(floating_val+strlen(floating_val)-3); /* read the last three characters */ + /* e.g. +09, or -07 */ + + shift_decimal_by=(300+exponent_val) % 3; /* added 300 to keep everything positive */ + + /* -- PICK UNITS -- */ + if (exponent_val<12 && exponent_val>=9) { + strcpy(unit_mult,"G"); + } else if (exponent_val<9 && exponent_val>=6) { + strcpy(unit_mult,"M"); + } else if (exponent_val<6 && exponent_val>=3) { + strcpy(unit_mult,"k"); + } else if (exponent_val<3 && exponent_val>=0) { + strcpy(unit_mult,""); + } else if (exponent_val<0 && exponent_val>=-3) { + strcpy(unit_mult,"m"); + } else if (exponent_val<-3 && exponent_val>=-6) { + strcpy(unit_mult,"u"); + } else if (exponent_val<-6 && exponent_val>=-9) { + strcpy(unit_mult,"n"); + } else if (exponent_val<-9 && exponent_val>=-12) { + strcpy(unit_mult,"p"); + } + + if (exponent_val<-12) { + strcpy(unit_mult,""); /* if parameter=0, don't use silly units */ + } + + /* -- MOVE DIGITS AROUND DECIMAL POINT -- */ + + /* move the digits that will come before the decimal */ + for (i=decimal_location; i<decimal_location+shift_decimal_by; ++i) { + out_val[chars_processed]=floating_val[1+i]; + ++chars_processed; + } + + /* put in the new decimal point */ + out_val[chars_processed]='.'; + ++chars_processed; + + /* copy the rest of the digits */ + for (i=shift_decimal_by+1+decimal_location; i<significant_digits+3; ++i) { + out_val[chars_processed]=floating_val[i]; + ++chars_processed; + /* leave space for minus sign, decimal point, and extra digit on the end too */ + } + + /* -- TERMINATE STRING -- */ + if ((show_plus_sign==YES) || (floating_val[0]=='-')) { + out_val[significant_digits+3]=0; + } else { + out_val[significant_digits+2]=0; + } + + + /* -- FINISH UP -- */ + + strcat(LCD_string,out_val); + LCD_string[strlen(LCD_string)-1]=0; /* remove extra digit */ + + /* -- CHECK FOR TERMINATING DECIMAL POINT -- */ + if (LCD_string[strlen(LCD_string)-1]=='.') { + LCD_string[strlen(LCD_string)-1]=0; + } + + strcat(LCD_string,unit_mult); + } + + strcat(LCD_string,units); +} + diff --git a/string_utils.h b/string_utils.h index c090000..5d1c013 100644 --- a/string_utils.h +++ b/string_utils.h @@ -5,5 +5,7 @@ void Float_To_Text(int decimal_digits,float number_in, gchar** text_out); gboolean String_is_it_numeric(char *parameter); +void String_Parameter_To_Text(float Float_To_Convert,int Int_To_Convert, int significant_digits, + char *start_string,char *units,char *LCD_string,int show_plus_sign); #endif |