#include <U8g2lib.h>
// U8X8_SSD1306_128X64_NONAME_HW_I2C display(U8X8_PIN_NONE);
// U8G2_SSD1306_128X64_NONAME_1_HW_I2C(rotation, [reset [, clock, data]]) [page buffer, size = 128 bytes]
// U8G2_SSD1306_128X64_NONAME_1_HW_I2C(5, 4)// [page buffer, size = 128 bytes]
// U8G2_SSD1306_128X64_NONAME_1_HW_I2C(U8G2_R0,U8X8_PIN_NONE,5,4);//[page buffer, size = 128 bytes];
U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE, 5, 4); //[page buffer, size = 128 bytes];
// Temp for testing
#define mobStateLIST_SIZE 3
char *mobStateList[mobStateLIST_SIZE] = { "Connected", "Connecting", "Disconnected" };
#define mobBandLIST_SIZE 3
char *mobBandList[mobBandLIST_SIZE] = { "LTE B20", "LTE B8", "WCDMA 2100" };
#define mobOperatorLIST_SIZE 3
char *mobOperatorList[mobOperatorLIST_SIZE] = { "O2 - UK", "Vodafone - UK", "Lebara" };
#define mobConnTypeLIST_SIZE 3
char *mobConnTypeList[mobConnTypeLIST_SIZE] = { "4G (LTE)", "4G (LTE); VoLTE", "3G" };
// end of temp for testing
int colOne = 5;
int colTwo = 40;
int colThree = 53;
int colFour = 76;
int colFive = 98;
int rowOne = 10;
int rowTwo = 24;
int rowThree = 36;
int rowFour = 48;
int rowFive = 60;
// Temp values for testing
int strValue = 2;
int qalValue = 3;
int pwrValue = 4;
int snrValue = 1;
// end of temp for testing
char mobOperator[14]; // eg "O2 - UK" or "Vodafone UK"
char mobBand[11]; // eg "LTE B41" or "WCDMA 2100"
char mobConnType[16]; // eg "4G (LTE); VoLTE"
char mobState[13]; // eg "Connected"
void setup() {
Serial.begin(9600);
u8g2.begin();
u8g2.setPowerSave(0);
u8g2.setFont(u8g2_font_helvR08_tf);
//Initiate random text
strlcpy(mobState, mobStateList[random(0, 3)], sizeof(mobState));
strlcpy(mobBand, mobBandList[random(0, 3)], sizeof(mobBand));
strlcpy(mobOperator, mobOperatorList[random(0, 3)], sizeof(mobOperator));
strlcpy(mobConnType, mobConnTypeList[random(0, 3)], sizeof(mobConnType));
// End of random text
}
void loop() {
u8g2.firstPage();
do {
drawInternetScreen();
} while (u8g2.nextPage());
// Swap values randomly for testing
strValue = random(1, 5);
qalValue = random(1, 4);
pwrValue = random(1, 4);
snrValue = random(1, 4);
strlcpy(mobState, mobStateList[random(0, 3)], sizeof(mobState));
strlcpy(mobBand, mobBandList[random(0, 3)], sizeof(mobBand));
strlcpy(mobOperator, mobOperatorList[random(0, 3)], sizeof(mobOperator));
strlcpy(mobConnType, mobConnTypeList[random(0, 3)], sizeof(mobConnType));
delay(15000);
// end of test content
}
void drawInternetScreen() {
// u8g2.firstPage();
// do {
u8g2.setFont(u8g2_font_helvR08_tf);
u8g2.setCursor(colOne, rowOne);
// u8g2.print(connectList[0]); //Connection status
u8g2.print(mobState); //Connection status
u8g2.setCursor(u8g2.getStrWidth(mobState) + colOne + 4, rowOne);
u8g2.print(mobConnType); // Line 1
u8g2.drawHLine(0, 14, 128);
u8g2.setCursor(colOne, rowFour);
u8g2.print(F("Operator:"));
u8g2.setCursor(colOne, rowFive);
u8g2.print(F("Band:"));
u8g2.setCursor(colOne, rowTwo);
u8g2.print(F("Signal"));
u8g2.setCursor(colOne, rowThree);
u8g2.print(F("Quality"));
// u8g2.setCursor(colOne, rowFour);
// u8g2.print(F("Power"));
// u8g2.setCursor(colOne, rowFive);
// u8g2.print(F("SNR"));
// u8g2.setCursor(colTwo, rowTwo);
// signalDisplay(colTwo,rowTwo,strValue);
// signalDisplay(colTwo,rowThree,qalValue);
signalDisplay(colTwo, rowTwo, strValue, 5);
signalDisplay(colTwo, rowThree, qalValue, 4);
signalDisplay(colFive, rowTwo, pwrValue, 4);
signalDisplay(colFive, rowThree, snrValue, 4);
// u8g2.print(F("Fair/poor"));
u8g2.setCursor(colThree, rowFour);
u8g2.print(mobOperator);
u8g2.setCursor(colThree, rowFive);
u8g2.print(mobBand);
u8g2.setCursor(colFour, rowTwo);
u8g2.print(F("Pwr"));
u8g2.setCursor(colFour, rowThree);
u8g2.print(F("Sinr"));
// } while (u8g2.nextPage());
}
void signalDisplay(int x, int y, int value, int numPoints) {
int height = 6;
int width = 5;
int space = 1;
int xOrigin = x;
int yOrigin = y - height - 0;
u8g2.drawBox(xOrigin, yOrigin, width, height); //x, y, width, height
xOrigin = xOrigin + width + space;
if (value > 1) {
u8g2.drawBox(xOrigin, yOrigin, width, height); //x, y, width, height
} else {
u8g2.drawFrame(xOrigin, yOrigin, width, height); //x, y, width, height
}
xOrigin = xOrigin + width + space;
if (value > 2) {
u8g2.drawBox(xOrigin, yOrigin, width, height); //x, y, width, height
} else {
u8g2.drawFrame(xOrigin, yOrigin, width, height); //x, y, width, height
}
xOrigin = xOrigin + width + space;
if (value > 3) {
u8g2.drawBox(xOrigin, yOrigin, width, height); //x, y, width, height
} else {
u8g2.drawFrame(xOrigin, yOrigin, width, height); //x, y, width, height
}
if (numPoints > 4) {
xOrigin = xOrigin + width + space;
if (value > 4) {
u8g2.drawBox(xOrigin, yOrigin, width, height); //x, y, width, height
} else {
u8g2.drawFrame(xOrigin, yOrigin, width, height); //x, y, width, height
}
}
}