diff options
author | info-cppsp <[email protected]> | 2017-11-18 16:19:42 +0100 |
---|---|---|
committer | raveit65 <[email protected]> | 2017-11-26 20:41:43 +0100 |
commit | 93dd9f3d232220ec4a807f122a9fae1e71f06f0f (patch) | |
tree | 8c8ee6b9f4cfb8bcefb2fcffa01a951173a56760 /plugins/i2c-sys/i2c-sys-plugin.c | |
parent | 2921854dcc3148fcf7a28104f3992abf6bc98558 (diff) | |
download | mate-sensors-applet-93dd9f3d232220ec4a807f122a9fae1e71f06f0f.tar.bz2 mate-sensors-applet-93dd9f3d232220ec4a807f122a9fae1e71f06f0f.tar.xz |
Fix indents 02
Diffstat (limited to 'plugins/i2c-sys/i2c-sys-plugin.c')
-rw-r--r-- | plugins/i2c-sys/i2c-sys-plugin.c | 257 |
1 files changed, 130 insertions, 127 deletions
diff --git a/plugins/i2c-sys/i2c-sys-plugin.c b/plugins/i2c-sys/i2c-sys-plugin.c index b1be6b2..3e86fa5 100644 --- a/plugins/i2c-sys/i2c-sys-plugin.c +++ b/plugins/i2c-sys/i2c-sys-plugin.c @@ -33,159 +33,162 @@ const gchar *plugin_name = "i2c-sys"; #define I2C_SYS_BASE_DIR "/sys" enum { - I2C_SYS_DEVICE_FILE_OPEN_ERROR, - I2C_SYS_DEVICE_FILE_READ_ERROR + I2C_SYS_DEVICE_FILE_OPEN_ERROR, + I2C_SYS_DEVICE_FILE_READ_ERROR }; static void i2c_sys_plugin_add_sensor(GList **sensors, const gchar *path) { - gchar *filename; - gchar *id; - gchar *label; - gboolean enable; - guint sensor_type; - IconType icon_type = GENERIC_ICON; - - filename = g_path_get_basename(path); - - /* setup temp2 as CPU sensor and enable it */ - if (g_ascii_strcasecmp(filename, "temp2_input") == 0) { - id = g_strndup(filename, 5); - label = g_strdup(_("CPU")); - sensor_type = TEMP_SENSOR; - enable = TRUE; - icon_type = CPU_ICON; - } else { - switch(filename[0]) { - case 'c': - /* either current or cpu?_vid sensor */ - if (filename[1] == 'u') { /* currents are curr?_input */ - id = g_strndup(filename, 5); - label = g_strndup(filename, 5); - sensor_type = CURRENT_SENSOR; - } - else { /* cpu_vid is cpu?_vid */ - id = g_strdup(filename); - label = g_strdup(filename); - sensor_type = VOLTAGE_SENSOR; - } - break; - case 'f': /* fans are "fan?_input" */ - id = g_strndup(filename, 4); - label = g_strndup(filename, 4); - sensor_type = FAN_SENSOR; - icon_type = FAN_ICON; - break; - case 't': /* temps are "temp?_input" */ - id = g_strndup(filename, 5); - label = g_strndup(filename, 5); - sensor_type = TEMP_SENSOR; - break; - case 'i': /* voltages are "in?_input" */ - id = g_strndup(filename, 3); - label = g_strndup(filename, 3); - sensor_type = VOLTAGE_SENSOR; - break; - default: - /* SHOULDN'T BE ABLE - * TO GET HERE!! */ - g_warning("filename:\"%s\" begins with a charater that is not covered by this switch statement... not adding sensor", filename); - g_free(filename); - g_free(id); - g_free(label); - - return; - - } - /* disable all other sensors */ - enable = FALSE; - } - sensors_applet_plugin_add_sensor(sensors, + gchar *filename; + gchar *id; + gchar *label; + gboolean enable; + guint sensor_type; + IconType icon_type = GENERIC_ICON; + + filename = g_path_get_basename(path); + + /* setup temp2 as CPU sensor and enable it */ + if (g_ascii_strcasecmp(filename, "temp2_input") == 0) { + id = g_strndup(filename, 5); + label = g_strdup(_("CPU")); + sensor_type = TEMP_SENSOR; + enable = TRUE; + icon_type = CPU_ICON; + } else { + switch(filename[0]) { + case 'c': /* either current or cpu?_vid sensor */ + if (filename[1] == 'u') { /* currents are curr?_input */ + id = g_strndup(filename, 5); + label = g_strndup(filename, 5); + sensor_type = CURRENT_SENSOR; + } else { /* cpu_vid is cpu?_vid */ + id = g_strdup(filename); + label = g_strdup(filename); + sensor_type = VOLTAGE_SENSOR; + } + break; + + case 'f': /* fans are "fan?_input" */ + id = g_strndup(filename, 4); + label = g_strndup(filename, 4); + sensor_type = FAN_SENSOR; + icon_type = FAN_ICON; + break; + + case 't': /* temps are "temp?_input" */ + id = g_strndup(filename, 5); + label = g_strndup(filename, 5); + sensor_type = TEMP_SENSOR; + break; + + case 'i': /* voltages are "in?_input" */ + id = g_strndup(filename, 3); + label = g_strndup(filename, 3); + sensor_type = VOLTAGE_SENSOR; + break; + + default: + /* SHOULDN'T BE ABLE * TO GET HERE!! */ + g_warning("filename:\"%s\" begins with a charater that is not covered by this switch statement... not adding sensor", filename); + g_free(filename); + g_free(id); + g_free(label); + + return; + } + + /* disable all other sensors */ + enable = FALSE; + } + + sensors_applet_plugin_add_sensor(sensors, path, id, - label, + label, sensor_type, enable, icon_type, DEFAULT_GRAPH_COLOR); - g_free(filename); - g_free(id); - g_free(label); -} - - -static void i2c_sys_plugin_test_sensor(GList **sensors, - const gchar *path) { - gchar *filename; - - filename = g_path_get_basename(path); - - if ((g_str_has_suffix(filename, "_input") && - (g_str_has_prefix(filename, "temp") || - g_str_has_prefix(filename, "fan") || - g_str_has_prefix(filename, "curr") || - g_str_has_prefix(filename, "in"))) || - (g_str_has_prefix(filename, "cpu") && - (g_str_has_suffix(filename, "_vid")))) { - i2c_sys_plugin_add_sensor(sensors, path); - - } - g_free(filename); + + g_free(filename); + g_free(id); + g_free(label); +} + +static void i2c_sys_plugin_test_sensor(GList **sensors, const gchar *path) { +gchar *filename; + +filename = g_path_get_basename(path); + +if ((g_str_has_suffix(filename, "_input") && + (g_str_has_prefix(filename, "temp") || + g_str_has_prefix(filename, "fan") || + g_str_has_prefix(filename, "curr") || + g_str_has_prefix(filename, "in"))) || + (g_str_has_prefix(filename, "cpu") && + (g_str_has_suffix(filename, "_vid")))) { + + i2c_sys_plugin_add_sensor(sensors, path); +} + + g_free(filename); } /* to be called to setup for sys sensors */ static GList *i2c_sys_plugin_init(void) { - GList *sensors = NULL; - /* call function to recursively look for sensors - starting at the defined base directory */ - sensors_applet_plugin_find_sensors(&sensors, - I2C_SYS_BASE_DIR, - i2c_sys_plugin_test_sensor); - return sensors; + GList *sensors = NULL; + + /* call function to recursively look for sensors + starting at the defined base directory */ + sensors_applet_plugin_find_sensors(&sensors, + I2C_SYS_BASE_DIR, + i2c_sys_plugin_test_sensor); + return sensors; } - -static gdouble i2c_sys_plugin_get_sensor_value(const gchar *path, - const gchar *id, +static gdouble i2c_sys_plugin_get_sensor_value(const gchar *path, + const gchar *id, SensorType type, GError **error) { - - /* to open and access the value of each sensor */ - FILE *fp; - gfloat sensor_value; - - if (NULL == (fp = fopen(path, "r"))) { - g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, I2C_SYS_DEVICE_FILE_OPEN_ERROR, "Error opening sensor device file %s", path); - return -1.0; - } - - if (fscanf(fp, "%f", &sensor_value) != 1) { - g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, I2C_SYS_DEVICE_FILE_READ_ERROR, "Error reading from sensor device file %s", path); - fclose(fp); - return -1.0; - } - fclose(fp); - - if (type != FAN_SENSOR) { - sensor_value /= 1000.0; - } - - return (gdouble)sensor_value; + + /* to open and access the value of each sensor */ + FILE *fp; + gfloat sensor_value; + + if (NULL == (fp = fopen(path, "r"))) { + g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, I2C_SYS_DEVICE_FILE_OPEN_ERROR, "Error opening sensor device file %s", path); + return -1.0; + } + + if (fscanf(fp, "%f", &sensor_value) != 1) { + g_set_error(error, SENSORS_APPLET_PLUGIN_ERROR, I2C_SYS_DEVICE_FILE_READ_ERROR, "Error reading from sensor device file %s", path); + fclose(fp); + return -1.0; + } + fclose(fp); + + if (type != FAN_SENSOR) { + sensor_value /= 1000.0; + } + + return (gdouble)sensor_value; } -const gchar *sensors_applet_plugin_name(void) +const gchar *sensors_applet_plugin_name(void) { - return plugin_name; + return plugin_name; } -GList *sensors_applet_plugin_init(void) +GList *sensors_applet_plugin_init(void) { - return i2c_sys_plugin_init(); + return i2c_sys_plugin_init(); } -gdouble sensors_applet_plugin_get_sensor_value(const gchar *path, - const gchar *id, +gdouble sensors_applet_plugin_get_sensor_value(const gchar *path, + const gchar *id, SensorType type, GError **error) { - return i2c_sys_plugin_get_sensor_value(path, id, type, error); + + return i2c_sys_plugin_get_sensor_value(path, id, type, error); } |