]> git.defcon.no Git - avrfbosd/commitdiff
Added support for drawing characters and strings, updated font with "limited ascii...
authorJon Langseth <jon.langseth@lilug.no>
Fri, 28 Jun 2013 13:02:32 +0000 (15:02 +0200)
committerJon Langseth <jon.langseth@lilug.no>
Fri, 28 Jun 2013 13:02:32 +0000 (15:02 +0200)
draw.c
draw.h
fbosd.c
font.h

diff --git a/draw.c b/draw.c
index 567b923aaeda8dcfec66f7f048e3487eaece0547..2fd89b412406574e36fe12e5301453338b3816e1 100644 (file)
--- a/draw.c
+++ b/draw.c
@@ -1,5 +1,6 @@
 #include "draw.h"
 #include <stdlib.h>
+#include "font.h"
 
 extern uint8_t* screen_buffer;
 extern uint8_t hres_bytes;
@@ -215,3 +216,29 @@ void pgm_draw_8bpp_bitmap( uint8_t pos_x, uint8_t pos_y, uint8_t width, uint8_t
        }
 }
 
+void draw_char ( uint8_t pos_x, uint8_t pos_y, uint8_t ch)
+{
+       for ( int h = 0; h < font_height; h++ )
+       {
+               uint8_t fl = pgm_read_byte(&( font[ch-32][h]));
+               fl = fl<<(8-font_width);
+               
+               for ( int p = 0; p < font_width; p++ )
+               {
+                       uint8_t ft = fl<<p;
+                       ft = ft & 0x80;
+                       ft = ft>>7;
+                       set_pixel( pos_x+p, pos_y+h, ft);
+               }
+       }
+       
+}
+
+void draw_string ( uint8_t pos_x, uint8_t pos_y, const char *text)
+{
+       for (int i = 0; text[i] != 0; i++)
+       {
+               draw_char( pos_x+(font_width*i)+1, pos_y, text[i]);
+       }
+}
+
diff --git a/draw.h b/draw.h
index 34e0d3cc5a711614d01e86c0ae7de81d62b0e7ef..1fbc3e87015d9aa635d27f0197c8edd72d4a8a72 100644 (file)
--- a/draw.h
+++ b/draw.h
@@ -37,4 +37,7 @@ void fill_circle(uint8_t x0, uint8_t y0, uint8_t radius, char c);
 void draw_8bpp_bitmap( uint8_t pos_x, uint8_t pos_y, uint8_t width, uint8_t height, const uint8_t* image );
 void pgm_draw_8bpp_bitmap( uint8_t pos_x, uint8_t pos_y, uint8_t width, uint8_t height, const uint8_t* image );
 
+void draw_char ( uint8_t pos_x, uint8_t pos_y, uint8_t ch);
+void draw_string ( uint8_t pos_x, uint8_t pos_y, const char *text);
+
 #endif
diff --git a/fbosd.c b/fbosd.c
index 075fa8042f86d55aef59278286aa5ba28abf56c0..3fe199163b461e1ff216608cfc92987f08ef293c 100644 (file)
--- a/fbosd.c
+++ b/fbosd.c
@@ -8,7 +8,6 @@
 #include "render.h"
 #include "draw.h"
 
-//#include "font.h"
 #include "testimage.h"
 
 void (*line_handler)( void );
@@ -141,37 +140,56 @@ int main(void)
        // Enable interrupts globally.
        sei();
 
-       int counter;
-       
-       // Do some static drawing :P
-       set_pixel(28, 8, 1);
-       set_pixel(92, 82, 1);
+       // Switch ON status LED
+       PORTD |= (uint8_t)(1 << PD6);
 
-       set_pixel(92, 8, 1);
-       set_pixel(28, 82, 1);
+       for (;;)
+       {
+               fill(c_BLACK);
+               Delay_ms(100);
+               
+               draw_string( 2, 2,  "!\"#$%&'()*+-./");
+               draw_string( 2, 10, "01234567890");
+               draw_string( 2, 18, ":;<=>?@");
+               draw_string( 2, 26, "ABCDEFGHIJKLM");
+               draw_string( 2, 34, "NOPQRSTUVWXYZ");
+               draw_string( 2, 42, "[\\]^_`");
+               draw_string( 2, 50, "ABCDEFGHIJKLM");
+               draw_string( 2, 58, "NOPQRSTUVWXYZ");
+               draw_string( 2, 66, "{|}~");
 
-       draw_line(0, 0, 128, 92, c_WHITE);
-       draw_line(128, 0, 0, 92, c_WHITE);
+               draw_char( 10, 80, 127);
+               draw_char( 20, 80, 128);
+               draw_char( 30, 80, 129);
+               draw_char( 40, 80, 130);
 
-       draw_rect( 0, 1, 127, 91, c_WHITE);
+               Delay_ms(500);
+               fill(c_BLACK);
 
-       draw_rect( 34, 21, 60, 50, c_WHITE);
-       _draw_rect( 24, 11, 80, 70, 1, c_NONE);
-       draw_rect( 34, 21, 60, 50, c_WHITE);
+               // Do some static drawing :P
+               set_pixel(28, 8, 1);
+               set_pixel(92, 82, 1);
 
-       fill_circle( 64,46, 45, c_WHITE );
-       fill_circle( 64,46, 40, c_BLACK );
+               set_pixel(92, 8, 1);
+               set_pixel(28, 82, 1);
 
-       _draw_circle( 64,46, 35, 1, c_NONE );
-       draw_circle( 64,46, 30, c_WHITE );
-       fill_rect( 38, 25, 52, 42, c_WHITE);
-       fill_rect( 41, 28, 46, 36, c_BLACK);
+               draw_line(0, 0, 128, 92, c_WHITE);
+               draw_line(128, 0, 0, 92, c_WHITE);
+
+               draw_rect( 0, 1, 127, 91, c_WHITE);
+
+               draw_rect( 34, 21, 60, 50, c_WHITE);
+               _draw_rect( 24, 11, 80, 70, 1, c_NONE);
+               draw_rect( 34, 21, 60, 50, c_WHITE);
+
+               fill_circle( 64,46, 45, c_WHITE );
+               fill_circle( 64,46, 40, c_BLACK );
+
+               _draw_circle( 64,46, 35, 1, c_NONE );
+               draw_circle( 64,46, 30, c_WHITE );
+               fill_rect( 38, 25, 52, 42, c_WHITE);
+               fill_rect( 41, 28, 46, 36, c_BLACK);
 
-       for (counter = 0; counter < 3; counter++)
-       {
-               // Toggle status LED
-               PORTD ^= (uint8_t)(1 << PD6);
-               
                for ( int j = 0; j < 92; j++ )
                {
                        draw_line(0,0,128,j, c_INVERT);
@@ -193,27 +211,25 @@ int main(void)
 
                }
                Delay_ms(250);
-       }
-       fill(c_BLACK);
-       
-       int8_t hp = 10;
-       int8_t vp = 10;
-       
-       for (counter = 0; counter < 100; counter++)
-       {
-               hp += 2;
-               vp += 1;
+               fill(c_BLACK);
                
-               if ( hp > 125 ) hp = 10;
-               if ( vp > VRES ) vp = 10;
+               int8_t hp = 10;
+               int8_t vp = 10;
 
-               pgm_draw_8bpp_bitmap(hp, vp, testimage_width, testimage_height, testimage);
-               Delay_ms(10);
-               fill_rect(hp, vp, testimage_width, testimage_height, 0);
-       }
-       for (;;)
-       {
+               int counter = 0;
+               for (counter = 0; counter < 60; counter++)
+               {
+                       hp += 2;
+                       vp += 1;
+                       
+                       if ( hp > 125 ) hp = 10;
+                       if ( vp > VRES ) vp = 10;
+
+                       pgm_draw_8bpp_bitmap(hp, vp, testimage_width, testimage_height, testimage);
+                       Delay_ms(10);
+                       fill_rect(hp, vp, testimage_width, testimage_height, 0);
+               }
+               
        }
-       
 }
 
diff --git a/font.h b/font.h
index 215fb7daaddadd8bd52535028c5e4b98d1fc3a90..bb4e258427060d20127b457d4c5b5e5e6b55ecf0 100644 (file)
--- a/font.h
+++ b/font.h
-const uint8_t font_width  = 8;
-const uint8_t font_height = 8;
+const uint8_t font_width  = 6;
+const uint8_t font_height = 5;
 
-const uint8_t font[3][64] PROGMEM = {
+const int font[99][8] PROGMEM = {
 // Space
+       {
+               0b000000,
+               0b000000,
+               0b000000,
+               0b000000,
+               0b000000,
+       },
 // !
+       {
+               0b001000,
+               0b001000,
+               0b001000,
+               0b000000,
+               0b001000,
+       },
 // "
+       {
+               0b101000,
+               0b101000,
+               0b000000,
+               0b000000,
+               0b000000,
+       },
 // #
+       {
+               0b010100,
+               0b111110,
+               0b010100,
+               0b111110,
+               0b010100,
+       },
 // $
+       {
+               0b111110,
+               0b101000,
+               0b111110,
+               0b001010,
+               0b111110,
+       },
 // %
+       {
+               0b100010,
+               0b000100,
+               0b001000,
+               0b010000,
+               0b100010,
+       },
+
 // &
+       {
+               0b011000,
+               0b100000,
+               0b011010,
+               0b100100,
+               0b011010,
+       },
 // '
+       {
+               0b001000,
+               0b001000,
+               0b000000,
+               0b000000,
+               0b000000,
+       },
 // (
+       {
+               0b001000,
+               0b010000,
+               0b010000,
+               0b010000,
+               0b001000,
+       },
 // )
+       {
+               0b001000,
+               0b000100,
+               0b000100,
+               0b000100,
+               0b001000,
+       },
 // *
+       {
+               0b101010,
+               0b001000,
+               0b111110,
+               0b001000,
+               0b101010,
+       },
 // +
+       {
+               0b000000,
+               0b001000,
+               0b011100,
+               0b001000,
+               0b000000,
+       },
 // ,
+       {
+               0b001000,
+               0b010000,
+               0b000000,
+               0b000000,
+               0b000000,
+       },
 // -
+       {
+               0b000000,
+               0b000000,
+               0b011100,
+               0b000000,
+               0b000000,
+       },
 // .
+       {
+               0b000000,
+               0b000000,
+               0b000000,
+               0b011000,
+               0b011000,
+       },
 // /
+       {
+               0b000010,
+               0b000100,
+               0b001000,
+               0b010000,
+               0b100000,
+       },
 // 0
+       {
+               0b111110,
+               0b100110,
+               0b101010,
+               0b110010,
+               0b111110,
+       },
 // 1
+       {
+               0b001000,
+               0b011000,
+               0b001000,
+               0b001000,
+               0b011100,
+       },
 // 2
+       {
+               0b111100,
+               0b000010,
+               0b011100,
+               0b100000,
+               0b111110,
+       },
 // 3
+       {
+               0b111100,
+               0b000010,
+               0b011100,
+               0b000010,
+               0b111100,
+       },
 // 4
+       {
+               0b001100,
+               0b010100,
+               0b111110,
+               0b000100,
+               0b000100,
+       },
 // 5
+       {
+               0b111110,
+               0b100000,
+               0b111100,
+               0b000010,
+               0b111100,
+       },
 // 6
+       {
+               0b111110,
+               0b100000,
+               0b111110,
+               0b100010,
+               0b111110,
+       },
 // 7
+       {
+               0b111110,
+               0b000010,
+               0b000100,
+               0b001000,
+               0b001000,
+       },
 // 8
+       {
+               0b111110,
+               0b100010,
+               0b111110,
+               0b100010,
+               0b111110,
+       },
 // 9
+       {
+               0b111110,
+               0b100010,
+               0b111110,
+               0b000010,
+               0b111110,
+       },
 // :
+       {
+               0b011000,
+               0b011000,
+               0b000000,
+               0b011000,
+               0b011000,
+       },
 // ;
+       {
+               0b011000,
+               0b011000,
+               0b000000,
+               0b011000,
+               0b010000,
+       },
 // <
+       {
+               0b000110,
+               0b011000,
+               0b100000,
+               0b011000,
+               0b000110,
+       },
 // =
+       {
+               0b000000,
+               0b011100,
+               0b000000,
+               0b011100,
+               0b000000,
+       },
 // >
+       {
+               0b110000,
+               0b001100,
+               0b000010,
+               0b001100,
+               0b110000,
+       },
 // ?
+       {
+               0b011000,
+               0b100100,
+               0b001000,
+               0b000000,
+               0b001000,
+       },
 // @
+       {
+               0b111110,
+               0b100010,
+               0b101110,
+               0b100000,
+               0b111110,
+       },
 // A
        {
-               0b00010000,
-               0b00101000,
-               0b01000100,
-               0b10000010,
-               0b11111110,
-               0b10000010,
-               0b10000010,
-               0b10000010
+               0b011100,
+               0b100010,
+               0b111110,
+               0b100010,
+               0b100010,
        },
 // B
        {
-               0b11111000,
-               0b10000100,
-               0b10000100,
-               0b11111000,
-               0b10000100,
-               0b10000100,
-               0b10000100,
-               0b11111000
+               0b111100,
+               0b100010,
+               0b111100,
+               0b100010,
+               0b111100,
        },
 // C   
        {
-               0b01111100,
-               0b10000010,
-               0b10000000,
-               0b10000000,
-               0b10000000,
-               0b10000000,
-               0b10000010,
-               0b01111100
+               0b011100,
+               0b100010,
+               0b100000,
+               0b100010,
+               0b011100,
        },
 // D
+       {
+               0b111100,
+               0b100010,
+               0b100010,
+               0b100010,
+               0b111100,
+       },
 // E
+       {
+               0b111110,
+               0b100000,
+               0b111000,
+               0b100000,
+               0b111110,
+       },
 // F
+       {
+               0b111110,
+               0b100000,
+               0b111000,
+               0b100000,
+               0b100000,
+       },
 // G
+       {
+               0b111110,
+               0b100000,
+               0b101110,
+               0b100010,
+               0b111110,
+       },
 // H
+       {
+               0b100010,
+               0b100010,
+               0b111110,
+               0b100010,
+               0b100010,
+       },
 // I
+       {
+               0b011100,
+               0b001000,
+               0b001000,
+               0b001000,
+               0b011100,
+       },
 // J
+       {
+               0b000110,
+               0b000010,
+               0b000010,
+               0b100010,
+               0b011100,
+       },
 // K
+       {
+               0b100010,
+               0b100100,
+               0b111000,
+               0b100100,
+               0b100010,
+       },
 // L
+       {
+               0b100000,
+               0b100000,
+               0b100000,
+               0b100010,
+               0b111110,
+       },
 // M
+       {
+               0b100010,
+               0b110110,
+               0b101010,
+               0b100010,
+               0b100010,
+       },
 // N
+       {
+               0b100010,
+               0b110010,
+               0b101010,
+               0b100110,
+               0b100010,
+       },
 // O
+       {
+               0b011100,
+               0b100010,
+               0b100010,
+               0b100010,
+               0b011100,
+       },
 // P
+       {
+               0b111100,
+               0b100010,
+               0b111100,
+               0b100000,
+               0b100000,
+       },
 // Q
+       {
+               0b011100,
+               0b100010,
+               0b100010,
+               0b011100,
+               0b000010,
+       },
 // R
+       {
+               0b111100,
+               0b100010,
+               0b111100,
+               0b100100,
+               0b100010,
+       },
 // S
+       {
+               0b111110,
+               0b100000,
+               0b111110,
+               0b000010,
+               0b111110,
+       },
 // T
+       {
+               0b111110,
+               0b001000,
+               0b001000,
+               0b001000,
+               0b001000,
+       },
 // U
+       {
+               0b100010,
+               0b100010,
+               0b100010,
+               0b100010,
+               0b011100,
+       },
 // V
+       {
+               0b100010,
+               0b100010,
+               0b010100,
+               0b010100,
+               0b001000,
+       },
 // W
+       {
+               0b100010,
+               0b101010,
+               0b101010,
+               0b101010,
+               0b010100,
+       },
 // X
+       {
+               0b100010,
+               0b010100,
+               0b001000,
+               0b010100,
+               0b100010,
+       },
 // Y
+       {
+               0b100010,
+               0b100010,
+               0b010100,
+               0b001000,
+               0b001000,
+       },
 // Z
+       {
+               0b111110,
+               0b000100,
+               0b001000,
+               0b010000,
+               0b111110,
+       },
 // [
-// \
+       {
+               0b011100,
+               0b010000,
+               0b010000,
+               0b010000,
+               0b011100,
+       },
+// '\'
+       {
+               0b100000,
+               0b010000,
+               0b001000,
+               0b000100,
+               0b000010,
+       },
 // ]
+       {
+               0b011100,
+               0b000100,
+               0b000100,
+               0b000100,
+               0b011100,
+       },
 // ^
+       {
+               0b001000,
+               0b010100,
+               0b000000,
+               0b000000,
+               0b000000,
+       },
 // _
+       {
+               0b000000,
+               0b000000,
+               0b000000,
+               0b000000,
+               0b111110,
+       },
 // `
+       {
+               0b010000,
+               0b001000,
+               0b000000,
+               0b000000,
+               0b000000,
+       },
 // a
+       {
+               0b011100,
+               0b100010,
+               0b111110,
+               0b100010,
+               0b100010,
+       },
 // b
-// c
+       {
+               0b111100,
+               0b100010,
+               0b111100,
+               0b100010,
+               0b111100,
+       },
+// c   
+       {
+               0b011100,
+               0b100010,
+               0b100000,
+               0b100010,
+               0b011100,
+       },
 // d
+       {
+               0b111100,
+               0b100010,
+               0b100010,
+               0b100010,
+               0b111100,
+       },
 // e
+       {
+               0b111110,
+               0b100000,
+               0b111000,
+               0b100000,
+               0b111110,
+       },
 // f
+       {
+               0b111110,
+               0b100000,
+               0b111000,
+               0b100000,
+               0b100000,
+       },
 // g
+       {
+               0b111110,
+               0b100000,
+               0b101110,
+               0b100010,
+               0b111110,
+       },
 // h
+       {
+               0b100010,
+               0b100010,
+               0b111110,
+               0b100010,
+               0b100010,
+       },
 // i
+       {
+               0b011100,
+               0b001000,
+               0b001000,
+               0b001000,
+               0b011100,
+       },
 // j
+       {
+               0b000110,
+               0b000010,
+               0b000010,
+               0b100010,
+               0b011100,
+       },
 // k
+       {
+               0b100010,
+               0b100100,
+               0b111000,
+               0b100100,
+               0b100010,
+       },
 // l
+       {
+               0b100000,
+               0b100000,
+               0b100000,
+               0b100010,
+               0b111110,
+       },
 // m
+       {
+               0b100010,
+               0b110110,
+               0b101010,
+               0b100010,
+               0b100010,
+       },
 // n
+       {
+               0b100010,
+               0b110010,
+               0b101010,
+               0b100110,
+               0b100010,
+       },
 // o
+       {
+               0b011100,
+               0b100010,
+               0b100010,
+               0b100010,
+               0b011100,
+       },
 // p
+       {
+               0b111100,
+               0b100010,
+               0b111100,
+               0b100000,
+               0b100000,
+       },
 // q
+       {
+               0b011100,
+               0b100010,
+               0b100010,
+               0b011100,
+               0b000010,
+       },
 // r
+       {
+               0b111100,
+               0b100010,
+               0b111100,
+               0b100100,
+               0b100010,
+       },
 // s
+       {
+               0b111110,
+               0b100000,
+               0b111110,
+               0b000010,
+               0b111110,
+       },
 // t
+       {
+               0b111110,
+               0b001000,
+               0b001000,
+               0b001000,
+               0b001000,
+       },
 // u
+       {
+               0b100010,
+               0b100010,
+               0b100010,
+               0b100010,
+               0b011100,
+       },
 // v
+       {
+               0b100010,
+               0b100010,
+               0b010100,
+               0b010100,
+               0b001000,
+       },
 // w
+       {
+               0b100010,
+               0b101010,
+               0b101010,
+               0b101010,
+               0b010100,
+       },
 // x
+       {
+               0b100010,
+               0b010100,
+               0b001000,
+               0b010100,
+               0b100010,
+       },
 // y
+       {
+               0b100010,
+               0b100010,
+               0b010100,
+               0b001000,
+               0b001000,
+       },
 // z
+       {
+               0b111110,
+               0b000100,
+               0b001000,
+               0b010000,
+               0b111110,
+       },
 // {
+       {
+               0b011100,
+               0b010000,
+               0b100000,
+               0b010000,
+               0b011100,
+       },
 // |
+       {
+               0b001000,
+               0b001000,
+               0b001000,
+               0b001000,
+               0b001000,
+       },
 // }
+       {
+               0b011100,
+               0b000100,
+               0b000010,
+               0b000100,
+               0b011100,
+       },
 // ~
+       {
+               0b000000,
+               0b010000,
+               0b101010,
+               0b000100,
+               0b000000,
+       },
+
+// Batt-full
+       {
+               0b011100,
+               0b111110,
+               0b111110,
+               0b111110,
+               0b111110,
+       },
+// Batt-high
+       {
+               0b011100,
+               0b100010,
+               0b111110,
+               0b111110,
+               0b111110,
+       },
+// Batt-low
+       {
+               0b011100,
+               0b100010,
+               0b100010,
+               0b111110,
+               0b111110,
+       },
+// Batt-empty
+       {
+               0b011100,
+               0b100010,
+               0b100010,
+               0b100010,
+               0b111110,
+       },
+
 };
\ No newline at end of file