SmartWheels self-driving race car. Designed for NXP Cup. Uses FRDM-KL25Z, area-scan camera, and simple image processing to detect and navigate any NXP spec track.

Dependencies:   TSI USBDevice mbed-dev

Fork of SmartWheels by haofan Zheng

Revision:
42:c4e1606087ff
Parent:
41:7b21c5e3599e
Child:
44:15de535c4005
--- a/Hardwares/ArduUTFT.cpp	Thu Mar 23 23:17:51 2017 +0000
+++ b/Hardwares/ArduUTFT.cpp	Fri Mar 24 15:44:08 2017 +0000
@@ -2,11 +2,10 @@
 
 #include "GlobalVariable.h"
 #include "SWUSBServer.h"
+#include "ArduUTFTFont.h"
 
 extern SPI g_spi_port;
 
-#define UTFT_DISP_X_SIZE  239
-#define UTFT_DISP_Y_SIZE  319
 #define UTFT_DISP_TRANS_MODE  8
 
 
@@ -145,12 +144,14 @@
     
     //setColor(255, 255, 255);
     //setBackColor(0, 0, 0);
-    current_font = NULL;
+    //current_font = NULL;
+    ardu_utft_set_font(SmallFont);
     ardu_utft_clr_scr();
     
-    ardu_utft_set_color(255, 0, 255);
-    //ardu_utft_draw_rect(150, 150, 20, 20);
-    
+    ardu_utft_set_color(0, 255, 255);
+    ardu_utft_fill_rect(10, 20, 120, 70);
+    ardu_utft_set_color(255, 255, 255);
+    ardu_utft_print("TEST", 70, 40);
 }
 
 void ardu_cam_set_mode(uint8_t mode)
@@ -183,16 +184,16 @@
     //Possible to be simplified
     swap(uint16_t, x1, y1);
     swap(uint16_t, x2, y2);
-    y1 = UTFT_DISP_Y_SIZE - y1;
-    y2 = UTFT_DISP_Y_SIZE - y2;
-    swap(uint16_t, y1, y2);
+    //y1 = UTFT_DISP_Y_SIZE - y1; //319 - 0 = 319
+    //y2 = UTFT_DISP_Y_SIZE - y2; //319 - 300 = 19
+    //swap(uint16_t, y1, y2); //y1 = 19, y2 = 319
     /////////////////////////////
     
     ardu_utft_write_COM_DATA_internal(0x44, (x2 << 8) + x1);
-    ardu_utft_write_COM_DATA_internal(0x45, y1);
-    ardu_utft_write_COM_DATA_internal(0x46, y2);
+    ardu_utft_write_COM_DATA_internal(0x45, UTFT_DISP_Y_SIZE - y2); //19
+    ardu_utft_write_COM_DATA_internal(0x46, UTFT_DISP_Y_SIZE - y1); //319
     ardu_utft_write_COM_DATA_internal(0x4e, x1);
-    ardu_utft_write_COM_DATA_internal(0x4f, y1);
+    ardu_utft_write_COM_DATA_internal(0x4f, UTFT_DISP_Y_SIZE - y2);
     ardu_utft_write_COM_internal(0x22);
 }
  
@@ -253,4 +254,80 @@
     }
     
     ardu_utft_reset_xy();
+}
+
+ 
+void ardu_utft_draw_pixel(int x, int y)
+{
+    ardu_utft_set_xy(x, y, x, y);
+    ardu_utft_write_DATA_internal(front_color_high, front_color_low);
+    ardu_utft_reset_xy();
+}
+
+void ardu_utft_fill_rect(int x1, int y1, int x2, int y2)
+{
+    if (x1 > x2)
+    {
+        swap(int, x1, x2);
+    }
+    if (y1 > y2)
+    {
+        swap(int, y1, y2);
+    }
+    
+    for (int i = 0; i < ((x2 - x1) / 2) + 1; ++i)
+    {
+        ardu_utft_draw_vline(x1 + i, y1, y2 - y1);
+        ardu_utft_draw_vline(x2 - i, y1, y2 - y1);
+    }
+}
+
+void ardu_utft_set_font(uint8_t * font)
+{
+    current_font = font;
+    font_x_size = font[0];
+    font_y_size = font[1];
+    font_offset = font[2];
+    font_numchars = font[3];
+}
+
+void ardu_utft_print_char(char c, int x, int y)
+{
+    char i, ch;
+    
+    uint16_t temp = ((c - font_offset) * ((font_x_size / 8) * font_y_size)) + 4;
+    
+    for(uint8_t j = 0; j < font_y_size; ++j) 
+    {
+        for (int zz = 0; zz < (font_x_size / 8); ++zz)
+        {
+            ch = current_font[temp + zz]; 
+            for(i = 0; i < 8; ++i)
+            {   
+                ardu_utft_set_xy(x + i + (zz * 8), y + j, x + i + (zz * 8) + 1, y + j + 1);
+            
+                if((ch & (1 << i)) != 0)   
+                {
+                    ardu_utft_write_DATA_internal(front_color_high, front_color_low);
+                } 
+            }
+        }
+        temp += (font_x_size / 8);
+    }
+    
+    ardu_utft_reset_xy();
+}
+
+void ardu_utft_print(char * st, int x, int y)
+{
+    int stl, i;
+    stl = strlen(st);
+    
+    if (x == UTFT_RIGHT)
+        x = (UTFT_DISP_Y_SIZE + 1) - (stl * font_x_size);
+    if (x == UTFT_CENTER)
+        x = ((UTFT_DISP_Y_SIZE + 1) - (stl * font_x_size)) / 2;
+
+    for (i = 0; i < stl; ++i)
+        ardu_utft_print_char(*st++, x - (i * (font_x_size)), y);
 }
\ No newline at end of file