whole 1st line done basically
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#define LCD_LINES 4
|
||||
#define LCD_COLS 40
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
struct lcd_t {
|
||||
@@ -24,7 +25,7 @@ void lcd_set_custom_char(struct lcd_t* lcd, uint8_t index, const lcd_glyph_t* gl
|
||||
void lcd_write_str(struct lcd_t* lcd, const char* str, uint8_t len);
|
||||
void lcd_write_str_pos(struct lcd_t* lcd, const char* str, uint8_t len, uint8_t posX, uint8_t posY);
|
||||
void lcd_write_buf(struct lcd_t* lcd, uint8_t row, uint8_t col, const char* str);
|
||||
int lcd_writef(struct lcd_t *lcd, uint8_t offset, const char *fmt, ...);
|
||||
void lcd_writef(struct lcd_t *lcd, uint8_t x, uint8_t y, const char *fmt, ...) __attribute__((format(printf, 4, 5)));
|
||||
void lcd_clear_buf(struct lcd_t* lcd);
|
||||
void lcd_flush_buf(struct lcd_t* lcd);
|
||||
char lcd_bar(struct lcd_t* lcd, uint8_t char_id, double value);
|
||||
|
||||
12
include/sys.h
Normal file
12
include/sys.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef LINUXSMARTIE_SYS_H
|
||||
#define LINUXSMARTIE_SYS_H
|
||||
|
||||
struct time_date_t {
|
||||
char date[12];
|
||||
char time[9];
|
||||
};
|
||||
|
||||
void sys_get_time(struct time_date_t *td);
|
||||
void sys_get_load_avg(double *load_avg);
|
||||
|
||||
#endif //LINUXSMARTIE_SYS_H
|
||||
18
src/sys.c
Normal file
18
src/sys.c
Normal file
@@ -0,0 +1,18 @@
|
||||
#include "sys.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
void sys_get_time(struct time_date_t *td) {
|
||||
constexpr char months[][4] = {"sty", "lut", "mar", "kwi", "maj", "cze", "lip", "sie", "wrz", "paz", "lis", "gru"};
|
||||
constexpr char wdays[][4] = {"Nie", "Pon", "Wto", "Sro", "Czw", "Pia", "Sob"};
|
||||
const time_t t = time(nullptr);
|
||||
const struct tm *tm = localtime(&t);
|
||||
snprintf(td->time, sizeof(td->time), "%02d:%02d:%02d", tm->tm_hour, tm->tm_min, tm->tm_sec);
|
||||
snprintf(td->date, sizeof(td->date), "%s, %02d %s", wdays[tm->tm_wday], tm->tm_mday, months[tm->tm_mon]);
|
||||
}
|
||||
|
||||
void sys_get_load_avg(double *load_avg) {
|
||||
getloadavg(load_avg, 3);
|
||||
}
|
||||
Reference in New Issue
Block a user