little simplification and improvement of $nvidia
authorPhil <n0-1@users.sourceforge.net>
Sun, 3 Aug 2008 13:27:00 +0000 (13:27 +0000)
committerPhil <n0-1@users.sourceforge.net>
Sun, 3 Aug 2008 13:27:00 +0000 (13:27 +0000)
* check only the unique part of the argument
* print temperatures like all others (%.1f)
* do argument parsing in nvidia.c (so all specific stuff is at one place)
* little header cleanup

git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@1231 7f574dfc-610e-0410-a909-a81674777703

doc/variables.xml
src/conky.c
src/conky.h
src/nvidia.c
src/nvidia.h

index 5e50414..54cf910 100644 (file)
                </term>
                <listitem>
                        Nvidia graficcard support for the XNVCtrl library.
-                       Each option gives back one integer value:
-                       (threshold): the thresholdtemperature at which the gpu slows down
-                       (temp): gives the gpu current temperature
-                       (gpufreq): gives the current gpu frequency
-                       (memfreq): gives the current mem frequency
-                       (imagequality): which imagequality should be choosen by OpenGL applications
+                       Each option can be shortened to the least significant part.
+                       Temperatures are printed as float, all other values as integer.
+                       <simplelist>
+                               <member><command>threshold</command>:
+                                       the thresholdtemperature at which the gpu slows down
+                               </member>
+                               <member><command>temp</command>:
+                                       gives the gpu current temperature
+                               </member>
+                               <member><command>gpufreq</command>:
+                                       gives the current gpu frequency
+                               </member>
+                               <member><command>memfreq</command>:
+                                       gives the current mem frequency
+                               </member>
+                               <member><command>imagequality</command>:
+                                       which imagequality should be choosen by OpenGL applications
+                               </member>
+                       </simplelist>
                        <para></para>
                </listitem>
        </varlistentry>
index c53063f..e432aef 100644 (file)
@@ -4022,24 +4022,11 @@ static struct text_object *construct_text_object(const char *s,
                        }
 #ifdef NVIDIA
                END OBJ(nvidia, 0)
-                       if (!arg){
-                               CRIT_ERR("nvidia needs one argument "
-                                               "[temp,threshold,gpufreq,memfreq,imagequality]");
-                       } else {
-                               if (strcmp(arg, "temp") == 0)
-                                       obj->data.nvidia.type = NV_TEMP;
-                               else if (strcmp(arg, "threshold") == 0)
-                                       obj->data.nvidia.type = NV_TEMP_THRESHOLD;
-                               else if (strcmp(arg, "gpufreq") == 0)
-                                       obj->data.nvidia.type = NV_GPU_FREQ;
-                               else if (strcmp(arg, "memfreq") == 0)
-                                       obj->data.nvidia.type = NV_MEM_FREQ;
-                               else if (strcmp(arg, "imagequality") == 0)
-                                       obj->data.nvidia.type = NV_IMAGE_QUALITY;
-                               else
-                                       CRIT_ERR("you have to give one of these arguments "
-                                                       "[temp,threshold,gpufreq,memfreq,imagequality");
-                               strncpy((char*)&obj->data.nvidia.arg, arg, 20);
+                       if (!arg) {
+                               CRIT_ERR("nvidia needs an argument\n");
+                       } else if (set_nvidia_type(&obj->data.nvidia, arg)) {
+                               CRIT_ERR("nvidia: invalid argument"
+                                        " specified: '%s'\n", arg);
                        }
 #endif /* NVIDIA */
                END {
@@ -6321,13 +6308,14 @@ head:
                        }
 #ifdef NVIDIA
                        OBJ(nvidia) {
-                               int hol = (strcmp((char*)&obj->data.nvidia.arg, "gpufreq")) ? 1 : 0;
-                               if(!(obj->data.nvidia.value = get_nvidia_value(obj->data.nvidia.type, display, hol)))
-                                       snprintf(p, p_max_size, "value unavailible");
+                               int value = get_nvidia_value(obj->data.nvidia.type, display);
+                               if(value == -1)
+                                       snprintf(p, p_max_size, "N/A");
+                               else if (obj->data.nvidia.print_as_float &&
+                                               value > 0 && value < 100)
+                                       snprintf(p, p_max_size, "%.1f", (float)value);
                                else
-                                       spaced_print(p, p_max_size, "%*d", 4, "nvidia",
-                                                            4, obj->data.nvidia.value);
-
+                                       snprintf(p, p_max_size, "%d", value);
                        }
 #endif /* NVIDIA */
 
index 2172877..ba429f3 100644 (file)
@@ -449,11 +449,4 @@ char *get_apm_battery_time(void);
 #include "hddtemp.h"
 #endif /* HDDTEMP */
 
-/* in nvidia.c */
-#ifdef NVIDIA
-
-int get_nvidia_value(QUERY_ID qid, Display *dpy, int highorlow);
-
-#endif /* NVIDIA */
-
 #endif
index 432ce3e..59659a5 100644 (file)
 
 #include "nvidia.h"
 
-int get_nvidia_value(QUERY_ID qid, Display *dpy, int highorlow){
+int get_nvidia_value(QUERY_ID qid, Display *dpy){
        int tmp;
        if(!XNVCTRLQueryAttribute(dpy, 0, 0, qid, &tmp)){
-               return 0;
-       } else if (qid == NV_GPU_FREQ){
-               if (highorlow == 1)
-                       return tmp >> 16;
-               else
-                       return tmp & 0x0000FFFF;
-       } else
-               return tmp;
+               return -1;
+       }
+       /* FIXME: when are the low 2 bytes of NV_GPU_FREQ needed? */
+       if (qid == NV_GPU_FREQ)
+               return tmp >> 16;
+       return tmp;
 }
 
+int set_nvidia_type(struct nvidia_s *nvidia, const char *arg)
+{
+       if (!arg || !arg[0] || !arg[1])
+               return 1;
+
+       nvidia->print_as_float = 0;
+       switch(arg[0]) {
+               case 't':                              // temp or threshold
+                       nvidia->print_as_float = 1;
+                       if (arg[1] == 'e')
+                               nvidia->type = NV_TEMP;
+                       else if (arg[1] == 'h')
+                               nvidia->type = NV_TEMP_THRESHOLD;
+                       else
+                               return 1;
+                       break;
+               case 'g':                              // gpufreq
+                       nvidia->type = NV_GPU_FREQ;
+                       break;
+               case 'm':                              // memfreq
+                       nvidia->type = NV_MEM_FREQ;
+                       break;
+               case 'i':                              // imagequality
+                       nvidia->type = NV_IMAGE_QUALITY;
+                       break;
+               default:
+                       return 1;
+       }
+       return 0;
+}
index 9dfffe9..9b2fe2a 100644 (file)
  */
 
 
-#include <X11/Xlib.h>
-#include <NVCtrl/NVCtrlLib.h>
-
 #ifndef NVIDIA_CONKY_H
 #define NVIDIA_CONKY_H
 
+#include <X11/Xlib.h>
+#include <NVCtrl/NVCtrlLib.h>
+
 typedef enum _QUERY_ID {
        NV_TEMP = NV_CTRL_GPU_CORE_TEMPERATURE,
        NV_TEMP_THRESHOLD = NV_CTRL_GPU_CORE_THRESHOLD,
@@ -43,9 +43,11 @@ typedef enum _QUERY_ID {
 
 struct nvidia_s {
        int interval;
-       int value;
-       char arg[20];
+       int print_as_float;
        QUERY_ID type;
 };
 
+int get_nvidia_value(QUERY_ID qid, Display *dpy);
+int set_nvidia_type(struct nvidia_s *, const char *);
+
 #endif