Skip to content

Commit

Permalink
added color calculation functions and a new 14bit example
Browse files Browse the repository at this point in the history
  • Loading branch information
bitluni committed Feb 8, 2019
1 parent 4871e26 commit 4123d2b
Show file tree
Hide file tree
Showing 10 changed files with 265 additions and 49 deletions.
5 changes: 5 additions & 0 deletions .vscode/arduino.json
@@ -0,0 +1,5 @@
{
"board": "esp8266:esp8266:huzzah",
"configuration": "xtal=80,vt=flash,exception=disabled,eesz=4M,ip=lm2f,dbg=Disabled,lvl=None____,wipe=none,baud=115200",
"port": "COM8"
}
14 changes: 14 additions & 0 deletions .vscode/c_cpp_properties.json
@@ -0,0 +1,14 @@
{
"configurations": [
{
"name": "Win32",
"includePath": [
"C:\\Users\\luni\\AppData\\Local\\Arduino15\\packages\\esp8266\\tools\\**",
"C:\\Users\\luni\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\2.5.0-beta3\\**"
],
"forcedInclude": [],
"intelliSenseMode": "msvc-x64"
}
],
"version": 4
}
50 changes: 50 additions & 0 deletions examples/VGADemo14Bit/VGADemo14Bit.ino
@@ -0,0 +1,50 @@
#include <ESP32Lib.h>
#include <math.h>

//pin configuration
const int redPins[] = {2, 4, 12, 13, 14};
const int greenPins[] = {15, 16, 17, 18, 19};
const int bluePins[] = {21, 22, 23, 27};
const int hsyncPin = 0;
const int vsyncPin = 5;

//VGA Device
VGA14Bit vga;

void setup()
{
//initializing i2s vga and frame buffers
vga.init(vga.MODE200x150, redPins, greenPins, bluePins, hsyncPin, vsyncPin);
}

int heat(VGA14Bit::Color c)
{
if (vga.B(c))
return vga.B(c) + 512;
if (vga.G(c))
return vga.G(c) + 256;
return vga.R(c);
}

VGA14Bit::Color color(int heat)
{
if (heat >= 512)
return vga.RGB(255, 255, heat - 512);
if (heat >= 256)
return vga.RGB(255, heat - 256, 0);
return vga.RGB(heat, 0, 0);
}

void loop()
{
float p = millis() * 0.001f;
vga.fillCircle(vga.xres / 2 + sin(p) * vga.xres / 3, vga.yres / 2 + cos(p * 1.34f) * vga.yres / 3, (rand() & 1) + 3, vga.RGB(255, 255, 255));
for (int y = 0; y < vga.yres - 1; y++)
for (int x = 1; x < vga.xres - 1; x++)
{
int h = (heat(vga.get(x, y)) + (heat(vga.get(x - 1, y + 1)) + heat(vga.get(x + 1, y + 1))) / 2 + heat(vga.get(x, y + 1))) / 3;
vga.dotFast(x, y, color(h));
}
for (int x = 0; x < vga.xres; x++)
vga.dotFast(x, vga.yres - 1, (rand() & 3 == 3) ? color(767) : 0);
}
43 changes: 36 additions & 7 deletions examples/WiFiTextToVGA/WiFiTextToVGA.ino
@@ -1,9 +1,10 @@
#include <stdio.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <WebServer.h>

//AP credentials
//true: creates an access point, false: connects to an existing wifi
const bool AccessPointMode = true;
//wifi credentials
const char *ssid = "VGA";
const char *password = "";

Expand Down Expand Up @@ -33,23 +34,51 @@ void sendPage()
void text()
{
server.send(200, "text/plain", "ok");
vga.println(server.args());
vga.println(server.arg(0).c_str());
}

void setup()
{
WiFi.softAP(ssid, password, 6, 0);
Serial.begin(115200);
if (AccessPointMode)
WiFi.softAP(ssid, password, 6, 0);
else
{
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
}
server.on("/", sendPage);
server.on("/text", text);
server.begin();

//initializing i2s vga and frame buffers
vga.init(vga.MODE360x400, redPin, greenPin, bluePin, hsyncPin, vsyncPin);
vga.clear();
vga.clear(4);
vga.backColor = 4;
vga.setFont(Font6x8);

vga.println("----------------------");
vga.println("bitluni's VGA Terminal");
vga.print("Try SSID: ");
vga.println(ssid);
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("----------------------");
}

Expand Down
127 changes: 88 additions & 39 deletions examples/WiFiTextToVGA/page.h
@@ -1,43 +1,92 @@
R"(
<html>

<head>
<title>bitluni's VGA text terminal</title>
<script>
function sendText()
{
var e = document.getElementById("text");
var xhr = new XMLHttpRequest();
xhr.open('POST', '/text');
xhr.send(e.value);
e.value = "";
}
<title>bitluni's VGA text terminal</title>
<script>
function load() {
document.querySelector('#in').focus();
}

</script>
<style>
.menu
{
background-color: #eeeeee;
padding: 1px;
display: block;
margin: 3px;
padding: 5px;
border-radius: 3px;
}
h2
{
color: white;
background: #800000;
padding: 10px;
border-radius: 5px;
margin-bottom: 5px;
}
</style>
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 style='font-family: arial'>
<h2>bitluni's VGA text terminal</h2>
<div>
<div class='menu'>
<input id='text' type='text' onchange='sendText()'>
</div>
</div>
</body></html>
)"

<body onload='load()'>
<h1>bitluni's VGA text terminal</h1>
<table>
<tr>
<td><input id='in' type='text' tabindex=1 onchange='send()'></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>

)"
4 changes: 2 additions & 2 deletions library.json
@@ -1,6 +1,6 @@
{
"name": "bitluni ESP32Lib",
"keywords": "VGA, audio, I2S, 3d, game, engine, mesh, gamepad, controller, NES, SNES, input, output, graphics, font, arduino, esp32, driver, display",
"keywords": "VGA, audio, I2S, 3d, game, engine, mesh, gamepad, controller, NES, SNES, input, output, graphics, font, arduino, esp32, driver, display, bitluni",
"description": "Provides VGA, Game Controller (NES, SNES), Audio support for the ESP32. The graphics engine supports sprites, animations and 3d meshes.",
"repository":
{
Expand All @@ -16,7 +16,7 @@
"maintainer": true
}
],
"version": "0.0.4",
"version": "0.0.5",
"frameworks": "arduino",
"platforms": "espressif32"
}
2 changes: 1 addition & 1 deletion library.properties
@@ -1,5 +1,5 @@
name=bitluni ESP32Lib
version=0.0.4
version=0.0.5
author=bitluni <arduino@bitluni.net>
maintainer=bitluni <arduino@bitluni.net>
sentence=Multimedia library for the ESP32
Expand Down
17 changes: 17 additions & 0 deletions src/Graphics/Graphics.h
Expand Up @@ -44,6 +44,23 @@ class Graphics
virtual void dotMix(int x, int y, Color color) = 0;
virtual char get(int x, int y) = 0;
virtual Color** allocateFrameBuffer() = 0;
virtual Color RGBA(int r, int g, int b, int a = 255) const = 0;
virtual int R(Color c) const = 0;
virtual int G(Color c) const = 0;
virtual int B(Color c) const = 0;
virtual int A(Color c) const = 0;
Color RGB(unsigned long rgb) const
{
return RGBA(rgb & 255, (rgb >> 8) & 255, (rgb >> 16) & 255);
}
Color RGBA(unsigned long rgba) const
{
return RGBA(rgba & 255, (rgba >> 8) & 255, (rgba >> 16) & 255, rgba >> 24);
}
Color RGB(int r, int g, int b) const
{
return RGBA(r, g, b);
}

void setFrameBufferCount(unsigned char i)
{
Expand Down
26 changes: 26 additions & 0 deletions src/Graphics/GraphicsR1G1B1A1.h
Expand Up @@ -22,6 +22,28 @@ class GraphicsR1G1B1A1: public Graphics<unsigned char>
frontColor = 0xf;
}

virtual int R(Color c) const
{
return (c & 1) * 255;
}
virtual int G(Color c) const
{
return (c & 2) ? 255 : 0;
}
virtual int B(Color c) const
{
return (c & 4) ? 255 : 0;
}
virtual int A(Color c) const
{
return (c & 8) ? 255 : 0;
}

virtual Color RGBA(int r, int g, int b, int a = 255) const
{
return ((r >> 7) & 1) | ((g >> 6) & 2) | ((b >> 5) & 4) | ((a >> 4) & 8);
}

virtual void dotFast(int x, int y, Color color)
{
if(x & 1)
Expand Down Expand Up @@ -80,7 +102,11 @@ class GraphicsR1G1B1A1: public Graphics<unsigned char>
{
Color** frame = (Color **)malloc(yres * sizeof(Color *));
for (int y = 0; y < yres; y++)
{
frame[y] = (Color *)malloc(xres / 2 * sizeof(Color));
for (int x = 0; x < xres / 2; x++)
frame[y][x] = 0;
}
return frame;
}
};

0 comments on commit 4123d2b

Please sign in to comment.