Update copyright stuff, fix conky.conf weirdness.
[monky] / src / nvidia.c
1 /* Conky, a system monitor, based on torsmo
2  *
3  * Any original torsmo code is licensed under the BSD license
4  *
5  * All code written since the fork of torsmo is licensed under the GPL
6  *
7  * Please see COPYING for details
8  *
9  * Copyright (c) 2008 Markus Meissner
10  * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
11  *      (see AUTHORS)
12  * All rights reserved.
13  *
14  * This program is free software: you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation, either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  * You should have received a copy of the GNU General Public License
24  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
25  *
26  */
27
28 #include "nvidia.h"
29
30 const int nvidia_query_to_attr[] = {NV_CTRL_GPU_CORE_TEMPERATURE,
31                                     NV_CTRL_GPU_CORE_THRESHOLD,
32                                     NV_CTRL_AMBIENT_TEMPERATURE,
33                                     NV_CTRL_GPU_CURRENT_CLOCK_FREQS,
34                                     NV_CTRL_GPU_CURRENT_CLOCK_FREQS,
35                                     NV_CTRL_IMAGE_SETTINGS};
36
37 int get_nvidia_value(QUERY_ID qid, Display *dpy){
38         int tmp;
39         if(!XNVCTRLQueryAttribute(dpy, 0, 0, nvidia_query_to_attr[qid], &tmp)){
40                 return -1;
41         }
42         /* FIXME: when are the low 2 bytes of NV_GPU_FREQ needed? */
43         if (qid == NV_GPU_FREQ)
44                 return tmp >> 16;
45         if (qid == NV_MEM_FREQ)
46                 return tmp & 0xFFFF;
47         return tmp;
48 }
49
50 int set_nvidia_type(struct nvidia_s *nvidia, const char *arg)
51 {
52         if (!arg || !arg[0] || !arg[1])
53                 return 1;
54
55         nvidia->print_as_float = 0;
56         switch(arg[0]) {
57                 case 't':                              // temp or threshold
58                         nvidia->print_as_float = 1;
59                         if (arg[1] == 'e')
60                                 nvidia->type = NV_TEMP;
61                         else if (arg[1] == 'h')
62                                 nvidia->type = NV_TEMP_THRESHOLD;
63                         else
64                                 return 1;
65                         break;
66                 case 'a':                              // ambient temp
67                         nvidia->print_as_float = 1;
68                         nvidia->type = NV_TEMP_AMBIENT;
69                         break;
70                 case 'g':                              // gpufreq
71                         nvidia->type = NV_GPU_FREQ;
72                         break;
73                 case 'm':                              // memfreq
74                         nvidia->type = NV_MEM_FREQ;
75                         break;
76                 case 'i':                              // imagequality
77                         nvidia->type = NV_IMAGE_QUALITY;
78                         break;
79                 default:
80                         return 1;
81         }
82         return 0;
83 }