##// END OF EJS Templates
Added graphical terminal (first shot).
Added graphical terminal (first shot).

File last commit:

r50:144bdeadc77a dev_alexis
r50:144bdeadc77a dev_alexis
Show More
Terminal.c
144 lines | 4.2 KiB | text/x-c | CLexer
/*------------------------------------------------------------------------------
-- This file is a part of the libuc, microcontroler library
-- Copyright (C) 2013, Alexis Jeandet
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 3 of the License, or
-- (at your option) any later version.
--
-- This program 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 General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-------------------------------------------------------------------------------
-- Author : Alexis Jeandet
-- Mail : alexis.jeandet@gmail.com
-------------------------------------------------------------------------------*/
#include <widget.h>
#include <terminal.h>
#include <stdint.h>
#include <stdio.h>
#include <gpio.h>
#include <core.h>
int __line__ =0;
int __column__=0;
int __lineCount__=0;
int __columnCount__=0;
LCD_t* __LCD__=NULL;
sFONT* __font__;
int __verticalSpace__=2;
int __horizontalSpace__=0;
int __verticalMargins__=5;
int __horizontalMargins__=5;
#define CHARXPOS(charwidth) ((__column__*charwidth)+__horizontalMargins__)
#define CHARYPOS(charheight) ((__line__*charheight)+__verticalMargins__+charheight)
#define charwidth (__font__->Width+__horizontalSpace__)
#define charheight (__font__->Height+__verticalSpace__)
int terminal_init(LCD_t* LCD,sFONT* font,streamdevice* strdev)
{
if((LCD!=NULL) && (font!=NULL) && (strdev!=NULL))
{
__LCD__=LCD;
__font__=font;
__lineCount__ = (LCD->height - (__verticalMargins__*2))/charheight;
__columnCount__ = ((LCD->width - (__horizontalMargins__*2))/charwidth)-1;
strdev->_stream = (UHANDLE)__LCD__;
strdev->write = (write_t)&terminal_write;
strdev->read = (read_t)&terminal_read;
strdev->setpos = (setpos_t)&terminal_setpos;
strdev->streamPt = 0;
__line__ = 0;
__column__ = 0;
__LCD__->paintFilRect(__LCD__,CHARXPOS(charwidth),CHARYPOS(charheight)-charheight,charwidth,charheight,0x0000,0,0x0000);
return 1;
}
return 0;
}
void terminal_movecursor(int n)
{
__column__ += n;
if(__column__>__columnCount__)
{
__line__ += (__column__)/__columnCount__;
__LCD__->paintFilRect(__LCD__,CHARXPOS(charwidth),CHARYPOS(charheight)-charheight,charwidth*(__columnCount__-__column__),charheight,0x0000,0,0x0000);
__line__ = __line__ % __lineCount__;
__column__ = __column__ % __columnCount__;
}
__LCD__->paintFilRect(__LCD__,CHARXPOS(charwidth),CHARYPOS(charheight)-charheight,charwidth,charheight,0x0000,0,0x0000);
}
int terminal_writenc(char* data, int n)
{
int l=0;
char buffer[2]=" ";
while(l<n)
{
buffer[0]=data[l];
if(buffer[0]=='\n')
{
__line__= (__line__+1) % __lineCount__;
__column__ = 0;
}else {
if(buffer[0]=='\t')
{
__line__ += (__column__+3) / __columnCount__;
__column__= (__column__+3) % __columnCount__;
}else {
__LCD__->paintFilRect(__LCD__,CHARXPOS(charwidth),CHARYPOS(charheight)-charheight,charwidth,charheight,0x0000,0,0x0000);
__LCD__->paintText(__LCD__,buffer,CHARXPOS(charwidth),CHARYPOS(charheight),__font__,0xFFFF);
terminal_movecursor(1);
}
}
l++;
}
return n;
}
int terminal_write(streamdeviceptr device,void* data,int size, int n)
{
return terminal_writenc((char*) data,size*n);
}
int terminal_read(streamdeviceptr device,void* data,int size, int n)
{
return n*size;
}
int terminal_setpos(streamdeviceptr device,int pos)
{
return 1;
}
int terminal_close(streamdeviceptr device)
{
return 1;
}