From 114128414399b173f8c6e2070abe31fa35e71f29 Mon Sep 17 00:00:00 2001 From: Nils Faerber Date: Sat, 30 Jul 2011 22:45:11 +0200 Subject: [PATCH 1/1] Add drawing fcuntions for lines and strings incl. three fonts --- fonts.h | 321 +++++++++++++++++++++++++++++++++++++++++++ metawatch.c | 17 ++- metawatch_protocol.h | 15 +- mw_main.c | 73 ++++++++++ mw_utility.c | 143 ++++++++++++++++++- mw_utility.h | 22 ++- 6 files changed, 586 insertions(+), 5 deletions(-) create mode 100644 fonts.h diff --git a/fonts.h b/fonts.h new file mode 100644 index 0000000..d8e8013 --- /dev/null +++ b/fonts.h @@ -0,0 +1,321 @@ +/* + * Copyright (C) 2008-2011 Nils Faerber + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +const unsigned char FONT6x8[97][8] = { +{0x06,0x08,0x08,0x00,0x00,0x00,0x00,0x00}, // the first data is allways parameters for font style +{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, +{0x20,0x20,0x20,0x20,0x20,0x00,0x20,0x00}, +{0x50,0x50,0x50,0x00,0x00,0x00,0x00,0x00}, +{0x50,0x50,0xF8,0x50,0xF8,0x50,0x50,0x00}, +{0x20,0x78,0xA0,0x70,0x28,0xF0,0x20,0x00}, +{0xC0,0xC8,0x10,0x20,0x40,0x98,0x18,0x00}, +{0x40,0xA0,0xA0,0x40,0xA8,0x90,0x68,0x00}, +{0x30,0x30,0x20,0x40,0x00,0x00,0x00,0x00}, +{0x10,0x20,0x40,0x40,0x40,0x20,0x10,0x00}, +{0x40,0x20,0x10,0x10,0x10,0x20,0x40,0x00}, +{0x00,0x20,0xA8,0x70,0x70,0xA8,0x20,0x00}, +{0x00,0x20,0x20,0xF8,0x20,0x20,0x00,0x00}, +{0x00,0x00,0x00,0x00,0x30,0x30,0x20,0x40}, +{0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00}, +{0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00}, +{0x70,0x88,0x88,0xA8,0x88,0x88,0x70,0x00}, +{0x20,0x60,0x20,0x20,0x20,0x20,0x70,0x00}, +{0x70,0x88,0x08,0x70,0x80,0x80,0xF8,0x00}, +{0xF8,0x08,0x10,0x30,0x08,0x88,0x70,0x00}, +{0x10,0x30,0x50,0x90,0xF8,0x10,0x10,0x00}, +{0xF8,0x80,0xF0,0x08,0x08,0x88,0x70,0x00}, +{0x38,0x40,0x80,0xF0,0x88,0x88,0x70,0x00}, +{0xF8,0x08,0x08,0x10,0x20,0x40,0x80,0x00}, +{0x70,0x88,0x88,0x70,0x88,0x88,0x70,0x00}, +{0x70,0x88,0x88,0x78,0x08,0x10,0xE0,0x00}, +{0x00,0x00,0x20,0x00,0x20,0x00,0x00,0x00}, +{0x00,0x00,0x20,0x00,0x20,0x20,0x40,0x00}, +{0x08,0x10,0x20,0x40,0x20,0x10,0x08,0x00}, +{0x00,0x00,0xF8,0x00,0xF8,0x00,0x00,0x00}, +{0x40,0x20,0x10,0x08,0x10,0x20,0x40,0x00}, +{0x70,0x88,0x08,0x30,0x20,0x00,0x20,0x00}, +{0x70,0x88,0xA8,0xB8,0xB0,0x80,0x78,0x00}, +{0x20,0x50,0x88,0x88,0xF8,0x88,0x88,0x00}, +{0xF0,0x88,0x88,0xF0,0x88,0x88,0xF0,0x00}, +{0x70,0x88,0x80,0x80,0x80,0x88,0x70,0x00}, +{0xF0,0x88,0x88,0x88,0x88,0x88,0xF0,0x00}, +{0xF8,0x80,0x80,0xF0,0x80,0x80,0xF8,0x00}, +{0xF8,0x80,0x80,0xF0,0x80,0x80,0x80,0x00}, +{0x78,0x88,0x80,0x80,0x98,0x88,0x78,0x00}, +{0x88,0x88,0x88,0xF8,0x88,0x88,0x88,0x00}, +{0x70,0x20,0x20,0x20,0x20,0x20,0x70,0x00}, +{0x38,0x10,0x10,0x10,0x10,0x90,0x60,0x00}, +{0x88,0x90,0xA0,0xC0,0xA0,0x90,0x88,0x00}, +{0x80,0x80,0x80,0x80,0x80,0x80,0xF8,0x00}, +{0x88,0xD8,0xA8,0xA8,0xA8,0x88,0x88,0x00}, +{0x88,0x88,0xC8,0xA8,0x98,0x88,0x88,0x00}, +{0x70,0x88,0x88,0x88,0x88,0x88,0x70,0x00}, +{0xF0,0x88,0x88,0xF0,0x80,0x80,0x80,0x00}, +{0x70,0x88,0x88,0x88,0xA8,0x90,0x68,0x00}, +{0xF0,0x88,0x88,0xF0,0xA0,0x90,0x88,0x00}, +{0x70,0x88,0x80,0x70,0x08,0x88,0x70,0x00}, +{0xF8,0xA8,0x20,0x20,0x20,0x20,0x20,0x00}, +{0x88,0x88,0x88,0x88,0x88,0x88,0x70,0x00}, +{0x88,0x88,0x88,0x88,0x88,0x50,0x20,0x00}, +{0x88,0x88,0x88,0xA8,0xA8,0xA8,0x50,0x00}, +{0x88,0x88,0x50,0x20,0x50,0x88,0x88,0x00}, +{0x88,0x88,0x50,0x20,0x20,0x20,0x20,0x00}, +{0xF8,0x08,0x10,0x70,0x40,0x80,0xF8,0x00}, +{0x78,0x40,0x40,0x40,0x40,0x40,0x78,0x00}, +{0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00}, +{0x78,0x08,0x08,0x08,0x08,0x08,0x78,0x00}, +{0x20,0x50,0x88,0x00,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x00}, +{0x60,0x60,0x20,0x10,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x60,0x10,0x70,0x90,0x78,0x00}, +{0x80,0x80,0xB0,0xC8,0x88,0xC8,0xB0,0x00}, +{0x00,0x00,0x70,0x88,0x80,0x88,0x70,0x00}, +{0x08,0x08,0x68,0x98,0x88,0x98,0x68,0x00}, +{0x00,0x00,0x70,0x88,0xF8,0x80,0x70,0x00}, +{0x10,0x28,0x20,0x70,0x20,0x20,0x20,0x00}, +{0x00,0x00,0x70,0x98,0x98,0x68,0x08,0x70}, +{0x80,0x80,0xB0,0xC8,0x88,0x88,0x88,0x00}, +{0x20,0x00,0x60,0x20,0x20,0x20,0x70,0x00}, +{0x10,0x00,0x10,0x10,0x10,0x90,0x60,0x00}, +{0x80,0x80,0x90,0xA0,0xC0,0xA0,0x90,0x00}, +{0x60,0x20,0x20,0x20,0x20,0x20,0x70,0x00}, +{0x00,0x00,0xD0,0xA8,0xA8,0xA8,0xA8,0x00}, +{0x00,0x00,0xB0,0xC8,0x88,0x88,0x88,0x00}, +{0x00,0x00,0x70,0x88,0x88,0x88,0x70,0x00}, +{0x00,0x00,0xB0,0xC8,0xC8,0xB0,0x80,0x80}, +{0x00,0x00,0x68,0x98,0x98,0x68,0x08,0x08}, +{0x00,0x00,0xB0,0xC8,0x80,0x80,0x80,0x00}, +{0x00,0x00,0x78,0x80,0x70,0x08,0xF0,0x00}, +{0x20,0x20,0xF8,0x20,0x20,0x28,0x10,0x00}, +{0x00,0x00,0x88,0x88,0x88,0x98,0x68,0x00}, +{0x00,0x00,0x88,0x88,0x88,0x50,0x20,0x00}, +{0x00,0x00,0x88,0x88,0xA8,0xA8,0x50,0x00}, +{0x00,0x00,0x88,0x50,0x20,0x50,0x88,0x00}, +{0x00,0x00,0x88,0x88,0x78,0x08,0x88,0x70}, +{0x00,0x00,0xF8,0x10,0x20,0x40,0xF8,0x00}, +{0x10,0x20,0x20,0x40,0x20,0x20,0x10,0x00}, +{0x20,0x20,0x20,0x00,0x20,0x20,0x20,0x00}, +{0x40,0x20,0x20,0x10,0x20,0x20,0x40,0x00}, +{0x40,0xA8,0x10,0x00,0x00,0x00,0x00,0x00}, +{0x70,0xD8,0xD8,0x70,0x00,0x00,0x00,0x00} +}; + + +const unsigned char FONT8x8F[97][8] = { +{0x08,0x08,0x08,0x00,0x00,0x00,0x00,0x00}, // the first data is allways parameters for font style +{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, +{0x30,0x78,0x78,0x30,0x30,0x00,0x30,0x00}, +{0x6C,0x6C,0x6C,0x00,0x00,0x00,0x00,0x00}, +{0x6C,0x6C,0xFE,0x6C,0xFE,0x6C,0x6C,0x00}, +{0x18,0x3E,0x60,0x3C,0x06,0x7C,0x18,0x00}, +{0x00,0x63,0x66,0x0C,0x18,0x33,0x63,0x00}, +{0x1C,0x36,0x1C,0x3B,0x6E,0x66,0x3B,0x00}, +{0x30,0x30,0x60,0x00,0x00,0x00,0x00,0x00}, +{0x0C,0x18,0x30,0x30,0x30,0x18,0x0C,0x00}, +{0x30,0x18,0x0C,0x0C,0x0C,0x18,0x30,0x00}, +{0x00,0x66,0x3C,0xFF,0x3C,0x66,0x00,0x00}, +{0x00,0x30,0x30,0xFC,0x30,0x30,0x00,0x00}, +{0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x30}, +{0x00,0x00,0x00,0x7E,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00}, +{0x03,0x06,0x0C,0x18,0x30,0x60,0x40,0x00}, +{0x3E,0x63,0x63,0x6B,0x63,0x63,0x3E,0x00}, +{0x18,0x38,0x58,0x18,0x18,0x18,0x7E,0x00}, +{0x3C,0x66,0x06,0x1C,0x30,0x66,0x7E,0x00}, +{0x3C,0x66,0x06,0x1C,0x06,0x66,0x3C,0x00}, +{0x0E,0x1E,0x36,0x66,0x7F,0x06,0x0F,0x00}, +{0x7E,0x60,0x7C,0x06,0x06,0x66,0x3C,0x00}, +{0x1C,0x30,0x60,0x7C,0x66,0x66,0x3C,0x00}, +{0x7E,0x66,0x06,0x0C,0x18,0x18,0x18,0x00}, +{0x3C,0x66,0x66,0x3C,0x66,0x66,0x3C,0x00}, +{0x3C,0x66,0x66,0x3E,0x06,0x0C,0x38,0x00}, +{0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x00}, +{0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x30}, +{0x0C,0x18,0x30,0x60,0x30,0x18,0x0C,0x00}, +{0x00,0x00,0x7E,0x00,0x00,0x7E,0x00,0x00}, +{0x30,0x18,0x0C,0x06,0x0C,0x18,0x30,0x00}, +{0x3C,0x66,0x06,0x0C,0x18,0x00,0x18,0x00}, +{0x3E,0x63,0x6F,0x69,0x6F,0x60,0x3E,0x00}, +{0x18,0x3C,0x66,0x66,0x7E,0x66,0x66,0x00}, +{0x7E,0x33,0x33,0x3E,0x33,0x33,0x7E,0x00}, +{0x1E,0x33,0x60,0x60,0x60,0x33,0x1E,0x00}, +{0x7C,0x36,0x33,0x33,0x33,0x36,0x7C,0x00}, +{0x7F,0x31,0x34,0x3C,0x34,0x31,0x7F,0x00}, +{0x7F,0x31,0x34,0x3C,0x34,0x30,0x78,0x00}, +{0x1E,0x33,0x60,0x60,0x67,0x33,0x1F,0x00}, +{0x66,0x66,0x66,0x7E,0x66,0x66,0x66,0x00}, +{0x3C,0x18,0x18,0x18,0x18,0x18,0x3C,0x00}, +{0x0F,0x06,0x06,0x06,0x66,0x66,0x3C,0x00}, +{0x73,0x33,0x36,0x3C,0x36,0x33,0x73,0x00}, +{0x78,0x30,0x30,0x30,0x31,0x33,0x7F,0x00}, +{0x63,0x77,0x7F,0x7F,0x6B,0x63,0x63,0x00}, +{0x63,0x73,0x7B,0x6F,0x67,0x63,0x63,0x00}, +{0x3E,0x63,0x63,0x63,0x63,0x63,0x3E,0x00}, +{0x7E,0x33,0x33,0x3E,0x30,0x30,0x78,0x00}, +{0x3C,0x66,0x66,0x66,0x6E,0x3C,0x0E,0x00}, +{0x7E,0x33,0x33,0x3E,0x36,0x33,0x73,0x00}, +{0x3C,0x66,0x30,0x18,0x0C,0x66,0x3C,0x00}, +{0x7E,0x5A,0x18,0x18,0x18,0x18,0x3C,0x00}, +{0x66,0x66,0x66,0x66,0x66,0x66,0x7E,0x00}, +{0x66,0x66,0x66,0x66,0x66,0x3C,0x18,0x00}, +{0x63,0x63,0x63,0x6B,0x7F,0x77,0x63,0x00}, +{0x63,0x63,0x36,0x1C,0x1C,0x36,0x63,0x00}, +{0x66,0x66,0x66,0x3C,0x18,0x18,0x3C,0x00}, +{0x7F,0x63,0x46,0x0C,0x19,0x33,0x7F,0x00}, +{0x3C,0x30,0x30,0x30,0x30,0x30,0x3C,0x00}, +{0x60,0x30,0x18,0x0C,0x06,0x03,0x01,0x00}, +{0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3C,0x00}, +{0x08,0x1C,0x36,0x63,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF}, +{0x18,0x18,0x0C,0x00,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x3C,0x06,0x3E,0x66,0x3B,0x00}, +{0x70,0x30,0x3E,0x33,0x33,0x33,0x6E,0x00}, +{0x00,0x00,0x3C,0x66,0x60,0x66,0x3C,0x00}, +{0x0E,0x06,0x3E,0x66,0x66,0x66,0x3B,0x00}, +{0x00,0x00,0x3C,0x66,0x7E,0x60,0x3C,0x00}, +{0x1C,0x36,0x30,0x78,0x30,0x30,0x78,0x00}, +{0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x7C}, +{0x70,0x30,0x36,0x3B,0x33,0x33,0x73,0x00}, +{0x18,0x00,0x38,0x18,0x18,0x18,0x3C,0x00}, +{0x06,0x00,0x06,0x06,0x06,0x66,0x66,0x3C}, +{0x70,0x30,0x33,0x36,0x3C,0x36,0x73,0x00}, +{0x38,0x18,0x18,0x18,0x18,0x18,0x3C,0x00}, +{0x00,0x00,0x66,0x7F,0x7F,0x6B,0x63,0x00}, +{0x00,0x00,0x7C,0x66,0x66,0x66,0x66,0x00}, +{0x00,0x00,0x3C,0x66,0x66,0x66,0x3C,0x00}, +{0x00,0x00,0x6E,0x33,0x33,0x3E,0x30,0x78}, +{0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x0F}, +{0x00,0x00,0x6E,0x3B,0x33,0x30,0x78,0x00}, +{0x00,0x00,0x3E,0x60,0x3C,0x06,0x7C,0x00}, +{0x08,0x18,0x3E,0x18,0x18,0x1A,0x0C,0x00}, +{0x00,0x00,0x66,0x66,0x66,0x66,0x3B,0x00}, +{0x00,0x00,0x66,0x66,0x66,0x3C,0x18,0x00}, +{0x00,0x00,0x63,0x6B,0x7F,0x7F,0x36,0x00}, +{0x00,0x00,0x63,0x36,0x1C,0x36,0x63,0x00}, +{0x00,0x00,0x66,0x66,0x66,0x3E,0x06,0x7C}, +{0x00,0x00,0x7E,0x4C,0x18,0x32,0x7E,0x00}, +{0x0E,0x18,0x18,0x70,0x18,0x18,0x0E,0x00}, +{0x0C,0x0C,0x0C,0x00,0x0C,0x0C,0x0C,0x00}, +{0x70,0x18,0x18,0x0E,0x18,0x18,0x70,0x00}, +{0x3B,0x6E,0x00,0x00,0x00,0x00,0x00,0x00}, +{0x1C,0x36,0x36,0x1C,0x00,0x00,0x00,0x00} +}; + + +const unsigned char FONT8x16[97][16] = { +{0x08,0x10,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // the first data is allways parameters for font style +{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x18,0x3C,0x3C,0x3C,0x18,0x18,0x18,0x00,0x18,0x18,0x00,0x00,0x00,0x00}, +{0x00,0x63,0x63,0x63,0x22,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x36,0x36,0x7F,0x36,0x36,0x36,0x7F,0x36,0x36,0x00,0x00,0x00,0x00}, +{0x0C,0x0C,0x3E,0x63,0x61,0x60,0x3E,0x03,0x03,0x43,0x63,0x3E,0x0C,0x0C,0x00,0x00}, +{0x00,0x00,0x00,0x00,0x00,0x61,0x63,0x06,0x0C,0x18,0x33,0x63,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x1C,0x36,0x36,0x1C,0x3B,0x6E,0x66,0x66,0x3B,0x00,0x00,0x00,0x00}, +{0x00,0x30,0x30,0x30,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x0C,0x18,0x18,0x30,0x30,0x30,0x30,0x18,0x18,0x0C,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x18,0x0C,0x0C,0x06,0x06,0x06,0x06,0x0C,0x0C,0x18,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00,0x42,0x66,0x3C,0xFF,0x3C,0x66,0x42,0x00,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00,0x18,0x18,0x18,0xFF,0x18,0x18,0x18,0x00,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x18,0x30,0x00,0x00}, +{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x01,0x03,0x07,0x0E,0x1C,0x38,0x70,0xE0,0xC0,0x80,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x3E,0x63,0x63,0x63,0x6B,0x6B,0x63,0x63,0x63,0x3E,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x0C,0x1C,0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3F,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x3E,0x63,0x03,0x06,0x0C,0x18,0x30,0x61,0x63,0x7F,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x3E,0x63,0x03,0x03,0x1E,0x03,0x03,0x03,0x63,0x3E,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x06,0x0E,0x1E,0x36,0x66,0x66,0x7F,0x06,0x06,0x0F,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x7F,0x60,0x60,0x60,0x7E,0x03,0x03,0x63,0x73,0x3E,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x1C,0x30,0x60,0x60,0x7E,0x63,0x63,0x63,0x63,0x3E,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x7F,0x63,0x03,0x06,0x06,0x0C,0x0C,0x18,0x18,0x18,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x3E,0x63,0x63,0x63,0x3E,0x63,0x63,0x63,0x63,0x3E,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x3E,0x63,0x63,0x63,0x63,0x3F,0x03,0x03,0x06,0x3C,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00,0x00,0x00,0x18,0x18,0x18,0x30,0x00,0x00}, +{0x00,0x00,0x00,0x06,0x0C,0x18,0x30,0x60,0x30,0x18,0x0C,0x06,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x00,0x00,0x7E,0x00,0x00,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x60,0x30,0x18,0x0C,0x06,0x0C,0x18,0x30,0x60,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x3E,0x63,0x63,0x06,0x0C,0x0C,0x0C,0x00,0x0C,0x0C,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x3E,0x63,0x63,0x6F,0x6B,0x6B,0x6E,0x60,0x60,0x3E,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x08,0x1C,0x36,0x63,0x63,0x63,0x7F,0x63,0x63,0x63,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x7E,0x33,0x33,0x33,0x3E,0x33,0x33,0x33,0x33,0x7E,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x1E,0x33,0x61,0x60,0x60,0x60,0x60,0x61,0x33,0x1E,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x7C,0x36,0x33,0x33,0x33,0x33,0x33,0x33,0x36,0x7C,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x7F,0x33,0x31,0x34,0x3C,0x34,0x30,0x31,0x33,0x7F,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x7F,0x33,0x31,0x34,0x3C,0x34,0x30,0x30,0x30,0x78,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x1E,0x33,0x61,0x60,0x60,0x6F,0x63,0x63,0x37,0x1D,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x63,0x63,0x63,0x63,0x7F,0x63,0x63,0x63,0x63,0x63,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x3C,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x3C,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x0F,0x06,0x06,0x06,0x06,0x06,0x06,0x66,0x66,0x3C,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x73,0x33,0x36,0x36,0x3C,0x36,0x36,0x33,0x33,0x73,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x78,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x33,0x7F,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x63,0x77,0x7F,0x6B,0x63,0x63,0x63,0x63,0x63,0x63,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x63,0x63,0x73,0x7B,0x7F,0x6F,0x67,0x63,0x63,0x63,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x1C,0x36,0x63,0x63,0x63,0x63,0x63,0x63,0x36,0x1C,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x7E,0x33,0x33,0x33,0x3E,0x30,0x30,0x30,0x30,0x78,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x3E,0x63,0x63,0x63,0x63,0x63,0x63,0x6B,0x6F,0x3E,0x06,0x07,0x00,0x00}, +{0x00,0x00,0x7E,0x33,0x33,0x33,0x3E,0x36,0x36,0x33,0x33,0x73,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x3E,0x63,0x63,0x30,0x1C,0x06,0x03,0x63,0x63,0x3E,0x00,0x00,0x00,0x00}, +{0x00,0x00,0xFF,0xDB,0x99,0x18,0x18,0x18,0x18,0x18,0x18,0x3C,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x63,0x63,0x63,0x63,0x63,0x63,0x63,0x63,0x63,0x3E,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x63,0x63,0x63,0x63,0x63,0x63,0x63,0x36,0x1C,0x08,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x63,0x63,0x63,0x63,0x63,0x6B,0x6B,0x7F,0x36,0x36,0x00,0x00,0x00,0x00}, +{0x00,0x00,0xC3,0xC3,0x66,0x3C,0x18,0x18,0x3C,0x66,0xC3,0xC3,0x00,0x00,0x00,0x00}, +{0x00,0x00,0xC3,0xC3,0xC3,0x66,0x3C,0x18,0x18,0x18,0x18,0x3C,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x7F,0x63,0x43,0x06,0x0C,0x18,0x30,0x61,0x63,0x7F,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x3C,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x3C,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x80,0xC0,0xE0,0x70,0x38,0x1C,0x0E,0x07,0x03,0x01,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3C,0x00,0x00,0x00,0x00}, +{0x08,0x1C,0x36,0x63,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00}, +{0x18,0x18,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00,0x00,0x3C,0x46,0x06,0x3E,0x66,0x66,0x3B,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x70,0x30,0x30,0x3C,0x36,0x33,0x33,0x33,0x33,0x6E,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00,0x00,0x3E,0x63,0x60,0x60,0x60,0x63,0x3E,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x0E,0x06,0x06,0x1E,0x36,0x66,0x66,0x66,0x66,0x3B,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00,0x00,0x3E,0x63,0x63,0x7E,0x60,0x63,0x3E,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x1C,0x36,0x32,0x30,0x7C,0x30,0x30,0x30,0x30,0x78,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00,0x00,0x3B,0x66,0x66,0x66,0x66,0x3E,0x06,0x66,0x3C,0x00,0x00}, +{0x00,0x00,0x70,0x30,0x30,0x36,0x3B,0x33,0x33,0x33,0x33,0x73,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x0C,0x0C,0x00,0x1C,0x0C,0x0C,0x0C,0x0C,0x0C,0x1E,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x06,0x06,0x00,0x0E,0x06,0x06,0x06,0x06,0x06,0x66,0x66,0x3C,0x00,0x00}, +{0x00,0x00,0x70,0x30,0x30,0x33,0x33,0x36,0x3C,0x36,0x33,0x73,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x1C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x1E,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00,0x00,0x6E,0x7F,0x6B,0x6B,0x6B,0x6B,0x6B,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00,0x00,0x6E,0x33,0x33,0x33,0x33,0x33,0x33,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00,0x00,0x3E,0x63,0x63,0x63,0x63,0x63,0x3E,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00,0x00,0x6E,0x33,0x33,0x33,0x33,0x3E,0x30,0x30,0x78,0x00,0x00}, +{0x00,0x00,0x00,0x00,0x00,0x3B,0x66,0x66,0x66,0x66,0x3E,0x06,0x06,0x0F,0x00,0x00}, +{0x00,0x00,0x00,0x00,0x00,0x6E,0x3B,0x33,0x30,0x30,0x30,0x78,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00,0x00,0x3E,0x63,0x38,0x0E,0x03,0x63,0x3E,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x08,0x18,0x18,0x7E,0x18,0x18,0x18,0x18,0x1B,0x0E,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00,0x00,0x66,0x66,0x66,0x66,0x66,0x66,0x3B,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00,0x00,0x63,0x63,0x36,0x36,0x1C,0x1C,0x08,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00,0x00,0x63,0x63,0x63,0x6B,0x6B,0x7F,0x36,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00,0x00,0x63,0x36,0x1C,0x1C,0x1C,0x36,0x63,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x00,0x00,0x00,0x63,0x63,0x63,0x63,0x63,0x3F,0x03,0x06,0x3C,0x00,0x00}, +{0x00,0x00,0x00,0x00,0x00,0x7F,0x66,0x0C,0x18,0x30,0x63,0x7F,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x0E,0x18,0x18,0x18,0x70,0x18,0x18,0x18,0x18,0x0E,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x18,0x18,0x18,0x18,0x18,0x00,0x18,0x18,0x18,0x18,0x18,0x00,0x00,0x00}, +{0x00,0x00,0x70,0x18,0x18,0x18,0x0E,0x18,0x18,0x18,0x18,0x70,0x00,0x00,0x00,0x00}, +{0x00,0x00,0x3B,0x6E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, +{0x00,0x70,0xD8,0xD8,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00} +}; + diff --git a/metawatch.c b/metawatch.c index 90ea65e..a87ac7b 100644 --- a/metawatch.c +++ b/metawatch.c @@ -1,7 +1,20 @@ /* * (c) 2011 Siegen, Germany by Nils Faerber * - * license LGPL + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. */ #include @@ -352,7 +365,7 @@ void mw_send_bitmap(int mw_fd, unsigned char mode, int width, int height, int of unsigned int y, rowlength; unsigned char mw_buf[24]; - rowlength = ((width / 8) + 1); + rowlength = (((width-1) / 8) + 1); if ((height + offset) > 96) height = 96 - offset; diff --git a/metawatch_protocol.h b/metawatch_protocol.h index 96c437f..0f45ac0 100644 --- a/metawatch_protocol.h +++ b/metawatch_protocol.h @@ -1,7 +1,20 @@ /* * (c) 2011 Siegen, Germany by Nils Faerber * - * license LGPL + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. */ #ifndef _MW_PROT_H diff --git a/mw_main.c b/mw_main.c index 0bcd41c..7a0831f 100644 --- a/mw_main.c +++ b/mw_main.c @@ -27,6 +27,7 @@ #include "metawatch.h" #include "crc16ccitt.h" +#include "mw_utility.h" void bitmap_test(int mw_fd) @@ -46,6 +47,69 @@ void bitmap_test(int mw_fd) mw_update_display(mw_fd, MW_SCREEN_MODE_IDLE, 1); } +void bitmap_test2(int mw_fd) +{ + mw_buffer *mwbuf1, *mwbuf2; + unsigned char *bbuf; + int len, x; + + mwbuf1 = mw_alloc_pbuffer(96, 66, 1); + mwbuf2 = mw_alloc_pbuffer(96, 66, 1); + + mw_buf_clear(mwbuf1, MW_BLACK); + mw_buf_clear(mwbuf2, MW_WHITE); + + for (x=0; x<66; x++) { + //mw_buf_clear(mwbuf1, MW_BLACK); + mw_buf_draw_pixel(mwbuf1, x, x, MW_WHITE); + mw_dump_mw_buffer(mwbuf1); + bbuf = mw_make_mw_buffer(mwbuf1, &len); + mw_send_bitmap(mw_fd, MW_SCREEN_MODE_IDLE, 96, 65, 31, bbuf, len); + mw_update_display(mw_fd, MW_SCREEN_MODE_IDLE, 1); + getchar(); + }; + + mw_free_pbuffer(mwbuf1); + mw_free_pbuffer(mwbuf2); +} + +void text_test(int mw_fd) +{ + mw_buffer *mwbuf; + unsigned char *bbuf; + int len; + + mwbuf = mw_alloc_pbuffer(96, 66, 1); + mw_buf_clear(mwbuf, MW_BLACK); + + mw_buf_print(mwbuf, 1, 10, "Font 0", 0, MW_WHITE, MW_BLACK); + mw_buf_print(mwbuf, 1, 20, "Font 1", 1, MW_WHITE, MW_BLACK); + mw_buf_print(mwbuf, 1, 30, "Font 2", 2, MW_WHITE, MW_BLACK); + mw_buf_print(mwbuf, 1, 45, "Big Fat Clipping", 2, MW_BLACK, MW_WHITE); + + bbuf = mw_make_mw_buffer(mwbuf, &len); + mw_send_bitmap(mw_fd, MW_SCREEN_MODE_IDLE, 96, 65, 31, bbuf, len); + mw_update_display(mw_fd, MW_SCREEN_MODE_IDLE, 1); + mw_free_pbuffer(mwbuf); +} + +void line_test(int mw_fd) +{ + mw_buffer *mwbuf; + unsigned char *bbuf; + int len, p; + + mwbuf = mw_alloc_pbuffer(96, 66, 1); + mw_buf_clear(mwbuf, MW_BLACK); + + for (p=0; p<=96; p+=8) + mw_buf_draw_line_bresenham(mwbuf, p, 0, 95-p, 65, MW_WHITE); + + bbuf = mw_make_mw_buffer(mwbuf, &len); + mw_send_bitmap(mw_fd, MW_SCREEN_MODE_IDLE, 96, 65, 31, bbuf, len); + mw_update_display(mw_fd, MW_SCREEN_MODE_IDLE, 1); + mw_free_pbuffer(mwbuf); +} void bitmap_read(int mw_fd) { @@ -170,6 +234,15 @@ void process_cmd(char *cmdline, int clinep, int mw_fd) if (strncmp(cmdline, "tbmp", 4) == 0) { bitmap_test(mw_fd); } + if (strncmp(cmdline, "t2bmp", 5) == 0) { + bitmap_test2(mw_fd); + } + if (strncmp(cmdline, "text", 4) == 0) { + text_test(mw_fd); + } + if (strncmp(cmdline, "tline", 5) == 0) { + line_test(mw_fd); + } if (strncmp(cmdline, "rbmp", 4) == 0) { bitmap_read(mw_fd); } diff --git a/mw_utility.c b/mw_utility.c index 119207b..baf3d0a 100644 --- a/mw_utility.c +++ b/mw_utility.c @@ -1,7 +1,20 @@ /* * (c) 2011 Siegen, Germany by Nils Faerber * - * license LGPL + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. */ #include @@ -11,6 +24,8 @@ #include "mw_utility.h" #include "metawatch.h" +#include "fonts.h" + /* * The pixmap buffer has at least one byte per pixel, even for monochrome (bpp=1) * bitmaps @@ -48,6 +63,31 @@ void mw_free_pbuffer(mw_buffer *mwbuf) free(mwbuf); } +/* + * makes a buffer for sending to the watch from the drawing buffer, e.g. + * mw_send_bitmap(mw_fd, MW_SCREEN_MODE_IDLE, 96, 65, 31, bbuf, len); + */ +unsigned char *mw_make_mw_buffer(mw_buffer *mwbuf, int *buflen) +{ + static unsigned char wbuf[96*12]; + int x, y; + unsigned char clr; + + memset(wbuf, 0, 96*12); + + for (y = 0; y < mwbuf->res_y; y++) { + for (x = 0; x < mwbuf->res_x; x++) { + clr = *(unsigned char *)(mwbuf->pbuf+((y*mwbuf->res_x)+x)); + if (clr) { + *(unsigned char *)(wbuf+((y*12)+(x/8))) |= 1 << (x%8); + }; + }; + }; + *buflen = mwbuf->res_y * 12; + + return wbuf; +} + void mw_dump_mw_buffer(mw_buffer *mwbuf) { int x, y; @@ -73,6 +113,8 @@ void mw_buf_clear(mw_buffer *mwbuf, mw_color clr) if (!mwbuf) return; + if (clr == MW_TRANSPARENT) + return; pbuf_size = mwbuf->res_x * mwbuf->res_y * ((mwbuf->bpp / 8) + 1); memset(mwbuf->pbuf, clr, pbuf_size); @@ -83,8 +125,107 @@ void mw_buf_draw_pixel(mw_buffer *mwbuf, unsigned int x, unsigned int y, mw_colo { if (!mwbuf) return; + if (clr == MW_TRANSPARENT) + return; *(unsigned char *)(mwbuf->pbuf+((y*mwbuf->res_x)+x)) = clr; } +void mw_buf_print(mw_buffer *mwbuf, unsigned int x, unsigned int y, char *text, unsigned char fsize, mw_color fgclr, mw_color bgclr) +{ + unsigned int i,j,z; + const unsigned char *data, *font_style; + unsigned char mask,xme,yme,offset; + + if (text==NULL || strlen(text) == 0) + return; + + switch (fsize) { + case 0: + data = (const unsigned char *)FONT6x8; + font_style = (const unsigned char *)FONT6x8; + break; + case 1: + data = (const unsigned char *)FONT8x8F; + font_style = (const unsigned char *)FONT8x8F; + break; + case 2: + data = (const unsigned char *)FONT8x16; + font_style = (const unsigned char *)FONT8x16; + break; + default: + data = (const unsigned char *)FONT6x8; + font_style = (const unsigned char *)FONT6x8; + break; + }; + xme = *data++; + yme = *data++; + offset = *data; + + do { + mask = 0x00; + data = (font_style + offset) + (offset * (int)(*text - 32)); + for (i=0; i < yme; i++) { + mask |=0x80; + for (j=x; j < (x + xme); j++) { + z = y + i; + if ((z < mwbuf->res_y) && (j < mwbuf->res_x)) { + if (*data & mask) { + mw_buf_draw_pixel(mwbuf, j, z, fgclr); + } else { + mw_buf_draw_pixel(mwbuf, j, z, bgclr); + } + } + mask >>= 1; + } + data++; + } + x += xme; + text++; + } while (*text != '\0'); +} + +void mw_buf_draw_line_bresenham(mw_buffer *mwbuf, unsigned int xstart, unsigned int ystart, unsigned int xend, unsigned int yend, mw_color clr) +{ + int x, y, t, dx, dy, incx, incy, pdx, pdy, ddx, ddy, es, el, err; + + dx = xend - xstart; + dy = yend - ystart; + + incx = (dx >= 0) ? 1 : -1; + incy = (dy >= 0) ? 1 : -1; + + if (dx<0) + dx = -dx; + if (dy<0) + dy = -dy; + + if (dx>dy) { + pdx = incx; pdy = 0; + ddx=incx; ddy=incy; + es =dy; el =dx; + } else { + pdx=0; pdy=incy; + ddx=incx; ddy=incy; + es =dx; el =dy; + } + + x = xstart; + y = ystart; + err = el/2; + mw_buf_draw_pixel(mwbuf, x, y, clr); + + for (t = 0; t < el; ++t) { + err -= es; + if (err < 0) { + err += el; + x += ddx; + y += ddy; + } else { + x += pdx; + y += pdy; + } + mw_buf_draw_pixel(mwbuf, x, y, clr); + } +} diff --git a/mw_utility.h b/mw_utility.h index 6537360..41e2242 100644 --- a/mw_utility.h +++ b/mw_utility.h @@ -1,7 +1,20 @@ /* * (c) 2011 Siegen, Germany by Nils Faerber * - * license LGPL + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. */ #ifndef _MW_UTILITY_H @@ -17,12 +30,16 @@ typedef struct { typedef enum { MW_BLACK = 0, MW_WHITE, + MW_TRANSPARENT } mw_color; mw_buffer *mw_alloc_pbuffer(unsigned int res_x, unsigned int res_y, unsigned int bpp); void mw_free_pbuffer(mw_buffer *mwbuf); +/* makes a buffer for sending to the watch from the drawing buffer */ +unsigned char *mw_make_mw_buffer(mw_buffer *mwbuf, int *buflen); + void mw_dump_mw_buffer(mw_buffer *mwbuf); @@ -32,6 +49,9 @@ void mw_buf_clear(mw_buffer *mwbuf, mw_color clr); /* draw a single pixel */ void mw_buf_draw_pixel(mw_buffer *mwbuf, unsigned int x, unsigned int y, mw_color clr); +void mw_buf_print(mw_buffer *mwbuf, unsigned int x, unsigned int y, char *text, unsigned char fsize, mw_color fgclr, mw_color bgclr); + +void mw_buf_draw_line_bresenham(mw_buffer *mwbuf, unsigned int xstart, unsigned int ystart, unsigned int xend, unsigned int yend, mw_color clr); #endif -- 2.39.2