#include <time.h>
#include <stdio.h>
+#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
#include <inttypes.h>
#include "functions.h"
+#define UFINT "%"PRIuFAST16
+
void get_temp(char *, char *);
void get_temp(char *str1, char *str2)
{
snprintf(str2, VLA, FMT_UINT, temp);
}
-void get_voltage(char *str1)
-{
- float voltage[4];
- FILE *fp;
- uint_fast16_t x = 0;
-
- char *voltage_files[] =
- {
- HWMON_DIR"in0_input",
- HWMON_DIR"in1_input",
- HWMON_DIR"in2_input",
- HWMON_DIR"in3_input"
- };
-
- for (x = 0; x < 4; x++)
- {
- if(!(fp = fopen(voltage_files[x], "r")))
- exit(EXIT_FAILURE);
-
- fscanf(fp, "%f", &voltage[x]);
- fclose(fp);
-
- voltage[x] /= (float)1000.0;
- }
-
- snprintf(str1, VLA, "%.2f %.2f %.2f %.2f",
- voltage[0], voltage[1], voltage[2], voltage[3]);
-}
-
-void get_mobo(char *str1, char *str2)
-{
- char vendor[VLA], name[VLA];
-
- FILE *fp = fopen(MOBO_VENDOR, "r");
- if (NULL == fp)
- exit(EXIT_FAILURE);
-
- /* use %[^\n] to get the whole line */
- fscanf(fp, "%s", vendor);
- fclose(fp);
-
- if (!(fp = fopen(MOBO_NAME, "r")))
- exit(EXIT_FAILURE);
-
- /* use %[^\n] to get the whole line */
- fscanf(fp, "%s", name);
- fclose(fp);
-
- get_temp(MOBO_TEMP_FILE, str2);
-
- snprintf(str1, VLA*2, "%s %s", vendor, name);
-}
void get_cpu(char *str1, char *str2)
{
FILL_ARR(str1, percent);
}
+
void get_ram(char *str1)
{
uintmax_t used = 0, total = 0, percent = 0;
return packs_num;
}
+
void get_packs(char *str1)
{
FILE *pkgs_file;
}
+void get_voltage(char *str1)
+{
+ float voltage[4];
+ FILE *fp;
+ uint_fast16_t x = 0;
+
+ char *voltage_files[] =
+ {
+ HWMON_DIR"in0_input",
+ HWMON_DIR"in1_input",
+ HWMON_DIR"in2_input",
+ HWMON_DIR"in3_input"
+ };
+
+ for (x = 0; x < 4; x++)
+ {
+ if (!(fp = fopen(voltage_files[x], "r")))
+ exit(EXIT_FAILURE);
+
+ fscanf(fp, "%f", &voltage[x]);
+ fclose(fp);
+
+ voltage[x] /= (float)1000.0;
+ }
+
+ snprintf(str1, VLA, "%.2f %.2f %.2f %.2f",
+ voltage[0], voltage[1], voltage[2], voltage[3]);
+}
+
+
+void get_fans(char *str1)
+{
+ FILE *fp;
+ bool found_fans = true;
+ char tempstr[VLA], buffer[VLA*5];
+ char *all_fans = buffer;
+ uint_fast16_t x = 0, z = 0, rpm[11];
+
+ for (x = 1; x < 10; x++, z++)
+ {
+ snprintf(tempstr, VLA, HWMON_DIR"fan"UFINT"_input", x);
+
+ if (!(fp = fopen(tempstr, "r")) && x > 1)
+ break;
+ else
+ if (NULL == fp) /* no system fans */
+ {
+ snprintf(str1, VLA, "%s", "Not found");
+ found_fans = false;
+ break;
+ }
+
+ fscanf(fp, UFINT, &rpm[z]);
+ fclose(fp);
+ }
+
+ if (found_fans)
+ {
+ for (x = 0; x < z; ++x)
+ all_fans += snprintf(all_fans,
+ sizeof(buffer) - (all_fans - buffer),
+ UFINT" ", rpm[x]);
+
+ snprintf(str1, VLA, "%s", buffer);
+ }
+}
+
+
+void get_mobo(char *str1, char *str2)
+{
+ char vendor[VLA], name[VLA];
+
+ FILE *fp = fopen(MOBO_VENDOR, "r");
+ if (NULL == fp)
+ exit(EXIT_FAILURE);
+
+ /* use %[^\n] to get the whole line */
+ fscanf(fp, "%s", vendor);
+ fclose(fp);
+
+ if (!(fp = fopen(MOBO_NAME, "r")))
+ exit(EXIT_FAILURE);
+
+ /* use %[^\n] to get the whole line */
+ fscanf(fp, "%s", name);
+ fclose(fp);
+
+ get_temp(MOBO_TEMP_FILE, str2);
+
+ snprintf(str1, VLA*2, "%s %s", vendor, name);
+}
+
+
void get_time(char *str1)
{
char time_str[VLA];
#define FMT_SSD FMT
#define FMT_PKGS FMT_TIME"%c "
#define FMT_VOLT FMT_PKGS
+#define FMT_FANS FMT_TIME
#define FMT_KERN "\x09%s%c "
#define FMT_VOL FMT
#define COMMA ','
char packs[VLA] = GIVEN_DISTRO;
char mobo[VLA], cpu[VLA], ram[VLA], ssd[VLA];
char kern[VLA], volume[VLA], Time[VLA], combine[VLA*9];
- char voltage[VLA], cpu_temp[VLA], mobo_temp[VLA];
+ char voltage[VLA], cpu_temp[VLA], mobo_temp[VLA], fans[VLA];
get_cpu(cpu, cpu_temp);
sleep(1);
- get_voltage(voltage);
- get_mobo(mobo, mobo_temp);
get_cpu(cpu, cpu_temp);
get_ram(ram);
get_ssd(ssd);
get_packs(packs);
get_kernel(kern);
+ get_voltage(voltage);
+ get_fans(fans);
+ get_mobo(mobo, mobo_temp);
get_volume(volume);
get_time(Time);
snprintf(combine, VLA*9,
- FMT_CPU FMT_RAM FMT_SSD FMT_PKGS FMT_KERN FMT_VOLT FMT_MOBO FMT_VOL FMT_TIME,
+ FMT_CPU FMT_RAM FMT_SSD FMT_PKGS FMT_KERN
+ FMT_VOLT FMT_FANS FMT_MOBO FMT_VOL FMT_TIME,
"CPU", cpu, cpu_temp, COMMA,
"RAM", ram, COMMA,
"SSD", ssd, COMMA,
"Pkgs", packs, COMMA,
kern, COMMA,
"Voltage", voltage, COMMA,
+ "Fans/RPM", fans,
"Mobo", mobo, mobo_temp, COMMA,
"Volume", volume, COMMA,
"Time", Time);