Warning message if no pin is set, disabled back button on node selection, reset selected item on main menu, online indicator when listing machines

main
xad1 3 years ago
parent 8abbd54afd
commit 400c838d1c

@ -4,6 +4,7 @@
#define SERVER_H_ #define SERVER_H_
/** /**
* Enter WiFi network and Proxmox information * Enter WiFi network and Proxmox information
*
*/ */
const String PROXMOX_ADDRESS = ""; const String PROXMOX_ADDRESS = "";

@ -6,5 +6,4 @@ void displayError(String message);
void connectWiFi(); void connectWiFi();
bool enterPin(); bool enterPin();
int pinListener(); int pinListener();
#endif /* UTILS_H */ #endif /* UTILS_H */

@ -6,7 +6,7 @@
#include <utils.h> #include <utils.h>
#include <menu.h> #include <menu.h>
#include <json/retrieve.h> #include <json/retrieve.h>
#include <pin.h>
void loop() void loop()
{ {
@ -38,11 +38,17 @@ void setup()
Serial.begin(115200); Serial.begin(115200);
GO.begin(); GO.begin();
GO.lcd.setTextWrap(false); GO.lcd.setTextWrap(false);
bool pinCorrect = false; if (LOCK_PIN != "")
while (!pinCorrect) { {
pinCorrect = enterPin(); bool pinCorrect = false;
while (!pinCorrect)
{
pinCorrect = enterPin();
}
} else {
displayError("Warning: No pin set");
} }
connectWiFi(); connectWiFi();
Serial.println("done setup"); Serial.println("done setup");
} }

@ -10,42 +10,41 @@ void vmRestart()
{ {
Serial.println("vm restart"); Serial.println("vm restart");
selectedItem = 0; selectedItem = 0;
selectedVM = 0;
int numVMs; int numVMs;
VM *vms = getVMInfo(&numVMs, selectedNode); VM *vms = getVMInfo(&numVMs, selectedNode);
if (vms != NULL) listVMs(vms, numVMs);
delete[] vms;
if (selectedVM > 0)
{ {
listVMs(vms, numVMs);
delete[] vms;
restartVM(selectedNode, selectedVM); restartVM(selectedNode, selectedVM);
GO.lcd.clearDisplay(); GO.lcd.clearDisplay();
GO.lcd.setCursor(0, 0); GO.lcd.setCursor(0, 0);
GO.lcd.println("done"); GO.lcd.println("done");
delay(2000); delay(2000);
manageVMMenu();
} }
manageVMMenu();
} }
void containerRestart() void containerRestart()
{ {
Serial.println("lxc restart"); Serial.println("lxc restart");
selectedItem = 0; selectedItem = 0;
selectedLXC = 0;
int numContainers; int numContainers;
Container *containers = getContainerInfo(&numContainers, selectedNode); Container *containers = getContainerInfo(&numContainers, selectedNode);
if (containers != NULL) listContainers(containers, numContainers);
delete[] containers;
if (selectedLXC > 0)
{ {
listContainers(containers, numContainers);
delete[] containers;
restartContainer(selectedNode, selectedLXC); restartContainer(selectedNode, selectedLXC);
GO.lcd.clearDisplay(); GO.lcd.clearDisplay();
GO.lcd.setCursor(0, 0); GO.lcd.setCursor(0, 0);
GO.lcd.println("done"); GO.lcd.println("done");
delay(2000); delay(2000);
manageContainerMenu();
} }
manageContainerMenu();
} }
@ -53,11 +52,14 @@ void vmStart()
{ {
Serial.println("vm start"); Serial.println("vm start");
selectedItem = 0; selectedItem = 0;
selectedVM = 0;
int numVMs; int numVMs;
VM *vms = getVMInfo(&numVMs, selectedNode); VM *vms = getVMInfo(&numVMs, selectedNode);
if (vms != NULL) listVMs(vms, numVMs);
delete[] vms;
if (selectedVM > 0)
{ {
listVMs(vms, numVMs);
startVM(selectedNode, selectedVM); startVM(selectedNode, selectedVM);
@ -66,35 +68,41 @@ void vmStart()
delay(2000); delay(2000);
} }
manageVMMenu();
} }
void containerStart() void containerStart()
{ {
Serial.println("lxc start"); Serial.println("lxc start");
selectedItem = 0; selectedItem = 0;
selectedLXC = 0;
int numContainers; int numContainers;
Container *containers = getContainerInfo(&numContainers, selectedNode); Container *containers = getContainerInfo(&numContainers, selectedNode);
if (containers != NULL) listContainers(containers, numContainers);
delete[] containers;
if (selectedLXC > 0)
{ {
listContainers(containers, numContainers);
startContainer(selectedNode, selectedLXC); startContainer(selectedNode, selectedLXC);
GO.lcd.clearDisplay(); GO.lcd.clearDisplay();
GO.lcd.println("done"); GO.lcd.println("done");
delay(2000); delay(2000);
} }
manageContainerMenu();
} }
void vmStop() void vmStop()
{ {
Serial.println("vm stop"); Serial.println("vm stop");
selectedItem = 0; selectedItem = 0;
selectedVM = 0;
int numVMs; int numVMs;
VM *vms = getVMInfo(&numVMs, selectedNode); VM *vms = getVMInfo(&numVMs, selectedNode);
if (vms != NULL) listVMs(vms, numVMs);
delete[] vms;
if (selectedVM > 0)
{ {
listVMs(vms, numVMs);
stopVM(selectedNode, selectedVM); stopVM(selectedNode, selectedVM);
@ -103,22 +111,25 @@ void vmStop()
delay(2000); delay(2000);
} }
manageVMMenu();
} }
void containerStop() void containerStop()
{ {
Serial.println("lxc stop"); Serial.println("lxc stop");
selectedItem = 0; selectedItem = 0;
selectedLXC = 0;
int numContainers; int numContainers;
Container *containers = getContainerInfo(&numContainers, selectedNode); Container *containers = getContainerInfo(&numContainers, selectedNode);
if (containers != NULL) listContainers(containers, numContainers);
delete[] containers;
if (selectedLXC > 0)
{ {
listContainers(containers, numContainers);
stopContainer(selectedNode, selectedLXC); stopContainer(selectedNode, selectedLXC);
GO.lcd.clearDisplay(); GO.lcd.clearDisplay();
GO.lcd.println("done"); GO.lcd.println("done");
delay(2000); delay(2000);
} }
manageContainerMenu();
} }

@ -6,9 +6,12 @@
#include <global.h> #include <global.h>
#include <manage.h> #include <manage.h>
const int MAIN_TEXT_COLOR = WHITE; const int MAIN_TEXT_COLOR = WHITE;
const int MAIN_TEXT_SIZE = 2; const int MAIN_TEXT_SIZE = 2;
const int ITEMS_PER_PAGE = 12; const int ITEMS_PER_PAGE = 12;
const int OFFLINE_COLOR = RED;
const int ONLINE_COLOR = GREEN;
int selectedItem = 0; int selectedItem = 0;
int selectedPage = 0; int selectedPage = 0;
@ -123,6 +126,7 @@ void drawMenu(MenuItem menuItems[], int numItems, String menuTitle)
void mainMenu() void mainMenu()
{ {
selectedItem = 0;
int numItems = sizeof(mainMenuItems) / sizeof(MenuItem); int numItems = sizeof(mainMenuItems) / sizeof(MenuItem);
drawMenu(mainMenuItems, numItems, "Main Menu"); drawMenu(mainMenuItems, numItems, "Main Menu");
} }
@ -155,23 +159,25 @@ void listNodes(Node *nodes, int numItems)
for (int i = selectedPage * ITEMS_PER_PAGE; i < numItems && i < (selectedPage + 1) * ITEMS_PER_PAGE; i++) for (int i = selectedPage * ITEMS_PER_PAGE; i < numItems && i < (selectedPage + 1) * ITEMS_PER_PAGE; i++)
{ {
Serial.println("running loop");
if (selectedItem == i) if (selectedItem == i)
{ {
GO.lcd.print("> "); GO.lcd.print("> ");
} }
if (nodes[i].onlineStatus == "online") {
GO.lcd.setTextColor(ONLINE_COLOR);
} else {
GO.lcd.setTextColor(OFFLINE_COLOR);
}
GO.lcd.print("O");
GO.lcd.setTextColor(MAIN_TEXT_COLOR);
GO.lcd.println(nodes[i].name); GO.lcd.println(nodes[i].name);
} }
Serial.println("completed loop");
switch (buttonListener(numItems)) switch (buttonListener(numItems))
{ {
case 1: case 1:
Serial.println("selected " + selectedItem); Serial.println("selected " + selectedItem);
selectedNode = nodes[selectedItem].name; selectedNode = nodes[selectedItem].name;
break; break;
case 2:
Serial.println("back");
break;
default: default:
listNodes(nodes, numItems); listNodes(nodes, numItems);
break; break;
@ -193,6 +199,13 @@ void listContainers(Container *containers, int numItems)
{ {
GO.lcd.print("> "); GO.lcd.print("> ");
} }
if (containers[i].onlineStatus == "running") {
GO.lcd.setTextColor(ONLINE_COLOR);
} else {
GO.lcd.setTextColor(OFFLINE_COLOR);
}
GO.lcd.print("O");
GO.lcd.setTextColor(MAIN_TEXT_COLOR);
GO.lcd.println(String(containers[i].id) + ": " + containers[i].name); GO.lcd.println(String(containers[i].id) + ": " + containers[i].name);
} }
@ -225,6 +238,13 @@ void listVMs(VM *vms, int numItems)
{ {
GO.lcd.print("> "); GO.lcd.print("> ");
} }
if (vms[i].onlineStatus == "running") {
GO.lcd.setTextColor(ONLINE_COLOR);
} else {
GO.lcd.setTextColor(OFFLINE_COLOR);
}
GO.lcd.print("O");
GO.lcd.setTextColor(MAIN_TEXT_COLOR);
GO.lcd.println(String(vms[i].id) + ": " + vms[i].name); GO.lcd.println(String(vms[i].id) + ": " + vms[i].name);
} }

@ -9,28 +9,35 @@ const int BACKGROUND_COLOR = WHITE;
const int TEXT_COLOR = BLACK; const int TEXT_COLOR = BLACK;
const int TEXT_SIZE = 2; const int TEXT_SIZE = 2;
String convertBytes(long long value) { String convertBytes(long long value)
if (value > 1099511627776) { {
if (value > 1099511627776)
{
return String(value / 1099511627776) + " TB"; return String(value / 1099511627776) + " TB";
} }
if (value > 1073741824) { if (value > 1073741824)
{
return String(value / 1073741824) + " GB"; return String(value / 1073741824) + " GB";
} }
if (value > 1048576) { if (value > 1048576)
{
return String(value / 1048576) + " MB"; return String(value / 1048576) + " MB";
} }
if (value > 1024) { if (value > 1024)
{
return String(value / 1024) + " KB"; return String(value / 1024) + " KB";
} }
return String(value) + " Bytes"; return String(value) + " Bytes";
} }
String convertTime(long long value)
String convertTime(long long value) { {
if (value > 3600) { if (value > 3600)
{
return String(value / 3600) + " hrs"; return String(value / 3600) + " hrs";
} }
if (value > 60) { if (value > 60)
{
return String(value / 60) + " mins"; return String(value / 60) + " mins";
} }
return String(value) + " secs"; return String(value) + " secs";
@ -127,13 +134,15 @@ void nodeInfo()
int updateInterval = 3000; int updateInterval = 3000;
while (true) while (true)
{ {
if(lastUpdate + updateInterval < millis()) { if (lastUpdate + updateInterval < millis())
{
printNodeStats(getNode(selectedNode)); printNodeStats(getNode(selectedNode));
lastUpdate = millis(); lastUpdate = millis();
} }
GO.update(); GO.update();
if(GO.BtnB.isPressed()) { if (GO.BtnB.isPressed())
{
break; break;
} }
} }
@ -156,18 +165,19 @@ void containerInfo()
while (true) while (true)
{ {
if(lastUpdate + updateInterval < millis()) { if (lastUpdate + updateInterval < millis())
{
printContainerStats(getContainer(selectedLXC, selectedNode)); printContainerStats(getContainer(selectedLXC, selectedNode));
lastUpdate = millis(); lastUpdate = millis();
} }
GO.update(); GO.update();
if(GO.BtnB.isPressed()) { if (GO.BtnB.isPressed())
{
mainMenu(); mainMenu();
break; break;
} }
} }
} }
void vmInfo() void vmInfo()
@ -177,23 +187,22 @@ void vmInfo()
selectedPage = 0; selectedPage = 0;
int numVMs; int numVMs;
VM *vms = getVMInfo(&numVMs, selectedNode); VM *vms = getVMInfo(&numVMs, selectedNode);
if (vms != NULL) listVMs(vms, numVMs);
delete[] vms;
unsigned long lastUpdate = millis();
int updateInterval = 3000;
while (true)
{ {
listVMs(vms, numVMs); if (lastUpdate + updateInterval < millis())
delete[] vms;
unsigned long lastUpdate = millis();
int updateInterval = 3000;
while (true)
{ {
if(lastUpdate + updateInterval < millis()) { printVMStats(getVM(selectedVM, selectedNode));
printVMStats(getVM(selectedVM, selectedNode)); lastUpdate = millis();
lastUpdate = millis(); }
} GO.update();
GO.update(); if (GO.BtnB.isPressed())
if(GO.BtnB.isPressed()) { {
mainMenu(); mainMenu();
break; break;
}
} }
} }
} }
@ -205,19 +214,18 @@ void diskInfo()
selectedPage = 0; selectedPage = 0;
int numDisks; int numDisks;
Disk *disks = getDiskInfo(&numDisks, selectedNode); Disk *disks = getDiskInfo(&numDisks, selectedNode);
if (disks != NULL)
{
listDisks(disks, numDisks);
delete[] disks;
printDiskStats(getDisk(selectedDisk, selectedNode)); listDisks(disks, numDisks);
while (true) delete[] disks;
printDiskStats(getDisk(selectedDisk, selectedNode));
while (true)
{
GO.update();
if (GO.BtnB.isPressed())
{ {
GO.update(); mainMenu();
if(GO.BtnB.isPressed()) { break;
mainMenu();
break;
}
} }
} }
} }
@ -229,19 +237,18 @@ void poolInfo()
selectedPage = 0; selectedPage = 0;
int numPools; int numPools;
Pool *pools = getPoolInfo(&numPools, selectedNode); Pool *pools = getPoolInfo(&numPools, selectedNode);
if (pools != NULL)
{
listPools(pools, numPools);
delete[] pools;
printPoolStats(getPool(selectedPool, selectedNode)); listPools(pools, numPools);
while (true) delete[] pools;
printPoolStats(getPool(selectedPool, selectedNode));
while (true)
{
GO.update();
if (GO.BtnB.isPressed())
{ {
GO.update(); mainMenu();
if(GO.BtnB.isPressed()) { break;
mainMenu();
break;
}
} }
} }
} }

@ -2,6 +2,7 @@
#include <wifi_info.h> #include <wifi_info.h>
#include <WiFi.h> #include <WiFi.h>
#include <pin.h> #include <pin.h>
#include <json/retrieve.h>
/** /**
Display an error on the screen Display an error on the screen
*/ */
@ -18,6 +19,8 @@ void connectWiFi() {
WiFi.begin(WIFI_SSID, WIFI_PASS); WiFi.begin(WIFI_SSID, WIFI_PASS);
GO.lcd.clearDisplay(); GO.lcd.clearDisplay();
GO.lcd.setCursor(0, 0); GO.lcd.setCursor(0, 0);
GO.lcd.setTextColor(WHITE);
GO.lcd.setTextSize(2);
GO.lcd.print("Connecting"); GO.lcd.print("Connecting");
@ -26,7 +29,6 @@ void connectWiFi() {
Serial.print("."); Serial.print(".");
GO.lcd.print("."); GO.lcd.print(".");
} }
} }

Loading…
Cancel
Save