Add Library

This commit is contained in:
Siwat Sirichai 2019-08-09 09:01:56 +07:00
parent e365b9dbd9
commit 3c47103b39
318 changed files with 56465 additions and 0 deletions

View file

@ -0,0 +1,116 @@
//This example acts like a websever. It can create an access point or join an existing WiFI network.
//All text that's entered in the served page will bis displayed on the connected VGA screen.
//You need to connect a VGA screen cable to the pins specified below.
//cc by-sa 4.0 license
//bitluni
#include <stdio.h>
#include <WiFi.h>
#include <WebServer.h>
//ESP32Lib headers
#include <ESP32Lib.h>
#include <Ressources/Font6x8.h>
//true: creates an access point, false: connects to an existing wifi
const bool AccessPointMode = true;
//wifi credentials (enter yours if you arne not using the AccessPointMode)
const char *ssid = "VGA";
const char *password = "";
//pin configuration, change if you need to
const int redPin = 14;
const int greenPin = 19;
const int bluePin = 27;
const int hsyncPin = 32;
const int vsyncPin = 33;
//the webserver at pot 80
WebServer server(80);
//The VGA Device
VGA3Bit vga;
//include html page
const char *page =
#include "page.h"
;
///Html page is sent on root
void sendPage()
{
server.send(200, "text/html", page);
}
///Received text will be displayed on the screen
void text()
{
server.send(200, "text/plain", "ok");
vga.println(server.arg(0).c_str());
}
///initialization
void setup()
{
Serial.begin(115200);
//Handle the WiFi AP or STA mode and display results on the screen
if (AccessPointMode)
{
Serial.println("Creating access point...");
WiFi.softAP(ssid, password, 6, 0);
}
else
{
Serial.print("Connecting to SSID ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
vga.print(".");
}
}
//start vga on the specified pins
vga.init(vga.MODE400x300, redPin, greenPin, bluePin, hsyncPin, vsyncPin);
//make the background blue
vga.clear(vga.RGBA(0, 0, 255));
vga.backColor = vga.RGB(0, 0, 255);
//select the font
vga.setFont(Font6x8);
//send page on http://<ip>/
server.on("/", sendPage);
//receive text on http://<ip>/text
server.on("/text", text);
//start the server
server.begin();
//display some text header on the screen including the ip
vga.clear(vga.RGBA(0, 0, 255));
vga.setCursor(0, 0);
vga.println("----------------------");
vga.println("bitluni's VGA Terminal");
if (AccessPointMode)
{
vga.print("SSID: ");
vga.println(ssid);
if (strlen(password))
{
vga.print("password: ");
vga.println(password);
}
vga.println("http://192.168.4.1");
}
else
{
vga.print("http://");
vga.println(WiFi.localIP().toString().c_str());
}
vga.println("----------------------");
}
void loop()
{
//process the server stuff
server.handleClient();
delay(10);
}

View file

@ -0,0 +1,92 @@
R"(
<html>
<head>
<title>bitluni's VGA text terminal</title>
<script>
function load() {
document.querySelector('#in').focus();
}
function send() {
var e = document.querySelector('#in');
var xhr = new XMLHttpRequest();
xhr.open('POST', '/text');
xhr.send(e.value);
document.querySelector("#log").innerHTML = e.value + "\n" + document.querySelector("#log").innerHTML;
e.value = '';
}
</script>
<style>
h1
{
color: white;
background: #800000;
padding: 10px;
border-radius: 5px;
margin-bottom: 5px;
}
body
{
font-family: monospace;
padding: 0;
}
input, textarea, button
{
border-style: solid;
border-radius: 3px;
}
td
{
width: auto;
}
td.min
{
width: 1%;
}
#in{
margin-bottom: 10px;
width: 100%;
}
#send{
margin-bottom: 10px;
}
#log
{
resize: vertical;
height: 200px;
width: 100%
}
#area
{
margin-top: 100px;
height: 500px;
}
table
{
width: 100%;
}
</style>
</head>
<body onload='load()'>
<h1>bitluni's VGA text terminal</h1>
<table>
<tr>
<td><input id='in' type='text' tabindex=1 onchange='send()' autocomplete='off'></td>
<td class='min'><button id='send' onclick='send()'>send</button></td>
</tr>
<tr>
<td colspan=2>
<textarea id='log' readonly>
</textarea>
</td>
</tr>
</table>
</body>
</html>
)"