sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

commit e8868bc9bfe4a180ca38ed8cbeb6f38e87c2fe19
parent 900314d1bc86f33c9a8fa92f9ff1a795f2049a10
Author: levi0x0 <levi0x0x@gmail.com>
Date:   Wed,  2 Jul 2014 19:03:41 +0300

dwmstatus - bar_monitor-0.4.c Updated.

Diffstat:
Adwm.suckless.org/dwmstatus/bar_monitor-0.4.c | 200+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mdwm.suckless.org/dwmstatus/index.md | 2+-
2 files changed, 201 insertions(+), 1 deletion(-)

diff --git a/dwm.suckless.org/dwmstatus/bar_monitor-0.4.c b/dwm.suckless.org/dwmstatus/bar_monitor-0.4.c @@ -0,0 +1,200 @@ +/* + * bar_monitor.c - another version of dwmstatus. + * + * Written by: levi0x0 (levi0x0x@gmail.com) for dwm. + * Date: 02/07/2014 + * Version: 0.4 + * License: GPL 3 + * + * What it's Displays:: + * 1. time/date + * 2. temerature + * 3. wireless Status. + * 4. battery status. + * + * if you are not using laptop, please define: LAPTOP 0 + * + * ** Using with .xinitrc **: + * + * while [ true ];do + * bar=`bar_monitor` + * xsetroot -name "$bar" + * done & + * + * bar_monitor contain sleep(1) function. + * if you want to add more functions to bar_monitor, + * please let me know. + * + * gcc bar_monitor.c -o bar_monitor + * + * mv bar_monitor /usr/local/bin/bar_monitor + * + */ + + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> + +//BAT1 change if needed +#define STATUS_FILE "/sys/class/power_supply/BAT1/status" +#define CAPACITY_FILE "/sys/class/power_supply/BAT1/capacity" +#define net_file "/proc/net/wireless" +#define temp_file "/sys/class/hwmon/hwmon0/temp1_input" +#define STR_SIZE 30 +#define TIME_FORMAT "%H:%M %d-%m-%y" +#define date read_date() +#define status open_status() +#define pcapacity open_capacity() +#define temp read_temp() +#define nett net() +#define LAPTOP 1 + + +static char status_linecp[STR_SIZE]; +static char time_buffer[STR_SIZE]; +static char net_buffer[STR_SIZE]; +int capacity; + +/*prototypes*/ +char * read_date(void); +char * open_status(void); +char * net(void); +int open_capacity(void); +int read_temp(void); + +int main(int argc, char **argv) { + if (!strcmp(status, "Discharging")) { + //printf("[%d%], Discharging\n", pcapacity); + if ( pcapacity < 10 ) { + printf("%d%% **Low Battery**", pcapacity); + } + else { + printf("%d%%", pcapacity); + } + } + + else if (!strcmp(status, "Charging")) { + //printf("[%d%], Charging\n", pcapacity); + printf("%d%%", pcapacity); + } + else if (!strcmp(status, "Full")) { + printf("[Full]"); + + } + else { + //What?! the program can't read the battery status + printf("w00t?\n"); + + } + #if LAPTOP + printf(" %s %dC %s", nett,temp, date); + #else + printf(" %dC %s", temp, date); + #endif + + sleep(1); + + return 0; +} + + +char * read_date(void) { + time_t now = time(0); + + strftime(time_buffer, STR_SIZE, TIME_FORMAT, localtime(&now)); + + return time_buffer; + +} + +int open_capacity(void) { + FILE *capacity_file; + + capacity_file = fopen(CAPACITY_FILE, "r"); + + if ( capacity_file == NULL ) { + fprintf(stderr, "Failed to open: %s\n", CAPACITY_FILE); + exit(EXIT_FAILURE); + } + + fscanf(capacity_file, "%d", &capacity); + fclose(capacity_file); + + return capacity; +} + +char * open_status(void) { + FILE *status_file; + char *line = NULL; + size_t len = 0; + ssize_t read; + + status_file = fopen(STATUS_FILE, "rt"); + + if ( status_file == NULL ) { + fprintf(stderr, "Failed to open: %s\n"); + exit(EXIT_FAILURE); + } + + while (( read = getline(&line, &len, status_file)) != -1 ) { + ; + } + + strncpy(status_linecp, line, strlen(line)); + + strtok(status_linecp, "\n"); + free(line); + + return status_linecp; +} + +char * net(void) { + FILE *fp; + char buffer[STR_SIZE]; + char *line = NULL; + ssize_t len = 0; + ssize_t read; + + + fp = fopen(net_file, "rt"); + + while (( read = getline(&line, &len, fp)) != -1 ) { + ; + } + + sscanf(line,"%s\n", &buffer); + + free(line); + + //if( strstr(buffer, "wlan") != NULL) { + if( strstr(buffer, "wlp") != NULL) { + return "(ON)"; + } + else { + return "(OFF)"; + } + +} + +/* +* This fucntion read the temperature form temp_file +*/ +int read_temp(void) { + FILE *t_file; + int ret = 0; + + + t_file = fopen(temp_file, "rt"); + + + if ( t_file == NULL ) { + fprintf(stderr, "Failed to open: %s\n", temp_file); + exit(1); + } + + fscanf(t_file, "%d", &ret); + + return ret / 1000; +} diff --git a/dwm.suckless.org/dwmstatus/index.md b/dwm.suckless.org/dwmstatus/index.md @@ -23,7 +23,7 @@ Please add your own version of dwmstatus here. * [profil-dwmstatus-1.0.c](profil-dwmstatus-1.0.c) - cpufreq, battery percent and date/time * [suspend-statusbar.c](suspend-statusbar.c) - loadavg, wifi, battery and date. If battery goes below threshold - run suspend command * [gods](https://github.com/schachmat/gods) - implemented in Go. prints network speed, cpu, ram, date/time -* [barmonitor](https://github.com/levi0x0/Scrips-IO/blob/master/bar_monitor.c) - display battery status, date/time. +* [barmonitor](bar_monitor-0.4.c) - displays, battery status, date/time, temperature, network status. Helper functions