aboutsummaryrefslogtreecommitdiffstats
AgeCommit message (Expand)AuthorFilesLines
2007-02-04picoLCD driver bugs fixedmichael2-101/+90
2007-01-23drv_picoLCD was missing in distributionmichael2-0/+3
2007-01-23removed -SVN from version stringmichael2-11/+11
2007-01-23try to add svn versionmichael6-11/+43
2007-01-21indentmichael1-5/+5
2007-01-21new function 'decode()'michael3-1/+25
2007-01-21removed unused variablemichael1-1/+0
2007-01-20keypad widget cleanupmichael2-22/+16
2007-01-20GPO cleanupmichael3-7/+4
2007-01-20minor fixes to evaluatormichael2-2/+10
2007-01-20dynamic properties for bars; new 'property_valid()' helpermichael13-65/+104
2007-01-20indentmichael6-12/+0
2007-01-19driver for picoLCD displays from mini-box.com by Nicu Pavelmichael5-2/+541
2007-01-19dynamic properties for keypad widgetmichael2-29/+14
2007-01-19indentmichael2-5/+5
2007-01-18dynamic properties for Icon widgetmichael4-51/+32
2007-01-17dynamic properties for GPO'smichael2-33/+26
2007-01-17removed DOS newlines again :-(michael1-60/+61
2007-01-17indentmichael2-9/+8
2007-01-17changed version number from 0.10.1-CVS to 0.10.1-SVNmichael2-12/+12
2007-01-16new driver 'HD44780-I2C'michael4-8/+97
2007-01-16Fix compilation of plugin_wireless.c with linux kernel 2.6.19 from Guillaume ...michael1-0/+1
2007-01-16Patch from Robert Buchholz: NULL driver link error fixed, m4 files included i...michael4-0/+8
2007-01-16patch from Mattia Jona-Lasinio for lcd-linux 0.12.0michael1-25/+24
2007-01-16svn keywordsmichael1-2/+2
2007-01-16removed some DOS newlinesmichael1-7/+8
2007-01-15minor cosmetic changes and fixesmichael5-11/+5
2007-01-14re-bootstrappedmichael4-10/+284
2007-01-14svn keywords correctedmichael1-1/+2
2007-01-14svn keywords correctedmichael6-47/+5
2007-01-14added svn properties and keywordsmichael14-320/+53
2007-01-14changed $Revision to $Revmichael28-28/+28
2007-01-14removed all tagsmichael125-6749/+0
2007-01-14svn properties fixedmichael132-153/+282
2007-01-14svn:ignore ported from .cvsignoremichael0-0/+0
2007-01-14switch from CVS to SVNmichael6-1658/+511
2006-10-01[lcd4linux @ 2006-10-01 11:54:38 by reinelt]reinelt3-60/+41
2006-09-29[lcd4linux @ 2006-09-29 04:48:21 by reinelt]reinelt8-240/+350
2006-10-04image widget memory leaks fixed (thanks to Magne Torresen)root1-22/+25
2006-09-19[lcd4linux @ 2006-09-19 11:20:52 by entropy]entropy1-1/+6
2006-09-15[lcd4linux @ 2006-09-15 20:30:03 by siretart]siretart3-87/+1987
2006-09-15[lcd4linux @ 2006-09-15 19:06:47 by entropy]entropy1-3/+7
2006-09-15[lcd4linux @ 2006-09-15 19:00:50 by entropy]entropy5-1/+180
2006-09-14[lcd4linux @ 2006-09-14 20:36:39 by entropy]entropy1-5/+45
2006-09-14[lcd4linux @ 2006-09-14 11:19:29 by entropy]entropy1-8/+15
2006-09-14[lcd4linux @ 2006-09-14 04:08:54 by reinelt]reinelt1-32/+22
2006-09-14[lcd4linux @ 2006-09-14 03:49:14 by reinelt]reinelt5-16/+32
2006-09-13[lcd4linux @ 2006-09-13 20:07:59 by entropy]entropy1-1/+11
2006-09-13[lcd4linux @ 2006-09-13 20:04:57 by entropy]entropy3-4/+29
2006-09-13[lcd4linux @ 2006-09-13 05:33:39 by reinelt]reinelt2-3/+10
r: #888888 } /* Comment */ .highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */ .highlight .k { color: #008800; font-weight: bold } /* Keyword */ .highlight .ch { color: #888888 } /* Comment.Hashbang */ .highlight .cm { color: #888888 } /* Comment.Multiline */ .highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/* $Id: bar.c,v 1.9 2003/10/05 17:58:50 reinelt Exp $
 *
 * generic bar handling
 *
 * Copyright 2002 Michael Reinelt <reinelt@eunet.at>
 *
 * This file is part of LCD4Linux.
 *
 * LCD4Linux 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 2, or (at your option)
 * any later version.
 *
 * LCD4Linux 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., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *
 * $Log: bar.c,v $
 * Revision 1.9  2003/10/05 17:58:50  reinelt
 * libtool junk; copyright messages cleaned up
 *
 * Revision 1.8  2003/09/09 05:30:34  reinelt
 * even more icons stuff
 *
 * Revision 1.7  2003/09/01 04:09:34  reinelt
 * icons nearly finished, but MatrixOrbital only
 *
 * Revision 1.6  2003/08/20 05:26:43  reinelt
 * small bug in bar compaction fixed
 *
 * Revision 1.5  2003/08/19 04:28:41  reinelt
 * more Icon stuff, minor glitches fixed
 *
 * Revision 1.4  2003/01/12 06:51:27  reinelt
 * fixed bug in bar compaction
 *
 * Revision 1.3  2002/08/19 07:52:19  reinelt
 * corrected type declaration of (*defchar)()
 *
 * Revision 1.2  2002/08/19 07:36:29  reinelt
 *
 * finished bar.c, USBLCD is the first driver that uses the generic bar functions
 *
 * Revision 1.1  2002/08/19 04:41:20  reinelt
 * introduced bar.c, moved bar stuff from display.h to bar.h
 *
 *
 */

/* 
 * exported functions:
 *
 * int bar_init (int rows, int cols, int xres, int yres, int chars)
 *
 * void bar_clear(void)
 *
 * void bar_add_segment(int len1, int len2, int type, int ascii)
 *
 * int bar_draw (int type, int row, int col, int max, int len1, int len2)
 *
 * int bar_process (void(*defchar)(int ascii, char *matrix))
 *
 * int bar_peek (int row, int col)
 *
 */

#include <stdlib.h>

#include "bar.h"
#include "debug.h"


static int ROWS=0;
static int COLS=0;
static int XRES=0;
static int YRES=0;
static int CHARS=0;

static int nSegment=0;
static int fSegment=0;
static SEGMENT Segment[128];

static BAR *Bar=NULL;


int bar_init (int rows, int cols, int xres, int yres, int chars)
{
  if (rows<1 || cols<1) 
    return -1;
  
  ROWS=rows;
  COLS=cols;
  XRES=xres;
  YRES=yres;
  CHARS=chars;

  if (Bar) {
    free (Bar);
  }
  
  if ((Bar=malloc (ROWS*COLS*sizeof(BAR)))==NULL) {
    error ("bar buffer allocation failed: out of memory");
    return -1;
  }

  bar_clear();

  nSegment=0;
  fSegment=0;

  return 0;
}


void bar_clear(void)
{
  int n;

  for (n=0; n<ROWS*COLS; n++) {
    Bar[n].len1=-1;
    Bar[n].len2=-1;
    Bar[n].type=0;
    Bar[n].segment=-1;
  }

}


void bar_add_segment(int len1, int len2, int type, int ascii)
{
  Segment[fSegment].len1=len1;
  Segment[fSegment].len2=len2;
  Segment[fSegment].type=type;
  Segment[fSegment].used=0;
  Segment[fSegment].ascii=ascii;
  
  fSegment++;
  nSegment=fSegment;
}


int bar_draw (int type, int row, int col, int max, int len1, int len2)
{
  int rev=0;
  
  if (len1<1) len1=1;
  else if (len1>max) len1=max;
  
  if (len2<1) len2=1;
  else if (len2>max) len2=max;
  
  switch (type) {
  case BAR_L:
    len1=max-len1;
    len2=max-len2;
    rev=1;
    
  case BAR_R:
    while (max>0 && col<COLS) {
      Bar[row*COLS+col].type=type;
      Bar[row*COLS+col].segment=-1;
      if (len1>=XRES) {
	Bar[row*COLS+col].len1=rev?0:XRES;
	len1-=XRES;
      } else {
	Bar[row*COLS+col].len1=rev?XRES-len1:len1;
	len1=0;
      }
      if (len2>=XRES) {
	Bar[row*COLS+col].len2=rev?0:XRES;
	len2-=XRES;
      } else {
	Bar[row*COLS+col].len2=rev?XRES-len2:len2;
	len2=0;
      }
      max-=XRES;
      col++;
    }
    break;

  case BAR_U:
    len1=max-len1;
    len2=max-len2;
    rev=1;
    
  case BAR_D:
    while (max>0 && row<ROWS) {
      Bar[row*COLS+col].type=type;
      Bar[row*COLS+col].segment=-1;
      if (len1>=YRES) {
	Bar[row*COLS+col].len1=rev?0:YRES;
	len1-=YRES;
      } else {
	Bar[row*COLS+col].len1=rev?YRES-len1:len1;
	len1=0;
      }
      if (len2>=YRES) {
	Bar[row*COLS+col].len2=rev?0:YRES;
	len2-=YRES;
      } else {
	Bar[row*COLS+col].len2=rev?YRES-len2:len2;
	len2=0;
      }
      max-=YRES;
      row++;
    }
    break;

  }
  return 0;
}


static void create_segments (void)
{
  int RES;
  int i, j, n;
  int l1, l2;

  /* find first unused segment */
  for (i=fSegment; i<nSegment && Segment[i].used; i++);

  /* pack unused segments */
  for (j=i+1; j<nSegment; j++) {
    if (Segment[j].used)
      Segment[i++]=Segment[j];
  }
  nSegment=i;
  
  /* create needed segments */
  for (n=0; n<ROWS*COLS; n++) {
    if (Bar[n].type==0) continue;
    RES=Bar[n].type & BAR_H ? XRES:YRES;
    for (i=0; i<nSegment; i++) {
      if (Segment[i].type & Bar[n].type) {
	l1=Segment[i].len1; if (l1>RES) l1=RES;
	l2=Segment[i].len2; if (l2>RES) l2=RES;
	if (l1 == Bar[n].len1 && l2 == Bar[n].len2) break;
      }
    }
    if (i==nSegment) {
      nSegment++;
      Segment[i].len1=Bar[n].len1;
      Segment[i].len2=Bar[n].len2;
      Segment[i].type=Bar[n].type;
      Segment[i].used=0;
      Segment[i].ascii=-1;
    }
    Bar[n].segment=i;
  }
}


static int segment_deviation (int i, int j)
{
  int RES;
  int i1, i2, j1, j2;
  
  if (i==j) return 65535;
  if (!(Segment[i].type & Segment[j].type)) return 65535;

  RES=Segment[i].type & BAR_H ? XRES:YRES;

  i1=Segment[i].len1; if (i1>RES) i1=RES;
  i2=Segment[i].len2; if (i2>RES) i2=RES;
  j1=Segment[j].len1; if (j1>RES) j1=RES;
  j2=Segment[j].len2; if (j2>RES) j2=RES;
  
  if (i1==0   && j1!=0)  return 65535;
  if (i2==0   && j2!=0)  return 65535;
  if (i1==RES && j1<RES) return 65535;
  if (i2==RES && j2<RES) return 65535;
  if (i1==1   && j1!=1 && i2 > 0)  return 65535;
  if (i2==1   && j2!=1 && j1 > 0)  return 65535;
  if (i1==i2  && j1!=j2) return 65535;

  return (i1-j1)*(i1-j1)+(i2-j2)*(i2-j2);
}


static void pack_segments (void)
{
  int i, j, n, min;
  int pack_i, pack_j;
  int pass1=1;
  int deviation[nSegment][nSegment];

  if (nSegment<=fSegment+CHARS) {
    return;
  }

  for (i=0; i<nSegment; i++) {
    for (j=0; j<nSegment; j++) {
      deviation[i][j]=segment_deviation(i,j);
    }
  }
    
  while (nSegment>fSegment+CHARS) {
    min=65535;
    pack_i=-1;
    pack_j=-1;
    for (i=fSegment; i<nSegment; i++) {
      if (pass1 && Segment[i].used) continue;
      for (j=0; j<nSegment; j++) {
	if (deviation[i][j]<min) {
	  min=deviation[i][j];
	  pack_i=i;
	  pack_j=j;
	}
      }
    }
    if (pack_i==-1) {
      if (pass1) {
	pass1=0;
	continue;
      } else {
	error ("unable to compact bar characters");
	nSegment=CHARS;
	break;
      }
    } 

#if 0
    debug ("pack_segment: n=%d i=%d j=%d min=%d", nSegment, pack_i, pack_j, min);
    debug ("Pack_segment: i1=%d i2=%d j1=%d j2=%d\n", 
	   Segment[pack_i].len1, Segment[pack_i].len2, 
	   Segment[pack_j].len1, Segment[pack_j].len2);
#endif
    
    nSegment--;
    Segment[pack_i]=Segment[nSegment];
      
    for (i=0; i<nSegment; i++) {
      deviation[pack_i][i]=deviation[nSegment][i];
      deviation[i][pack_i]=deviation[i][nSegment];
    }
      
    for (n=0; n<ROWS*COLS; n++) {
      if (Bar[n].segment==pack_i)   Bar[n].segment=pack_j;
      if (Bar[n].segment==nSegment) Bar[n].segment=pack_i;
    }
  }
}


static void define_chars (void(*defchar)(int ascii, char *matrix))
{
  int c, i, j;
  char buffer[8];

  for (i=fSegment; i<nSegment; i++) {
    if (Segment[i].used) continue;
    if (Segment[i].ascii!=-1) continue;
    for (c=0; c<CHARS; c++) {
      for (j=fSegment; j<nSegment; j++) {
	if (Segment[j].ascii==c) break;
      }
      if (j==nSegment) break;
    }
    Segment[i].ascii=c;
    switch (Segment[i].type) {
    case BAR_L:
      for (j=0; j<4; j++) {
#if 0
	char Pixel[] = { 0, 1, 3, 7, 15, 31 };
	buffer[j  ]=Pixel[Segment[i].len1];
	buffer[j+4]=Pixel[Segment[i].len2];
#else
	buffer[j  ]=(1<<Segment[i].len1)-1;
	buffer[j+4]=(1<<Segment[i].len2)-1;
#endif
      }
      break;
    case BAR_R:
      for (j=0; j<4; j++) {
#if 0
	char Pixel[] = { 0, 16, 24, 28, 30, 31 };
	buffer[j  ]=Pixel[Segment[i].len1];
	buffer[j+4]=Pixel[Segment[i].len2];
#else
	buffer[j  ]=255<<(XRES-Segment[i].len1);
	buffer[j+4]=255<<(XRES-Segment[i].len2);
#endif
      }
      break;
    case BAR_U:
      for (j=0; j<Segment[i].len1; j++) {
	buffer[7-j]=(1<<XRES)-1;
      }
      for (; j<YRES; j++) {
	buffer[7-j]=0;
      }
      break;
    case BAR_D:
      for (j=0; j<Segment[i].len1; j++) {
	buffer[j]=(1<<XRES)-1;
      }
      for (; j<YRES; j++) {
	buffer[j]=0;
      }
      break;
    }
    defchar(c, buffer);
  }
}


int bar_process (void(*defchar)(int ascii, char *matrix))
{
  int n, s;
  
  create_segments();
  pack_segments();
  define_chars(defchar);
  
  for (s=0; s<nSegment; s++) {
    Segment[s].used=0;
  }

  for (n=0; n<ROWS*COLS; n++) {
    s=Bar[n].segment;
    if (s!=-1) {
      Segment[s].used=1;
    }
  }
  
  return 0;
}


int bar_peek (int row, int col)
{
  int s;

  s=Bar[row*COLS+col].segment;
  if (s==-1) {
    return -1;
  } else {
    return Segment[s].ascii;
  }
}