Mathematica-like environment on the mbed using USB keyboard input, VGA output, and a thermal printer.

Dependencies:   mbed Thermal 4DGL-uLCD-SE USBHost_Modified uVGAIII

Revision:
2:d97e71edb2b3
Parent:
0:824466ffa6da
Child:
3:2b6951038d5b
--- a/main.cpp	Mon Dec 10 18:15:37 2018 +0000
+++ b/main.cpp	Thu Dec 13 03:05:28 2018 +0000
@@ -3,11 +3,14 @@
 #include "USBHostKeyboard.h"
 #include "uVGAIII.h"
 
+//#include "stdafx.h"
+#include <iostream>
+#include <cstdlib>
+#include <ctime>
+
 #define SIZE_X       480
 #define SIZE_Y       800
 
-using namespace std;
-
 // Debugging LEDs
 DigitalOut led(LED1);
 DigitalOut led2(LED2);
@@ -15,6 +18,7 @@
 DigitalOut led4(LED4);
 
 uVGAIII ecran(p9,p10,p11); // serial tx, serial rx, reset pin;
+uLCD_4DGL uLCD(p13,p14,p12); // serial tx, serial rx, reset pin;
 Thermal printer(p28, p27, 19200);
 
 int verticalCursor = 2;
@@ -23,6 +27,36 @@
 char currentLine[48];
 int currentLineIndex = 0;
 
+unsigned char bitmap[5000];
+char temp[8];
+
+char getPixel(int x, int y, int bk) {
+    int r = ecran.read_pixel(x, y);
+    if (r == bk) //same as background
+        return '0';
+    else
+        return '1';
+}
+
+void makeBitmap() {
+    int bk = ecran.read_pixel(799,479);
+    for (int i = 0; i < 32; ++i) {
+        for (int j = 0; j < 8; ++j) { //get next 8 bits and put them in temp array
+            temp[j] = getPixel(1+((i%2)*8+j),1+(i/2),bk); // wtf
+            //temp[j] = ecran.read_pixel();
+        }
+       
+        //need to convert to 0b format
+        char * end;
+        long int value = strtol(temp, &end, 2);
+        bitmap[i] = value;
+        led3 = !led3;
+    }
+    printer.printBitmap(16,16,bitmap);
+    printer.feed(2);
+}
+
+/*
 // hardcode plot x^2
 void plot(void const *)
 {
@@ -42,7 +76,7 @@
             pastY = currentY;
             continue;
         }
-        //ecran.line(pastX, pastY, currentX, currentY, RED);
+        ecran.line(pastX, pastY, currentX, currentY, RED);
         //ecran.put_pixel(i*2 + xOffset, yOffset-(i*i),RED);
         pastX = currentX;
         pastY = currentY;
@@ -50,7 +84,9 @@
     while(1) {
         Thread::wait(200);
     }
-}
+}*/
+
+
 
 void onKeyCode(uint8_t key, uint8_t modifier) {
     
@@ -78,6 +114,7 @@
         ecran.move_cursor(verticalCursor, horizontalCursor);
          
         ecran.puts(currentLine);  
+        
         printer.printf(currentLine);
         printer.feed(2);
         
@@ -138,14 +175,14 @@
     }
 }
 
-int main() {    
+int main() {  
+    led = 1; 
     // Set up display
     ecran.baudrate(300000);
     ecran.screen_mode(LANDSCAPE);
     ecran.graphics_parameters(RESOLUTION, 2); 
     ecran.touch_status();
-    //ecran.background_color(DGREY);
-    ecran.background_color(WHITE);
+    ecran.background_color(DGREY);
     ecran.cls();
 
     ecran.move_cursor(0, 0);
@@ -156,12 +193,17 @@
     ecran.puts("Booting up...");   
     
     ecran.line(400, 0 , 400, 480, RED);
+    ecran.filled_rectangle(400,0,405,480,RED);
         
     // Use old style threading
     Thread keyboardTask(keyboard_task, NULL, osPriorityNormal, 256 * 4);
     
     ecran.move_cursor(2, 0);
     ecran.puts("Ready!");
+    //int pix = ecran.read_pixel(400, 0);
+    //printer.printf((char *)pix);
+    makeBitmap();
+    led3 = 1;
     
     //printer.printf("Printing from main");
     //printer.feed(2);
@@ -174,6 +216,17 @@
         
     //Thread drawPlot(plot, NULL, osPriorityNormal, 256*4);
     
+    //int pixel = ecran.read_pixel(200, 200);
+    //char arr[10];
+    //itoa(pixel, arr, 2);
+    //ecran.put_string(pixel);
+    //ecran.put_string(arr);
+    
+   // char * arr = 
+   //    reinterpret_cast <char *>(&pixel);
+       
+   // printer.puts(arr);
+    
     while(1) {
         led=!led;
         Thread::wait(500); // Wait .5s in main thread