clangify includes
This commit is contained in:
@@ -4,16 +4,8 @@
|
||||
#define LCD_LINES 4
|
||||
#define LCD_COLS 40
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <log.hpp>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
class LCDDisplay {
|
||||
@@ -23,8 +15,7 @@ class LCDDisplay {
|
||||
char writebuf[LCD_LINES * LCD_COLS + 8]; // 4x40 chars + 2x4 setcursor commands
|
||||
static constexpr bool dualDisp = (LCD_LINES * LCD_COLS > 80); // is it dual display device or not, evauluated from the size at compile time
|
||||
void writeLines(std::array<std::string, 4> lines); // do not use
|
||||
|
||||
|
||||
|
||||
public:
|
||||
LCDDisplay(std::string dev, uint32_t baud = 0010002); // from termios-baud.h, B115200
|
||||
~LCDDisplay();
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
#ifndef CPU_HPP
|
||||
#define CPU_HPP
|
||||
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
#include <log.hpp>
|
||||
#include <string>
|
||||
#include <utils.hpp>
|
||||
|
||||
#define N_CPU 16
|
||||
|
||||
|
||||
@@ -2,11 +2,8 @@
|
||||
#define GPU_HPP
|
||||
|
||||
#include <cstdint>
|
||||
#include <fstream>
|
||||
#include <gpu_metrics.hpp>
|
||||
#include <log.hpp>
|
||||
#include <string>
|
||||
#include <utils.hpp>
|
||||
|
||||
|
||||
#define REL_METRICS_PATH "/../../gpu_metrics" // gpu_metrics path relative to hwmon path
|
||||
#define MAX_METRICS_LENGTH 512 // length of the metrics buffer
|
||||
|
||||
@@ -3,9 +3,7 @@
|
||||
|
||||
#include <libwebsockets.h>
|
||||
|
||||
#include <ArduinoJson.hpp>
|
||||
#include <iostream>
|
||||
#include <log.hpp>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
#define HASS_TOKEN "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiI0MzUxMTZiY2VjNTg0MTI3OGI4YmU0NTY4ZGQ5MzIyYiIsImlhdCI6MTc1NzQzMDI0MCwiZXhwIjoyMDcyNzkwMjQwfQ.6wKTlxEA0FLWfv-qW35vewUSvTxdVrZWqFwHT5Khu6E"
|
||||
@@ -16,10 +14,10 @@ class HomeAssistant {
|
||||
std::string entity;
|
||||
uint16_t id = 2;
|
||||
std::string tx;
|
||||
struct lws_context *context = NULL;
|
||||
lws *websock = NULL;
|
||||
void event_handler(struct lws *wsi, enum lws_callback_reasons reason, char *in);
|
||||
static int callback(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len);
|
||||
struct lws_context* context = NULL;
|
||||
lws* websock = NULL;
|
||||
void event_handler(struct lws* wsi, enum lws_callback_reasons reason, char* in);
|
||||
static int callback(struct lws* wsi, enum lws_callback_reasons reason, void* user, void* in, size_t len);
|
||||
|
||||
public:
|
||||
HomeAssistant(std::string addr, std::string ent);
|
||||
|
||||
@@ -11,8 +11,8 @@ const char wdays[][4] = {"Nie", "Pon", "Wto", "Sro", "Czw", "Pia", "Sob"};
|
||||
|
||||
struct sysSensors {
|
||||
std::string hwmon = "";
|
||||
uint16_t fan_speed[2] = {0}; // left and right cpu fans
|
||||
uint8_t t_sensor = 0; // ntc temp sensor
|
||||
uint16_t fan_speed[2] = {0}; // left and right cpu fans
|
||||
uint8_t t_sensor = 0; // ntc temp sensor
|
||||
};
|
||||
|
||||
struct Memory {
|
||||
|
||||
@@ -1,17 +1,9 @@
|
||||
#ifndef UTILS_HPP
|
||||
#define UTILS_HPP
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <filesystem>
|
||||
#include <format>
|
||||
#include <log.hpp>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#define FILL_CHAR ' '
|
||||
|
||||
@@ -22,8 +14,8 @@ std::string pad(std::string s, uint8_t len, bool ljust = false);
|
||||
std::string center(std::string str, uint8_t len);
|
||||
std::string pBytes(double bytes, bool isKbytes = false);
|
||||
std::string readFile(std::string path, size_t trim = 4096);
|
||||
ssize_t readFile2(std::string path, char *buffer, size_t maxlen);
|
||||
ssize_t readFile2(const char *path, char *buffer, size_t maxlen);
|
||||
ssize_t readFile2(std::string path, char* buffer, size_t maxlen);
|
||||
ssize_t readFile2(const char* path, char* buffer, size_t maxlen);
|
||||
int get_val(std::string_view target, std::string_view content);
|
||||
std::string getFirstDir(std::string_view path);
|
||||
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
#include "LCDDisplay.hpp"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <log.hpp>
|
||||
#include <string>
|
||||
|
||||
/* lcd size hardcoded to 4x40 idgaf */
|
||||
LCDDisplay::LCDDisplay(std::string dev, uint32_t baud) {
|
||||
_dev = dev;
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
#include <chrono>
|
||||
#include <cpu.hpp>
|
||||
#include <print>
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
#include <log.hpp>
|
||||
#include <string>
|
||||
#include <utils.hpp>
|
||||
|
||||
namespace cpu {
|
||||
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
#include <gpu.hpp>
|
||||
#include <gpu_metrics.hpp>
|
||||
#include <log.hpp>
|
||||
#include <string>
|
||||
#include <utils.hpp>
|
||||
|
||||
/* maybe have a read pp_table function */
|
||||
/* would be neat to wrap it in a class but eh namespace is good enough */
|
||||
|
||||
20
src/hass.cpp
20
src/hass.cpp
@@ -1,4 +1,10 @@
|
||||
|
||||
#include <libwebsockets.h>
|
||||
|
||||
#include <ArduinoJson.hpp>
|
||||
#include <hass.hpp>
|
||||
#include <log.hpp>
|
||||
#include <string>
|
||||
|
||||
HomeAssistant::HomeAssistant(std::string addr, std::string ent) {
|
||||
address = addr;
|
||||
@@ -9,7 +15,7 @@ HomeAssistant::~HomeAssistant() {
|
||||
disconnect();
|
||||
}
|
||||
|
||||
void HomeAssistant::event_handler(struct lws *wsi, enum lws_callback_reasons reason, char *in) {
|
||||
void HomeAssistant::event_handler(struct lws* wsi, enum lws_callback_reasons reason, char* in) {
|
||||
ArduinoJson::JsonDocument json;
|
||||
switch (reason) {
|
||||
case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: {
|
||||
@@ -50,7 +56,7 @@ void HomeAssistant::event_handler(struct lws *wsi, enum lws_callback_reasons rea
|
||||
break;
|
||||
}
|
||||
|
||||
log(LOG::WRN, "HomeAssistant::event_handler", "unhandled event: {}", (char *)in);
|
||||
log(LOG::WRN, "HomeAssistant::event_handler", "unhandled event: {}", (char*)in);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -68,7 +74,7 @@ void HomeAssistant::event_handler(struct lws *wsi, enum lws_callback_reasons rea
|
||||
/* skip whole callback if there's no tx to send */
|
||||
if (tx.size() > 0) {
|
||||
size_t msgLen = LWS_PRE + tx.size();
|
||||
unsigned char *buf = (unsigned char *)malloc(msgLen);
|
||||
unsigned char* buf = (unsigned char*)malloc(msgLen);
|
||||
if (buf) {
|
||||
memcpy(&buf[LWS_PRE], tx.c_str(), tx.size());
|
||||
if (!lws_write(wsi, &buf[LWS_PRE], tx.size(), LWS_WRITE_TEXT))
|
||||
@@ -85,9 +91,9 @@ void HomeAssistant::event_handler(struct lws *wsi, enum lws_callback_reasons rea
|
||||
}
|
||||
}
|
||||
|
||||
int HomeAssistant::callback(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len) {
|
||||
HomeAssistant *self = static_cast<HomeAssistant *>(user);
|
||||
self->event_handler(wsi, reason, (char *)in);
|
||||
int HomeAssistant::callback(struct lws* wsi, enum lws_callback_reasons reason, void* user, void* in, size_t len) {
|
||||
HomeAssistant* self = static_cast<HomeAssistant*>(user);
|
||||
self->event_handler(wsi, reason, (char*)in);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -101,7 +107,7 @@ int HomeAssistant::connect() {
|
||||
memset(&info, 0, sizeof info);
|
||||
|
||||
static const struct lws_protocols protocols[] = {
|
||||
{"lws-minimal-client", callback, sizeof(void *), 0, 0, NULL, 0},
|
||||
{"lws-minimal-client", callback, sizeof(void*), 0, 0, NULL, 0},
|
||||
LWS_PROTOCOL_LIST_TERM};
|
||||
|
||||
static const struct lws_extension extensions[] = {
|
||||
|
||||
11
src/sys.cpp
11
src/sys.cpp
@@ -1,4 +1,5 @@
|
||||
#include <sys/statvfs.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <format>
|
||||
#include <string>
|
||||
@@ -35,11 +36,11 @@ void sys::getNetwork(Network* net, std::string device) {
|
||||
uint64_t rx = 0;
|
||||
uint64_t tx = 0;
|
||||
};
|
||||
|
||||
|
||||
static _net prev;
|
||||
_net current;
|
||||
|
||||
current.ts = std::chrono::steady_clock::now();
|
||||
|
||||
current.ts = std::chrono::steady_clock::now();
|
||||
current.rx = std::stoull(readFile("/sys/class/net/" + device + "/statistics/rx_bytes", 32));
|
||||
current.tx = std::stoull(readFile("/sys/class/net/" + device + "/statistics/tx_bytes", 32));
|
||||
float ts_diff = std::chrono::duration_cast<std::chrono::microseconds>(current.ts - prev.ts).count() / 1000000.0f;
|
||||
@@ -48,13 +49,13 @@ void sys::getNetwork(Network* net, std::string device) {
|
||||
prev = current;
|
||||
}
|
||||
|
||||
|
||||
void sys::detectHwmon(sysSensors* s, std::string platform) {
|
||||
s->hwmon = getFirstDir("/sys/devices/platform/" + platform + "/hwmon");
|
||||
}
|
||||
|
||||
void sys::updateSensors(sysSensors* s) {
|
||||
s->fan_speed[0] = std::stol(readFile(s->hwmon + "/fan2_input", 4));
|
||||
s->fan_speed[1] = std::stol(readFile(s->hwmon + "/fan7_input", 4));;
|
||||
s->fan_speed[1] = std::stol(readFile(s->hwmon + "/fan7_input", 4));
|
||||
;
|
||||
s->t_sensor = std::stol(readFile(s->hwmon + "/temp5_input", 2));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
#include <utils.hpp>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <filesystem>
|
||||
#include <format>
|
||||
#include <log.hpp>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utils.hpp>
|
||||
|
||||
// pads given string to length
|
||||
std::string pad(std::string s, uint8_t len, bool ljust) {
|
||||
@@ -23,8 +33,8 @@ std::string pBytes(double bytes, bool isKbytes) {
|
||||
if (suffix == 'K' && isKbytes) continue; // skip first loop if already in Kbytes
|
||||
bytes /= 1024.0;
|
||||
if (bytes < 1024) {
|
||||
if(bytes > 100) return pNum(bytes) + suffix;
|
||||
if(bytes > 10) return pNum(bytes, 1) + suffix;
|
||||
if (bytes > 100) return pNum(bytes) + suffix;
|
||||
if (bytes > 10) return pNum(bytes, 1) + suffix;
|
||||
return pNum(bytes, 2) + suffix;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user