Verified Commit ddb6face authored by Vinod Mishra's avatar Vinod Mishra
Browse files

Initial commit

parents
# Created by https://www.gitignore.io/api/c,c++,assembler
# Edit at https://www.gitignore.io/?templates=c,c++,assembler
### General ###
*.exe
*.lst
*.o
*.obj
*.bc
*.cache
.vscode/*
### C ###
# Prerequisites
*.d
# Linker output
*.ilk
*.map
*.exp
# Firmware
*.elf
*.bin
*.hex
# Precompiled Headers
*.gch
*.pch
# Libraries
*.lib
*.a
*.la
*.lo
# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib
# Executables
*.out
*.app
*.i*86
*.x86_64
# Debug files
*.dSYM/
*.su
*.idb
*.pdb
# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf
### C++ ###
# Prerequisites
# Compiled Object files
*.slo
# Precompiled Headers
# Compiled Dynamic libraries
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
# Executables
# End of https://www.gitignore.io/api/c,c++,assembler
\ No newline at end of file
/*----------------------------------------------------------------------------------
DISPLAY STYLE 1
----------------------------------------------------------------------------------*/
void DisplayStyle1() {
//-------------------------------------------Clearing Box ----------------------------------------------------
//Clearing Boxes, eg: display.fillRect(<X>, ^Y^, W, H, Color);*/
display.fillRect(0, 0, 128, 64, BLACK); // Clear entire screen
//--------------------------------------- Display Background ----------------------------------------------------
/* OLED Background */
display.setTextSize(2); //set background txt font size
display.setCursor(1, 12);
display.println("CPU");
display.setCursor(1, 38);
display.println("GPU");
display.setTextSize(1); //set background txt font size
display.setCursor(1, 56);
display.println("SYSRAM");
//---------------------------------------CPU & GPU Hardware ID----------------------------------------------------
display.setTextSize(0); // string font size
display.println("");
display.setTextSize(1);
display.setCursor(0, 1);
display.println(data.CpuName);
display.setTextSize(0);
display.setCursor(0, 28);
display.println(data.GpuName);
//------------------------------------------ CPU Load/Temp -------------------------------------------------
/*CPU TEMPERATURE*/
display.setTextSize(2);
display.setCursor(42, 12);
display.print(data.CpuTemperature);
display.setTextSize(1);
#ifdef noDegree
display.print("C"); // Centigrade Symbol
#else
display.print((char)247); //Degrees Symbol
display.print("C"); // Centigrade Symbol
#endif
/*CPU LOAD, ALL CORES*/
display.setTextSize(2);
display.print(" " + data.CpuLoad);
display.setTextSize(1);
display.println("%"); // Small Percent Symbol
//------------------------------------------ GPU Load/Temp -------------------------------------------------
/*GPU TEMPERATURE*/
display.setTextSize(2);
display.setCursor(42, 38);
display.print(data.GpuTemperature);
display.setTextSize(1);
#ifdef noDegree
display.print("C"); // Centigrade Symbol
#else
display.print((char)247); //Degrees Symbol
display.print("C"); // Centigrade Symbol
#endif
/*GPU LOAD*/
display.setTextSize(2);
display.print(" " + data.GpuLoad);
display.setTextSize(1);
display.println("%"); // Small Percent Symbol
//----------------------------------------SYSTEM RAM USAGE---------------------------------------------------
/*RAM USAGE*/
display.setTextSize(1); //set background txt font size
display.setCursor(42, 56);
display.print(data.RamUsed + "GB");
display.setTextSize(1);
display.setCursor(115, 1);
display.println("D1");
display.display();
oledDraw = 1;
}
/*----------------------------------------------------------------------------------
DISPLAY STYLE 2
----------------------------------------------------------------------------------*/
void DisplayStyle2() {
//-------------------------------------------Clearing Box ----------------------------------------------------
//Clearing Boxes, eg: display.fillRect(<X>, ^Y^, W, H, Color);*/
display.fillRect(0, 0, 128, 64, BLACK); // Clear entire screen for testing
//---------------------------------------- Static Background ----------------------------------------------------
display.setTextSize(2); //set background txt font size
display.setCursor(1, 12);
display.println("CPU");
display.setCursor(1, 38);
display.println("GPU");
display.setTextSize(1); //set background txt font size
//---------------------------------------CPU & GPU Hardware ID--------------------------------------------------
/*CPU & GPU Hardware ID*/
display.setTextSize(0); // string font size
display.println("");
display.setTextSize(1);
display.setCursor(0, 1);
display.println(data.CpuName);
display.setTextSize(0);
display.setCursor(0, 28);
display.println(data.GpuName);
//------------------------------------------ CPU Freq -------------------------------------------------
/*CPU Core Freq*/
display.setTextSize(2);
display.setCursor(42, 12);
display.print(data.CpuClock);
display.setTextSize(1);
display.print("MHz");
//------------------------------------------ CPU Temp -------------------------------------------------
/*CPU TEMPERATURE*/
display.setTextSize(1);
display.setCursor(105, 22);
display.print(data.CpuTemperature);
display.setTextSize(1);
#ifdef noDegree
display.print("C"); // Centigrade Symbol
#else
display.print((char)247); //Degrees Symbol
display.print("C"); // Centigrade Symbol
#endif
//------------------------------------------ GPU Freq/Temp -------------------------------------------------
/*GPU Core Freq*/
display.setTextSize(1);
display.setCursor(42, 38);
display.print("Core :");
display.print(data.GpuCoreClock);
display.setTextSize(1);
display.print("MHz"); // Centigrade Symbol
display.setCursor(42, 46);
display.print("VRAM :");
display.print(data.GpuMemoryClock);
display.print("MHz");
display.setCursor(42, 54);
display.print("Shader:");
display.print(data.GpuShaderClock);
display.print("MHz");
/*GPU TEMPERATURE*/
display.setTextSize(1);
display.setCursor(1, 56);
display.print(data.GpuTemperature);
display.setTextSize(1);
#ifdef noDegree
display.print("C"); // Centigrade Symbol
#else
display.print((char)247); //Degrees Symbol
display.print("C"); // Centigrade Symbol
#endif
display.setTextSize(1);
display.setCursor(115, 1);
display.println("D2");
display.display();
oledDraw = 1;
}
/*----------------------------------------------------------------------------------
DISPLAY STYLE 3
----------------------------------------------------------------------------------*/
void DisplayStyle3() {
//-------------------------------------------Clearing Box ----------------------------------------------------
//Clearing Boxes, eg: display.fillRect(<X>, ^Y^, W, H, Color);*/
display.fillRect(0, 0, 128, 64, BLACK); // Clear entire screen for testing
//---------------------------------------- Static Background ----------------------------------------------------
display.setTextSize(2); //set background txt font size
display.setCursor(1, 12);
display.println("CPU");
display.setCursor(1, 38);
display.println("GPU");
display.setTextSize(1); //set background txt font size
//---------------------------------------CPU & GPU Hardware ID--------------------------------------------------
/*CPU & GPU Hardware ID*/
display.setTextSize(0); // string font size
display.println("");
display.setTextSize(1);
display.setCursor(0, 1);
display.println(data.CpuName);
display.setTextSize(0);
display.setCursor(0, 28);
display.println(data.GpuName);
//------------------------------------------ CPU Freq -------------------------------------------------
/*CPU Freq Display*/
display.setTextSize(2);
display.setCursor(42, 12);
display.print(data.CpuClock);
display.setTextSize(1);
display.print("MHz");
//------------------------------------------ CPU Temp -------------------------------------------------
/*CPU Temp Display*/
display.setTextSize(1);
display.setCursor(105, 22);
display.print(data.CpuTemperature);
display.setTextSize(1);
#ifdef noDegree
display.print("C"); // Centigrade Symbol
#else
display.print((char)247); //Degrees Symbol
display.print("C"); // Centigrade Symbol
#endif
//------------------------------------------ GPU Freq/Temp -------------------------------------------------
/* GPU temp V's GPU freq to check for throttling and max 'GPU Boost' */
/*GPU Core Freq Display*/
display.setTextSize(2);
display.setCursor(42, 38);
display.print(data.GpuCoreClock);
display.setTextSize(1);
display.print("MHz");
/*GPU VRAM Freq Display*/
display.setCursor(1, 56);
display.print("VRAM: ");
display.print(data.GpuMemoryClock);
display.print("MHz");
/*GPU Core Temp Display*/
display.setTextSize(1);
display.setCursor(105, 48);
display.print(data.GpuTemperature);
display.setTextSize(1);
#ifdef noDegree
display.print("C"); // Centigrade Symbol
#else
display.print((char)247); //Degrees Symbol
display.print("C"); // Centigrade Symbol
#endif
display.setTextSize(1);
display.setCursor(115, 1);
display.println("D3");
display.display();
oledDraw = 1;
}
Licence
-------
Attribution-NonCommercial-ShareAlike CC BY-NC-SA
This license lets others remix, tweak, and build upon your work non-commercially, as long as they credit you and license their new creations under the identical terms.
https://creativecommons.org/licenses/
/*
PikkuStats - Version 0.1
Vinod Mishra
----------------------------------------------------------------------------------
ATTRIBUTION
----------------------------------------------------------------------------------
Heavily based on
GNATSTATS PC Performance Monitor - Version 1.x Rupert Hirst & Colin Conway © 2016
http://tallmanlabs.com & http://runawaybrainz.blogspot.com/
----------------------------------------------------------------------------------
LICENSE
----------------------------------------------------------------------------------
Attribution-NonCommercial-ShareAlike CC BY-NC-SA
This license lets others remix, tweak, and build upon your work non-commercially, as long as they credit you and license their new creations under the identical terms.
https://creativecommons.org/licenses/
----------------------------------------------------------------------------------
NOTES
----------------------------------------------------------------------------------
- Only ATmega32U4 boards are supported
- Only supports SH1106 or SSD1306 i2c displays supported
- Needs the counterpart desktop application Wee Hardware Stat Server available at https://gitlab.com/vinodmishra/wee-hardware-stat-server which uses LibreHardwareMonitor lib to detect the hardware.
- Does not support integrated GPUs.
----------------------------------------------------------------------------------
NOTES
----------------------------------------------------------------------------------
Version 0.1 : Refactor and reorganisation to clean up duplicate code and avoid doing extra procesing when getting incoming data.
Switched to a new data format which uses WeeHardwareStatmonitor instead which is easier to parse.
Removed Neopixel as it frees up some memory and I have no need for it at the moment.
----------------------------------------------------------------------------------
LIBRARIES
----------------------------------------------------------------------------------
Adafruit SSD1306 library
https://github.com/adafruit/Adafruit_SSD1306
Adafruit library ported to the SH1106
https://github.com/badzz/Adafruit_SH1106
Adafruit GFX Library
https://github.com/adafruit/Adafruit-GFX-Library
*/
#include <Adafruit_GFX.h>
#include <SPI.h>
#include <Wire.h>
#include "bitmap.h"
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#define CODE_VERS "0.1" // Code version number
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/*----------------------------------------------------------------------------------
CONFIGURATION OPTIONS
----------------------------------------------------------------------------------
----------------------------------
Pins Reference
----------------------------------
SDA: D2, SCL: D3
----------------------------------*/
//----------------------------------- OLED Setup ----------------------------------------
/*Uncomment the correct OLED display type, uncomment only one!!!*/
#define OLED_SSD1306
//#define OLED_SH1106
/* Uncomment the initialize the I2C address , uncomment only one, If you get a totally blank screen try the other*/
#define i2c_Address 0x3c //initialize with the I2C addr 0x3C Typically eBay OLED's
//#define i2c_Address 0x3d //initialize with the I2C addr 0x3D Typically Adafruit OLED's
/*Rotate the display at the start: 0 or 2 (0, 180 degrees)*/
#define rotateScreen 2
/* Uncomment below, to enable positive and negative screen cycler */
//#define enableInvertscreen
/* Uncomment below, to take out small degree symbol for better spacing
when hitting 100% cpu/gpu load the percent symbol gets clipped */
//#define noDegree
//------------------------------------- Other Stuff --------------------------------------------
/* comment out, to disable blank screen on serial timeout to retain info eg: PC crash fault diagnostics */
#define enableActivityChecker
/* Time between "DisplayStyle" changes */
#define displayChangeDelay 18000
/* Timer for active connection to host*/
#define lastActiveDelay 10000
//------------------------------------ End of User configuration ---------------------------------
/*----------------------------------------------------------------------------------
DEFINITIONS AND GLOBAL VARS
----------------------------------------------------------------------------------*/
/*SH1106 OLED setup*/
#ifdef OLED_SH1106
#include <Adafruit_SH1106.h> // i2C not SPI
#define SH1106_128_64
#define OLED_RESET 4 // "OLED_RESET" IS IS NOT A PHYSICAL PIN DO NOT CONNECT!!!
Adafruit_SH1106 display(OLED_RESET);
#endif
//-----------------------
/*SSD1306 OLED setup*/
#ifdef OLED_SSD1306
#include <Adafruit_SSD1306.h> // i2C not SPI
#define SSD1306_128_64
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET 4 // "OLED_RESET" IS IS NOT A PHYSICAL PIN DO NOT CONNECT!!!
//#define OLED_RESET -1 // QT-PY / XIAO
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#endif
//----------------------
/* More OLED stuff*/
int oledDraw = 0;
int oledOverride = 0;
//----------------------
/* Inverted timers for oled*/
long invertDelay = 60000; // 60 sec delay
long lastInvertTime = 0;
int invertedStatus = 1;
//----------------------
/* Debounce timers for buttons /// lastDebounceTime = millis();*/
long lastDebounceTime = 0;
long debounceDelay = 3000;
//----------------------
/* Delay screen event, to help stop screen data corruption ESP8622 use 25, most others 5 will do*/
int Serial_eventDelay = 0;
/* Timer for active connection to host*/
boolean activeConn = false;
long lastActiveConn = 0;
boolean bootMode = true;
/*vars for serial input*/
String inputString = "";
boolean stringComplete = false;
struct HardwareInfo {
String CpuName;
String CpuTemperature;
String CpuLoad;
String CpuClock;
String GpuName;
String GpuTemperature;
String GpuLoad;
String GpuCoreClock;
String GpuMemoryClock;
String GpuShaderClock;
String RamUsed;
};
HardwareInfo data = HardwareInfo();
//----------------------
/* Start DisplayStyle */
int displayChangeMode = 1;
long lastDisplayChange;
//----------------------
/*----------------------------------------------------------------------------------
SETUP
----------------------------------------------------------------------------------*/
void setup() {
/* OLED SETUP */
#ifdef OLED_SH1106
display.begin(SH1106_SWITCHCAPVCC, i2c_Address); // initialize with the I2C addr 0x3D (for the 128x64)
#endif
#ifdef OLED_SSD1306
display.begin(SSD1306_SWITCHCAPVCC, i2c_Address); // initialize with the I2C addr 0x3D (for the 128x64
#endif
display.clearDisplay();
display.setTextColor(WHITE);
display.setRotation(rotateScreen); // Rotate the display at the start: 0, 1, 2 or 3 = (0, 90, 180 or 270 degrees)
display.clearDisplay();
/* stops text wrapping*/
display.setTextWrap(false); // Stop "Loads/Temps" wrapping and corrupting static characters
/* Serial setup, start serial port at 9600 bps and wait for port to open:*/
Serial.begin(9600); // 32u4 USB Serial Baud Rate
inputString.reserve(200);
/*Initial Load screen*/
splashScreen();
}
//END of Setup
/*----------------------------------------------------------------------------------
MAIN LOOP
----------------------------------------------------------------------------------*/
void loop() {
/*Serial stuff*/
serialEvent();
#ifdef enableActivityChecker
activityChecker();
#endif
/*change display screen*/
if ((millis() - lastDisplayChange) > displayChangeDelay) {
if (displayChangeMode == 1) {
displayChangeMode = 2;
display.fillRect(0, 0, 128, 64, BLACK);
} else if (displayChangeMode == 2) {
displayChangeMode = 3;
display.fillRect(0, 0, 128, 64, BLACK);
} else if (displayChangeMode == 3) {
displayChangeMode = 1;
display.fillRect(0, 0, 128, 64, BLACK);
}
lastDisplayChange = millis();
}
/* OLED DRAW STATS */
if (stringComplete) {
if (bootMode) {
display.clearDisplay();
display.display();
bootMode = false;
}
lastActiveConn = millis();
if (displayChangeMode == 1) {
DisplayStyle1();
} else if (displayChangeMode == 2) {
DisplayStyle2();
} else if (displayChangeMode == 3) {
DisplayStyle3();
}
inputString = "";
stringComplete = false;
/* Keep running anti screen burn, whilst serial is active */
if ((millis() - lastInvertTime) > invertDelay && oledDraw == 1) {
lastInvertTime = millis();
#ifdef enableInvertscreen
inverter();
#endif
}
}
}
//END of Main Loop