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