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