Compare commits

..

No commits in common. "2ccaff73e5266fcf92098fd683b62e64a888dd64" and "e4d93f6d5153dc74b87fd17ee79ecc060586a652" have entirely different histories.

7 changed files with 37 additions and 209 deletions

2
.gitignore vendored
View File

@ -1,3 +1 @@
display display
.gdb_history

View File

@ -14,8 +14,8 @@ copy the listen2P1AM.service to /etc/systemd/system/
run run
`sudo systemctl enable listen2P1AM.service` sudo systemctl enable listen2P1AM.service
`sudo systemctl start listen2P1AM.service` sudo systemctl start listen2P1AM.service
## interlock database at fsunuc.physics.fsu.edu ## interlock database at fsunuc.physics.fsu.edu

Binary file not shown.

Before

Width:  |  Height:  |  Size: 663 KiB

View File

@ -1,17 +0,0 @@
# Compiler
CXX = g++
# Flags
CXXFLAGS = -Wall -Wextra -pedantic -std=c++11
# Libraries
LIBS = -lSDL2 -lSDL2_image -lSDL2_ttf
# Executable name
EXECUTABLE = display
all: $(EXECUTABLE)
$(EXECUTABLE): display.cpp
$(CXX) $(CXXFLAGS) -o $(EXECUTABLE) display.cpp $(LIBS)
clean:
rm -f $(EXECUTABLE)

View File

@ -1,9 +1,7 @@
# Intoduction The Status Display on Raspberry Pi use the SDL C++ library
The Status Display on Raspberry Pi use the SDL (Simple DirectMedia Layer) C++ library sudo apt-get install libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev
`sudo apt-get install libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev` To Compile
# To Compile g++ -o display display.cpp -lSDL2 -lSDL2_image -lSDL2_ttf
`make`

View File

@ -3,211 +3,60 @@
#include <SDL2/SDL_image.h> #include <SDL2/SDL_image.h>
#include <SDL2/SDL_ttf.h> #include <SDL2/SDL_ttf.h>
#include <string> #include <string>
#include <thread>
#include <chrono>
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
SDL_Window* window = nullptr;
SDL_Renderer* renderer = nullptr;
TTF_Font* font = nullptr;
SDL_Color blackColor = { 0, 0, 0, 255};
SDL_Color redColor = { 255, 0, 0, 255};
SDL_Color greenColor = { 0, 200, 0, 255};
SDL_Color blueColor = { 0, 0, 255, 255};
SDL_Texture* textTexture = nullptr;
void textDisplay(std::string text, int posX, int posY, SDL_Color color){
SDL_Surface* textSurface = TTF_RenderText_Solid(font, text.c_str(), color);
textTexture = SDL_CreateTextureFromSurface(renderer, textSurface);
SDL_Rect textRect = { posX, posY, textSurface->w, textSurface->h };
SDL_RenderCopy(renderer, textTexture, NULL, &textRect);
SDL_FreeSurface(textSurface);
SDL_DestroyTexture(textTexture);
}
int statusReading = 0;
double tritiumReading = 0;
double vaccumReading = 0;
double subPumpReading = 0;
bool preAccel = true;
bool valve1 = true;
bool valve2 = true;
bool hv = true;
bool boiler = true ;
bool ionizer = true ;
void readStatus(){
std::ifstream file("data.txt"); // Replace "your_file.txt" with your actual file path
if (!file.is_open()) {
std::cout << "Unable to open file" << std::endl;
return;
}
std::string line;
while (std::getline(file, line)) {
std::istringstream iss(line);
std::string key;
double value;
if (std::getline(iss, key, '=')) {
// Extract the key
std::string valueStr;
if (std::getline(iss, valueStr)) {
// Convert the value string to double
try {
value = std::stod(valueStr);
//std::cout << "Key: " << key << ", Value: " << value << std::endl;
// Use 'value' as needed
if( key == "State value" ) statusReading = value;
if( key == "Tritium value" ) tritiumReading = value;
if( key == "Vaccum value" ) vaccumReading = value;
if( key == "SubPump value" ) subPumpReading = value;
} catch (const std::invalid_argument& e) {
std::cout << "Invalid value format for key: " << key << std::endl;
}
}
}
}
file.close();
if( statusReading == 0 || statusReading == 1 ){ // startup or normal
preAccel = true;
valve1 = true;
valve2 = true;
hv = true;
boiler = true;
ionizer = true;
}
if( statusReading == 2 ){ // toruble1
preAccel = false;
hv = false;
}
if( statusReading == 3 ){ // toruble2
preAccel = false;
valve1 = false;
valve2 = false;
hv = false;
ionizer = false;
}
if( statusReading == 4 ){ // toruble3
preAccel = false;
valve1 = false;
valve2 = false;
hv = false;
boiler = false;
ionizer = false;
}
}
int main() { int main() {
SDL_Init(SDL_INIT_VIDEO); SDL_Init(SDL_INIT_VIDEO);
// Create a window // Create a window
window = SDL_CreateWindow("Tritium Source Status", SDL_Window* window = SDL_CreateWindow("Image with Text Overlay",
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
1577, 695, 0); 640, 480, 0);
// Create a renderer // Create a renderer
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
// Load an image
SDL_Surface* imageSurface = IMG_Load("image.png");
SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, imageSurface);
SDL_FreeSurface(imageSurface);
// Font initialization for rendering text // Font initialization for rendering text
TTF_Init(); TTF_Init();
font = TTF_OpenFont("/usr/share/fonts/truetype/freefont/FreeSerifBold.ttf", 24); TTF_Font* font = TTF_OpenFont("/usr/share/fonts/trutype/freefont/FreeMono.ttf", 24);
SDL_Color textColor = { 255, 255, 255 }; // White color
// Load an image SDL_Rect imageRect = { 0, 0, 640, 480 }; // Image position and size
SDL_Surface* imageSurface = IMG_Load("BG.png");
SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, imageSurface);
SDL_FreeSurface(imageSurface);
SDL_Rect imageRect = { 0, 0, 1577, 695 }; // Image position and size
SDL_Event event; SDL_Event event;
bool running = true; bool running = true;
int count = 0;
while (running) { while (running) {
while (SDL_PollEvent(&event)) { while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) { if (event.type == SDL_QUIT) {
running = false; running = false;
} }
} }
if( count == 0 ) readStatus(); // Clear the renderer
SDL_RenderClear(renderer);
count ++; // Render the image
if( count >= 5 ) count = 0; SDL_RenderCopy(renderer, texture, NULL, &imageRect);
// Clear the renderer // Render text
SDL_RenderClear(renderer); std::string textToRender = "Dynamic Number: 123"; // Replace with your dynamic number
SDL_Surface* textSurface = TTF_RenderText_Solid(font, textToRender.c_str(), textColor);
SDL_Texture* textTexture = SDL_CreateTextureFromSurface(renderer, textSurface);
// Render the image SDL_Rect textRect = { 50, 50, textSurface->w, textSurface->h }; // Position of text
SDL_RenderCopy(renderer, texture, NULL, &imageRect); SDL_RenderCopy(renderer, textTexture, NULL, &textRect);
{// Get current time SDL_FreeSurface(textSurface);
std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); SDL_DestroyTexture(textTexture);
std::time_t now_c = std::chrono::system_clock::to_time_t(now);
// Convert time to a string
std::string timeString = std::ctime(&now_c);
timeString.erase(timeString.length() - 1); //remove the '\n'
textDisplay(timeString, 10, 10, blackColor);
}
textDisplay( valve1 ? "Open" : "Close", 570, 455, valve1 ? greenColor : redColor); // GateValve-1
textDisplay( valve2 ? "Open" : "Close", 1270, 455, valve2 ? greenColor : redColor); // GateValve-2
textDisplay( "Pre-Accel. supply : ", 750, 455, blackColor); // pre-accel. supply text
textDisplay( preAccel ? "On" : "Off", 950, 455, preAccel ? greenColor : redColor); // pre-accel. supply text
textDisplay( "HV Supply : ", 30, 200, blackColor);
textDisplay( hv ? "On" : "Off", 230, 200, hv ? greenColor : redColor);
textDisplay( "Boiler Supply : ", 30, 240, blackColor);
textDisplay( boiler ? "On" : "Off", 230, 240, boiler ? greenColor : redColor);
textDisplay( "Ionizer Supply : ", 30, 280, blackColor);
textDisplay( ionizer ? "On" : "Off", 230, 280, ionizer ? greenColor : redColor);
switch (statusReading){
case 0: textDisplay( "Start-Up", 10, 40, blueColor); break;
case 1: textDisplay( "Normal", 10, 40, greenColor); break;
case 2: textDisplay( "Trouble-1", 10, 40, redColor); break;
case 3: textDisplay( "Trouble-2", 10, 40, redColor); break;
case 4: textDisplay( "Trouble-3", 10, 40, redColor); break;
}
textDisplay( "Tritium Sensor : " + std::to_string(tritiumReading) + " mCr", 720, 200, blueColor);
textDisplay( "Vaccum : " + std::to_string(vaccumReading) + " Torr", 630, 20, blueColor);
textDisplay( "SubPump : " + std::to_string(subPumpReading) + " Amp", 1020, 70, blueColor);
textDisplay("update every 5 sec.", 1200, 670, blackColor);
// Update the screen
SDL_RenderPresent(renderer);
std::this_thread::sleep_for(std::chrono::seconds(1));
// Update the screen
SDL_RenderPresent(renderer);
} }
// Clean up // Clean up

BIN
statusDisplay/image.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 194 KiB