New website branch

previous was doomed, that is why I made a new brench that was updated with the main.
This commit is contained in:
TeunBugwood
2023-12-11 13:20:19 +01:00
parent c4b21ee3b3
commit ec09cb9625
23 changed files with 252532 additions and 42896 deletions

BIN
llfs-data/base.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

BIN
llfs-data/clap.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

BIN
llfs-data/dafoe.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.3 KiB

BIN
llfs-data/fellowkids.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

BIN
llfs-data/goose.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 117 KiB

122
llfs-data/index.css Normal file
View File

@@ -0,0 +1,122 @@
body{
font-family:Arial;
}
h1{
font-size: 175%;
padding: 10px;
margin: 10px;
}
h2 {
font-size: 150%;
padding: 8px;
position: absolute;
top: -6px;
left: 20px;
background-color:orangered;
color: white;
border-radius: 20px;
padding-left: 30px;
padding-right: 30px;
}
h3 {
font-size: 125%;
padding: 10px;
margin: 10px;
}
p {
padding: 10px;
margin: 10px;
}
header {
padding: 30px;
background-color: orangered;
}
header:after {
content:"";
display: block;
clear: both;
}
.logo{
width:100px;
transform:rotate(-10deg);
-moz-transform:rotate(-10deg);
-webkit-transform:rotate(-10deg);
-o-transform:rotate(-10deg);
float:left;
}
.title{
color: white;
font-size: 40px;
font: 60px "Lucida Sans Unicode", "Lucida Grande", sans-serif;
text-align: center;
padding-top: 10px;
}
.column {
flex-grow: 0;
flex-basis: 48%;
position: relative;
}
.right {
margin-left: 2%;
}
.content {
padding: 20px;
display: flex;
}
/*Geef vorm aan de vakjes op de site*/
.card {
background-color: white;
border-radius:10px;
padding:1%;
border: 1px solid black;
margin: 2% 0;
width: 100%;
padding-top: 30px;
}
.image {
width: 25%;
height: auto;
border: 10px solid transparent;
}
.image:hover {
border: 10px solid lightsalmon;
border-radius: 10px;
}
#selected {
border: 10px solid lightsalmon;
border-radius: 10px;
}
.sendButton {
position: absolute;
margin-top: 8%;
text-align: center;
margin-left: 40%;
font-size: 150%;
padding: 20px;
background-color:orangered;
color: white;
border-radius: 20px;
}
.sendButton:hover {
background-color:white;
color: orangered ;
}
/*---------------------------------------------------------------------------------------*/
footer {
background-color: orangered;
padding: 20px;
text-align: center;
border-top:20px solid lightskyblue; /*solid is vast*/
border-bottom:20px solid lightskyblue;
margin-top: 20px;
}
.foot {
color: white;
}
html{
background-color: white;
}
#myImg {
border: none;
transition: border 0.3s;
}

133
llfs-data/index.html Normal file
View File

@@ -0,0 +1,133 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Webservices & Applications</title>
<link href="reset.css" rel="stylesheet" />
<link href="index.css" rel="stylesheet" />
</head>
<body>
<div>
<header>
<img class="logo" src="st.bmp" alt="STM"/>
<p class="title">
Webservices & Applications
</p>
</header>
<form action="cgi">
<div class="content row">
<div class="column left">
<div class="card">
<h2>Adjustments</h2>
<label for="send_text">Text LCD:</label>
<input type="text" id="send_text" name="vtxt"><br><br>
<label for="send_colorTxt">Select the text color:</label>
<input type="color" id="send_colorTxt" name="vktxt" value="#0000ff"><br><br>
<label for="send_colorBack">Select the background color:</label>
<input type="color" id="send_colorBack" name="vka" value="#0000ff"><br><br>
<!--<span class="sendButton" onClick="start();">
<input type="submit" value="Send">
</span>-->
<input type="submit" value="Send" class="sendButton" onClick="start();">
</div>
</div>
<div class="column right">
<div class="card">
<h2 >Images</h2>
<label for="vfo">Choose your photo:</label>
<div class="gallery" id="gallery">
<input type="hidden" id="gallery1" name="vfo" value="">
</div>
</div>
</div>
</div>
</form>
<script>
document.getElementById('send_colorBack').addEventListener('input', function() { document.body.style.backgroundColor = this.value; });
document.getElementById('send_colorTxt').addEventListener('input', function() { document.getElementById('send_text').style.color = this.value; });
/*--------------------------------------------------------------*/
// Function to load images from the folder
function loadImages() {
console.log("loadImages");
const xhttp = new XMLHttpRequest();
xhttp.onload = function() {
const imageContainer = document.getElementById('gallery');
console.log(this.responseText);
images = this.responseText.split('|');
console.log(images);
for (let i = 0; i < images.length; i++) {
console.log(images[i]);
const img = document.createElement('img');;
img.src= images[i];
img.alt = images[i];
img.className = `image ${i}`;
img.value = images[i];
img.onload = () => {
imageContainer.appendChild(img);
}
img.onclick = () => {
selecteerFoto(img, i, images[i]);
}
}
}
xhttp.open("GET", "images.info");
xhttp.send();
}
function selecteerFoto(image, i, images) {
var gallery = document.getElementById('gallery1');
var value = gallery.getAttribute('value');
var Pictures = document.querySelectorAll('.gallery img');
Pictures.forEach(function(image) {
image.removeAttribute('id');
image.removeAttribute('name');
});
image.id = "selected";
image.name = "vfo";
image.value = images[i];
gallery.setAttribute('value', images);
}
// Call the function to load the images
loadImages();
const xhr = new XMLHttpRequest();
function start() {
var send_text = document.getElementById("send_text").value;
var send_colorTxt = document.getElementById("send_colorTxt").value;
var send_colorBack = document.getElementById("send_colorBack").value;
var sendPicture = document.getElementById("selected").alt;
var url = "cgi?";
var queryString = url + "vtxt=" + send_text + "&vktxt=" + encodeURIComponent(send_colorTxt) + "&vka=" + encodeURIComponent(send_colorBack) + "&vfo=" + sendPicture;
console.log(queryString);
xhr.onreadystatechange = showAnswer;
xhr.open("GET", queryString);
xhr.send();
}
function showAnswer() {
if (xhr.readyState == 4 && xhr.status == 200) {
alert(xhr.responseText);
}
}
</script>
<footer>
<p class="foot">
Copyright &copy; Thomas More Mechelen-Antwerpen vzw -
Campus De Nayer - Professionele bachelor elektronica-ict
2023
</p>
</footer>
</div>
</body>
</html>

BIN
llfs-data/mind.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 522 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 66 KiB

62
llfs-data/reset.css Normal file
View File

@@ -0,0 +1,62 @@
/* http://meyerweb.com/eric/tools/css/reset/
v2.0b1 | 201101
NOTE: WORK IN PROGRESS
USE WITH CAUTION AND TEST WITH ABANDON */
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, figcaption, figure,
footer, header, hgroup, menu, nav, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
outline: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
/* remember to define visible focus styles!
:focus {
outline: ?????;
} */
/* remember to highlight inserts somehow! */
ins {
text-decoration: none;
}
del {
text-decoration: line-through;
}
table {
border-collapse: collapse;
border-spacing: 0;
}

View File

@@ -1 +0,0 @@
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer penatibus lorem nunc semper venenatis vestibulum urna. Hac elit inceptos mattis integer sollicitudin pellentesque parturient. Est fermentum laoreet class egestas odio tellus condimentum.

View File

@@ -1 +0,0 @@
Aliquet pellentesque morbi fermentum dolor fermentum auctor lacinia. Montes euismod habitasse fringilla praesent sodales metus interdum. Lacinia vel duis cum auctor class commodo adipiscing. Elementum condimentum taciti iaculis metus ornare duis curae. Risus consectetur urna convallis metus fusce arcu class. Nisl himenaeos vel praesent laoreet taciti himenaeos lacus. Duis pharetra aptent phasellus sodales imperdiet aptent elit.

BIN
llfs-data/webp.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 KiB

View File

@@ -0,0 +1,89 @@
/**
* @file website_backend.h
* @brief Backend for the website to operate
* @author Toon B.
*/
#ifndef INC_WEBSITE_BACKEND_
#define INC_WEBSITE_BACKEND_
/* Include headers C lib */
#include <string.h>
#include <stdint.h>
/* Defines */
#define LOGGER_LEVEL_ALL
#define STR_MAX 200
#define CLR_MAX 11
#define IMG_X 250
#define IMG_Y 50
#define SD_IMG "st.bmp"
/* Include headers */
#include "log.h"
#include "lwip.h"
#include "httpd.h"
#include "lwip/apps/fs.h"
#include "llfs.h"
#include "lcd_api.h"
/**
* @fn void wbe_init(void)
* @brief Initialise the http server. It also sets the beginning screen
* of the display.
*/
void wbe_init(void);
/**
* @fn int fs_open_custom(struct fs_file*, const char*)
* @brief Function is called when the frontend wants to reach/open a file
* or endpoint on the backend.
*
* @param[in] file, the file pointer of the file that the frontend wants
* @param[in] name, the name of the file or endpoint that the frontend asks for
* @return[out] returns 0 if file or endpoint was not found, 1 if it was found
*/
int fs_open_custom(struct fs_file* file, const char* name);
/**
* @fn void fs_close_custom(struct fs_file*)
* @brief Called when closing files and endpoints
*
* @param[in] file, the file pointer of the file that the frontend wants
*/
void fs_close_custom(struct fs_file* file);
/**
* @fn void httpd_cgi_handler(struct fs_file*, const char*, int, char**, char**)
* @brief When data is send from the frontend to the backend with the CGI
* tag and parameters, this function is called. With this comes parameters that
* we want to read for further use.
*
* @param[in] file, the file pointer of the file that the frontend wants
* @param[in] uri, the URI that is given to the backend from the frontend (here cgi)
* @param[in] num_parm, the number of parameters that is given with the URI
* @param[in] pc_param, contains the name of each parameter
* @param[in] pc_value, is the value of each parameter
*/
void httpd_cgi_handler(struct fs_file* file, const char* uri, int num_parm, char** pc_param, char** pc_value );
/**
* @fn void wbe_display(const char*, const uint32_t, const uint32_t, const char*)
* @brief Function displays the sentence, its color, the background and the given
* image on the LCD screen.
*
* @param[in] txt, is the text string that needs to be displayed
* @param[in] txt_color, the color of the wanted string
* @param[in] background_color, color of the background of the screen
* @param[in] image, name of the wanted image to be displayed
*/
void wbe_display(const char* txt, const uint32_t txt_color, const uint32_t background_color, const char* image);
#endif /* INC_WEBSITE_BACKEND_ */

File diff suppressed because it is too large Load Diff

View File

@@ -33,6 +33,7 @@
#include "modbus_tcp.h"
#include "UDP_broadcast.h"
#include "tcp_cmd.h"
#include "website_backend.h"
/* USER CODE END Includes */
@@ -155,6 +156,9 @@ int main(void)
LOG_WARN(TAG,"error setting owner's details");
}
/* Initialize website backend */
wbe_init();
/* USER CODE END 2 */
/* Infinite loop */

View File

@@ -0,0 +1,350 @@
/**
* @file website_backend.h
* @brief Backend for the website to operate
* @author Toon B.
*/
// Includes
#include "website_backend.h"
// Static functions
static size_t wbe_get_images(char* images_string, size_t file_count_fs);
static inline void wbe_build_infostring(const llfs_file_t* file_list, char* info_string, const size_t cnt);
static void wbe_decoding_url(const char* encoded, char* decoded);
static uint32_t wbe_color_value(const char* rgb);
void wbe_init(void) {
httpd_init();
LOG_DEBUG("WBE", "Initialize webserver");
// Set starting LCD screen
wbe_display("Please Edit Me !", LCD_GREEN, LCD_BLACK, SD_IMG);
return;
}
int fs_open_custom(struct fs_file* file, const char* name) {
// Variables
llfs_file_t* wanted_file = llfs_file_open(name + 1);
size_t buffer_len = 0;
static char image_stringbuffer[STR_MAX] = "";
// The wanted file was found in the filesystem
if (wanted_file != NULL) {
// Debug info
LOG_DEBUG("WBE", "The file : %s was found", wanted_file->name);
// Give the information about the file to the client
file->data = (const char*)wanted_file->data;
file->len = (int)wanted_file->len;
file->index = (int)wanted_file->len;
file->is_custom_file = 1;
file->pextension = NULL;
file->flags = FS_FILE_FLAGS_HEADER_INCLUDED;
return 1;
}
/*
* The endpoint '/images.info' is called when the client wants to call for the
* information string that contains the names of the available images.
*/
if (strncmp(name, "/images.info", strlen("/images.info")) == 0) {
// Create the information string for the images in the filesystem
buffer_len = wbe_get_images(image_stringbuffer, llfs_file_count());
// Give the string back to the client
file->data = image_stringbuffer;
file->len = (int)buffer_len;
file->index = (int)buffer_len;
file->is_custom_file = 1;
file->pextension = NULL;
file->flags = FS_FILE_FLAGS_HEADER_INCLUDED;
return 1;
}
// Endpoint when client wants to send information to the backend
if (strncmp(name, "/cgi", 3) == 0) {
// Give the original index.html back to the client
wanted_file = llfs_file_open("index.html");
if (wanted_file != NULL) {
file->data = (const char*)wanted_file->data;
file->len = (int)wanted_file->len;
file->index = (int)wanted_file->len;
file->is_custom_file = 1;
file->pextension = NULL;
file->flags = FS_FILE_FLAGS_HEADER_INCLUDED;
return 1;
}
}
return 0;
}
void fs_close_custom(struct fs_file* file) {
}
/**
* @fn void wbe_get_images(char*, size_t)
* @brief Function searches filesystem for files with extention ".bmp" and ".gif" and put them
* combined in a string that needs to be send to the frontend.
*
* @param[in] images_string, string that will contain the image names
* @param[in] file_count_fs, the number of files in the filesystem
*/
static size_t wbe_get_images(char* images_string, size_t file_count_fs) {
// Allocate space for the files
llfs_file_t file_list[file_count_fs];
size_t file_count_bmp = 0;
size_t file_count_gif = 0;
// Reset string
strcpy(images_string, "");
// Get all the ".bmp" and ".gif" files
file_count_bmp = llfs_file_list(file_list, file_count_fs, ".bmp");
file_count_gif = llfs_file_list(file_list + file_count_bmp, file_count_fs, ".gif");
// Create the info string
wbe_build_infostring(file_list, images_string, file_count_gif + file_count_bmp);
// Debug info
LOG_DEBUG("WBE", "Images string : %s ",images_string);
// Return the length of the string
return strlen(images_string);
}
/**
* @fn void wbe_build_infostring(const llfs_file_t*, char*, const size_t)
* @brief Function adds the names of the files in "file_list" and adds them in "infoStr".
* The names are seperated by '|' characters.
*
* @param[in] file_list, list with files
* @param[in] info_string, string that will contain the filenames
* @param[in] cnt, the number of files
*/
static inline void wbe_build_infostring(const llfs_file_t* file_list, char* info_string, const size_t cnt) {
// Add the filenames to the info string
for (size_t i = 0; i < cnt; ++i) {
strncat(info_string, file_list[i].name, strlen(file_list[i].name));
strncat(info_string, "|", 2);
}
//Remove last seperator '|'
info_string[strlen(info_string) - 1] = '\0';
}
void httpd_cgi_handler(struct fs_file* file, const char* uri, int num_parm, char** pc_param, char** pc_value) {
// Variables
uint32_t vktxt = LCD_GREEN;
uint32_t vka = LCD_BLACK;
// Allocate space for parameters
char vtxt[STR_MAX]; // The sentence that we want to print on the LCD.
char vfo[STR_MAX]; // Name of the selected image on the website.
char s_vktxt[CLR_MAX]; // The color of the sentence. (in #RGB)
char s_vka[CLR_MAX]; // Color of the background. (also in #RGB)
if (strcmp("/cgi", uri) == 0) {
for (size_t i = 0; i < num_parm; ++i) {
// The given sentence
if (strcmp("vtxt", pc_param[i]) == 0) {
LOG_DEBUG("WBE", "--> %s", pc_value[i]);
wbe_decoding_url(pc_value[i], vtxt);
}
// The color of the sentence
if (strcmp("vktxt", pc_param[i]) == 0) {
wbe_decoding_url(pc_value[i], s_vktxt);
// Convert to hex value
if (s_vktxt != NULL) {
vktxt = wbe_color_value(s_vktxt);
}
}
// Color of the background
if (strcmp("vka", pc_param[i]) == 0) {
wbe_decoding_url(pc_value[i], s_vka);
// convert to hex value
if (s_vka != NULL) {
vka = wbe_color_value(s_vka);
}
}
// Name of the image
if (strcmp("vfo", pc_param[i]) == 0) {
wbe_decoding_url(pc_value[i], vfo);
}
}
// Debug info
LOG_DEBUG("WBE", "CGI DATA : %s , %x , %x , %s", vtxt, vktxt, vka, vfo);
// Display on LCD
wbe_display(vtxt, vktxt, vka, vfo);
}
}
/**
* @fn void wbe_decoding_url(const char*, char*)
* @brief The given information from the CGI parameters are URL encoded.
* This function translates this encoded string in a readable
* decoded string. The lengthe of "char* decoded" is at least the
* length of "char* encoded" + 1.
*
* @param[in] encoded, the encoded URL string that needs to be decoded
* @param[in] decoded, string that will contain the decoded URL.
*/
static void wbe_decoding_url(const char* encoded, char* decoded) {
// Variables
char* endptr;
size_t decoded_index = 0;
size_t encoded_length = strlen(encoded);
uint32_t hex_val;
for (size_t i = 0; i < encoded_length; ++i) {
// If we encounter a %xx, decode it to ascii
if ((encoded[i] == '%') && (i + 2 < encoded_length)) {
/*
// Decode %xx
hex_val = (uint32_t)strtoul(&encoded[i + 1], &endptr, 16);
// Check for conversion errors
if (endptr == &encoded[i + 1] || *endptr != '\0') {
strcpy(decoded, "");
LOG_DEBUG("WBE", "URL text conversion error");
//return;
}
decoded[decoded_index++] = (char)hex_val;
*/
// Decode %xx
sscanf(&encoded[i + 1], "%2x", &hex_val);
decoded[decoded_index++] = (char)hex_val;
// Skip 2 characters
i += 2;
// If we encounter a +, add a space character
} else if (encoded[i] == '+') {
decoded[decoded_index++] = ' ';
// If no % or +, just put what stands in 'encoded'
} else {
decoded[decoded_index++] = encoded[i];
}
}
// Finish the string
decoded[decoded_index] = '\0';
}
static uint32_t wbe_color_value(const char* rgb) {
// Variables
char* endptr;
uint32_t color = LCD_BLACK;
char argb[11] = "0xff";
// Create argb string (also, skip the '#' char)
strncat(argb, rgb + 1, strlen(rgb + 1));
// Get argb value
color = (uint32_t)strtoul(argb, &endptr, 16);
// Check for conversion errors
if (*endptr != '\0') {
color = LCD_BLACK;
LOG_DEBUG("WBE", "URL color conversion error");
}
return color;
}
void wbe_display(const char* txt, const uint32_t txt_color, const uint32_t bg_color, const char* image) {
// Variables
lcd_gif_t* gif;
char* extension;
// clear the screen
lcd_clear_text();
lcd_clear_images();
// Display the text and the background
lcd_set_bg_color_layer0(bg_color);
lcd_display_text(txt, 10, 10, txt_color, bg_color, LCD_FONT16);
// Get the extension of the file
extension = llfs_get_filename_ext(image);
// Check extension
if (extension != NULL) {
// Draw bmp
if (strcmp(extension, "bmp") == 0) {
lcd_draw_img_from_fs(image, IMG_X, IMG_Y);
// Draw gif
} else if (strcmp(extension, "gif") == 0) {
gif = lcd_draw_gif_from_fs(image, IMG_X, IMG_Y);
if (gif == NULL) {
LOG_DEBUG("WBE", "GIF could not be drawn");
}
// If nothing, then draw the standard image
} else {
lcd_draw_img_from_fs(SD_IMG, IMG_X, IMG_Y);
}
// If nothing, then draw the standard image
} else {
lcd_draw_img_from_fs(SD_IMG, IMG_X, IMG_Y);
}
}