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_
/**
* Enter WiFi network and Proxmox information
*
*/
const String PROXMOX_ADDRESS = "";

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

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

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

@ -6,9 +6,12 @@
#include <global.h>
#include <manage.h>
const int MAIN_TEXT_COLOR = WHITE;
const int MAIN_TEXT_SIZE = 2;
const int ITEMS_PER_PAGE = 12;
const int OFFLINE_COLOR = RED;
const int ONLINE_COLOR = GREEN;
int selectedItem = 0;
int selectedPage = 0;
@ -123,6 +126,7 @@ void drawMenu(MenuItem menuItems[], int numItems, String menuTitle)
void mainMenu()
{
selectedItem = 0;
int numItems = sizeof(mainMenuItems) / sizeof(MenuItem);
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++)
{
Serial.println("running loop");
if (selectedItem == i)
{
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);
}
Serial.println("completed loop");
switch (buttonListener(numItems))
{
case 1:
Serial.println("selected " + selectedItem);
selectedNode = nodes[selectedItem].name;
break;
case 2:
Serial.println("back");
break;
default:
listNodes(nodes, numItems);
break;
@ -193,6 +199,13 @@ void listContainers(Container *containers, int numItems)
{
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);
}
@ -225,6 +238,13 @@ void listVMs(VM *vms, int numItems)
{
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);
}

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

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

Loading…
Cancel
Save