"Fossies" - the Fresh Open Source Software Archive 
Member "xosview-1.23/bsd/sensor.cc" (11 Jul 2020, 2958 Bytes) of package /linux/misc/xosview-1.23.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "sensor.cc" see the
Fossies "Dox" file reference documentation.
1 //
2 // Copyright (c) 2012 by Tomi Tapper <tomi.o.tapper@jyu.fi>
3 //
4 // File based on linux/lmstemp.* by
5 // Copyright (c) 2000, 2006 by Leopold Toetsch <lt@toetsch.at>
6 //
7 // This file may be distributed under terms of the GPL
8 //
9 //
10 //
11
12 #include "sensor.h"
13 #include "kernel.h"
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <string.h>
17 #include <math.h>
18 #include <string>
19
20
21 BSDSensor::BSDSensor( XOSView *parent, const char *name, const char *high,
22 const char *low, const char *label, const char *caption, int nbr )
23 : SensorFieldMeter( parent, label, caption, 1, 1, 0 ) {
24 nbr_ = nbr;
25 highname_[0] = highval_[0] = '\0';
26 lowname_[0] = lowval_[0] = '\0';
27 std::string n(name), tmp;
28 tmp = n.substr( 0, n.find_first_of('.') );
29 strncpy(name_, tmp.c_str(), NAMESIZE);
30 tmp = n.substr( n.find_first_of('.') + 1 );
31 strncpy(val_, tmp.c_str(), NAMESIZE);
32 if (high) {
33 has_high_ = true;
34 if ( sscanf(high, "%lf", &high_) == 0 ) { // high given as number?
35 n = high;
36 tmp = n.substr( 0, n.find_first_of('.') );
37 strncpy(highname_, tmp.c_str(), NAMESIZE);
38 tmp = n.substr( n.find_first_of('.') + 1 );
39 strncpy(highval_, tmp.c_str(), NAMESIZE);
40 }
41 }
42 if (low) {
43 has_low_ = true;
44 if ( sscanf(low, "%lf", &low_) == 0 ) { // low given as number?
45 n = low;
46 tmp = n.substr( 0, n.find_first_of('.') );
47 strncpy(lowname_, tmp.c_str(), NAMESIZE);
48 tmp = n.substr( n.find_first_of('.') + 1 );
49 strncpy(lowval_, tmp.c_str(), NAMESIZE);
50 }
51 }
52 }
53
54 BSDSensor::~BSDSensor( void ) {
55 }
56
57 void BSDSensor::checkResources( void ) {
58 SensorFieldMeter::checkResources();
59
60 actcolor_ = parent_->allocColor( parent_->getResource( "bsdsensorActColor" ) );
61 highcolor_ = parent_->allocColor( parent_->getResource( "bsdsensorHighColor" ) );
62 lowcolor_ = parent_->allocColor( parent_->getResource( "bsdsensorLowColor" ) );
63 setfieldcolor( 0, actcolor_ );
64 setfieldcolor( 1, parent_->getResource( "bsdsensorIdleColor" ) );
65 setfieldcolor( 2, highcolor_ );
66 priority_ = atoi( parent_->getResource( "bsdsensorPriority" ) );
67
68 char s[32];
69 const char *tmp = parent_->getResourceOrUseDefault( "bsdsensorHighest", "0" );
70 snprintf(s, 32, "bsdsensorHighest%d", nbr_);
71 total_ = fabs( atof( parent_->getResourceOrUseDefault(s, tmp) ) );
72 snprintf(s, 32, "bsdsensorUsedFormat%d", nbr_);
73 const char *f = parent_->getResourceOrUseDefault(s, NULL);
74 SetUsedFormat( f ? f : parent_->getResource( "bsdsensorUsedFormat" ) );
75
76 if (!has_high_)
77 high_ = total_;
78 if (!has_low_)
79 low_ = 0;
80
81 // Get the unit.
82 float dummy;
83 BSDGetSensor(name_, val_, &dummy, unit_);
84 updateLegend();
85 }
86
87 void BSDSensor::checkevent( void ) {
88 getsensor();
89 drawfields();
90 }
91
92 void BSDSensor::getsensor( void ) {
93 float value, high = high_, low = low_;
94 BSDGetSensor(name_, val_, &value);
95 if ( strlen(highname_) )
96 BSDGetSensor(highname_, highval_, &high);
97 if ( strlen(lowname_) )
98 BSDGetSensor(lowname_, lowval_, &low);
99
100 fields_[0] = value;
101 checkFields(low, high);
102 }