several changes..
authorroot@rika
Thu, 23 Apr 2009 19:10:12 +0200
changeset 307fd00015f62f
parent 29 2723893dc865
child 31 4567e7bc404c
several changes..
graphlcd-base/glcddrivers/Makefile
graphlcd-base/glcddrivers/driver.c
graphlcd-base/glcddrivers/driver.h
graphlcd-base/glcddrivers/drivers.c
graphlcd-base/glcddrivers/picctl.c
graphlcd-base/glcddrivers/picctl.h
graphlcd-base/glcddrivers/port.c
graphlcd-base/glcddrivers/port.h
graphlcd-base/tools/Makefile
graphlcd-base/tools/showpic/showpic.c
     1.1 --- a/graphlcd-base/glcddrivers/Makefile	Mon Mar 30 18:40:54 2009 +0200
     1.2 +++ b/graphlcd-base/glcddrivers/Makefile	Thu Apr 23 19:10:12 2009 +0200
     1.3 @@ -14,7 +14,7 @@
     1.4  
     1.5  LIBNAME = $(BASENAME).$(VERMAJOR).$(VERMINOR).$(VERMICRO)
     1.6  
     1.7 -OBJS = common.o config.o driver.o drivers.o port.o simlcd.o framebuffer.o gu140x32f.o gu256x64-372.o gu256x64-3900.o hd61830.o ks0108.o image.o sed1330.o sed1520.o t6963c.o noritake800.o serdisp.o g15daemon.o network.o gu126x64D-K610A4.o picctl.o avrctl.o
     1.8 +OBJS = common.o config.o driver.o drivers.o port.o simlcd.o framebuffer.o gu140x32f.o gu256x64-372.o gu256x64-3900.o hd61830.o ks0108.o image.o sed1330.o sed1520.o t6963c.o noritake800.o serdisp.o avrctl.o g15daemon.o network.o gu126x64D-K610A4.o picctl.o
     1.9  
    1.10  HEADERS = config.h driver.h drivers.h
    1.11  
    1.12 @@ -38,7 +38,7 @@
    1.13  all: $(LIBNAME)
    1.14  
    1.15  $(LIBNAME): $(OBJS)
    1.16 -	$(CXX) $(CXXFLAGS) -debug -shared $(OBJS) $(LIBS) -ldl -lpthread -Wl,-soname="$(BASENAME).$(VERMAJOR)" -o $@
    1.17 +	$(CXX) $(CXXFLAGS) -shared $(OBJS) $(LIBS) -ldl -lpthread -Wl,-soname="$(BASENAME).$(VERMAJOR)" -o $@
    1.18  	ln -sf $(LIBNAME) $(BASENAME)
    1.19  
    1.20  install: all
     2.1 --- a/graphlcd-base/glcddrivers/driver.c	Mon Mar 30 18:40:54 2009 +0200
     2.2 +++ b/graphlcd-base/glcddrivers/driver.c	Thu Apr 23 19:10:12 2009 +0200
     2.3 @@ -50,5 +50,14 @@
     2.4          }
     2.5      }
     2.6  }
     2.7 +int cDriver::GetKey()
     2.8 +{
     2.9 +    return(-1);
    2.10 +}
    2.11 +
    2.12 +bool cDriver::HasKeys()
    2.13 +{
    2.14 +    return(false);
    2.15 +}
    2.16  
    2.17  } // end of namespace
     3.1 --- a/graphlcd-base/glcddrivers/driver.h	Mon Mar 30 18:40:54 2009 +0200
     3.2 +++ b/graphlcd-base/glcddrivers/driver.h	Thu Apr 23 19:10:12 2009 +0200
     3.3 @@ -39,8 +39,10 @@
     3.4      virtual void Set8Pixels(int x, int y, unsigned char data) {}
     3.5      virtual void SetScreen(const unsigned char * data, int width, int height, int lineSize);
     3.6      virtual void Refresh(bool refreshAll = false) {}
     3.7 +    virtual void SetBrightness(unsigned int percent) {}
     3.8 +    virtual bool HasKeys(); 
     3.9 +    virtual int  GetKey(); 
    3.10  
    3.11 -    virtual void SetBrightness(unsigned int percent) {}
    3.12  };
    3.13  
    3.14  } // end of namespace
     4.1 --- a/graphlcd-base/glcddrivers/drivers.c	Mon Mar 30 18:40:54 2009 +0200
     4.2 +++ b/graphlcd-base/glcddrivers/drivers.c	Thu Apr 23 19:10:12 2009 +0200
     4.3 @@ -103,7 +103,7 @@
     4.4          case kDriverAvrCtl:
     4.5              return new cDriverAvrCtl(config);
     4.6          case kDriverPICCtl:
     4.7 -            return cDriverPICCtl::getInstance(config);
     4.8 +            return new cDriverPICCtl(config);
     4.9          case kDriverNetwork:
    4.10              return new cDriverNetwork(config);
    4.11          case kDriverGU126X64D_K610A4:
     5.1 --- a/graphlcd-base/glcddrivers/picctl.c	Mon Mar 30 18:40:54 2009 +0200
     5.2 +++ b/graphlcd-base/glcddrivers/picctl.c	Thu Apr 23 19:10:12 2009 +0200
     5.3 @@ -13,6 +13,7 @@
     5.4  #include <stdint.h>
     5.5  #include <syslog.h>
     5.6  #include <math.h>
     5.7 +#include <signal.h>
     5.8  
     5.9  #include "common.h"
    5.10  #include "config.h"
    5.11 @@ -60,25 +61,6 @@
    5.12  const unsigned char CMD_BOOT =			0x80;
    5.13  
    5.14  
    5.15 -// globals...
    5.16 -uint8_t cDriverPICCtl::buf[255];
    5.17 -uint8_t cDriverPICCtl::buf_pos;
    5.18 -uint8_t cDriverPICCtl::buf_cmd_start;
    5.19 -bool cDriverPICCtl::buf_flag_escape;
    5.20 -
    5.21 -// singleton
    5.22 -cDriverPICCtl* cDriverPICCtl::instance = NULL;
    5.23 -
    5.24 -cDriverPICCtl* cDriverPICCtl::getInstance(cDriverConfig * config)
    5.25 -{
    5.26 -    if (!instance)
    5.27 -        instance = new cDriverPICCtl(config);
    5.28 -    return instance;
    5.29 -}
    5.30 -// end singleton-pattern
    5.31 -
    5.32 -
    5.33 -
    5.34  cDriverPICCtl::cDriverPICCtl(cDriverConfig * config)
    5.35  :   config(config)
    5.36  {
    5.37 @@ -95,36 +77,59 @@
    5.38      buf_pos = 0;
    5.39      buf_cmd_start = 255;
    5.40      buf_flag_escape = false;
    5.41 +
    5.42 +    keys_pos  = 0;
    5.43 +    keys_pos_ = 0;
    5.44  }
    5.45  
    5.46  cDriverPICCtl::~cDriverPICCtl()
    5.47  {
    5.48 -    instance = NULL;
    5.49 -
    5.50      delete port;
    5.51      port = NULL;
    5.52      delete oldConfig;
    5.53      oldConfig = NULL;
    5.54  }
    5.55  
    5.56 -void cDriverPICCtl::SignalHandler(int signal)
    5.57 -{
    5.58 -    //uint8_t i;
    5.59 -
    5.60 +bool cDriverPICCtl::HasKeys()
    5.61 +{
    5.62 +    return true;
    5.63 +}
    5.64 +
    5.65 +int cDriverPICCtl::GetKey()
    5.66 +{
    5.67 +    InputHandler();
    5.68 +
    5.69 +    if (keys_pos != keys_pos_)
    5.70 +    {
    5.71 +        keys_pos_ = keys_pos;
    5.72 +        return(keys[keys_pos-1]);
    5.73 +    }
    5.74 +    else
    5.75 +    {
    5.76 +        return(-1);
    5.77 +    }
    5.78 +
    5.79 +}
    5.80 +
    5.81 +void cDriverPICCtl::InputHandler()
    5.82 +{
    5.83      // read all available data (always get single bytes...)
    5.84 -    while (instance->port->ReadData(&buf[buf_pos]) > 0)
    5.85 +    while (port->ReadData(&buf[buf_pos]) > 0)
    5.86      {
    5.87          // search for SYNC byte
    5.88          if ((buf[buf_pos] == CMD_SYNC_RECV) && (!buf_flag_escape))
    5.89  	{
    5.90  	    if (buf_cmd_start != 255)
    5.91  	    {
    5.92 -		/*printf("Damaged Packet: ");
    5.93 +	    	#ifdef DEBUG
    5.94 +    		uint8_t i;
    5.95 +		printf("Damaged Packet: ");
    5.96  	        for (i=buf_cmd_start; i<buf_pos; i++)
    5.97  		{
    5.98  		  printf("0x%02x ",buf[i]);
    5.99  		}
   5.100 -		printf("; buf_pos = %d, buf_cmd_start = %d\n",buf_pos,buf_cmd_start);*/
   5.101 +		printf("; buf_pos = %d, buf_cmd_start = %d\n",buf_pos,buf_cmd_start);
   5.102 +		#endif
   5.103  
   5.104                  syslog(LOG_INFO, "PICCtl received a malformed packet. Scrapped %d bytes\n",(buf_pos - buf_cmd_start));
   5.105  		buf_pos = 0;
   5.106 @@ -134,18 +139,15 @@
   5.107  	}
   5.108  
   5.109  
   5.110 -        if ((buf[buf_pos] == CMD_ESCAPE_BYTE) && (!buf_flag_escape))
   5.111 +	// escaping is not used so far...
   5.112 +/*        if ((buf[buf_pos] == CMD_ESCAPE_BYTE) && (!buf_flag_escape))
   5.113  	{
   5.114  	    // this byte was for masking only.. ignore it! 
   5.115  	    buf_flag_escape = true;
   5.116  	    continue;
   5.117  	} 
   5.118 -        buf_flag_escape = false;
   5.119 -
   5.120 -/*        printf("buf: ");
   5.121 -        for (i=1; i<=buf_pos; i++) { printf("0x%02x ",buf[i]);}
   5.122 -	printf("\n");*/
   5.123 -        
   5.124 +        buf_flag_escape = false;*/
   5.125 +
   5.126  	buf_pos++;
   5.127  
   5.128          // we need to check for a valid packet...
   5.129 @@ -154,7 +156,7 @@
   5.130              // if we recieved a valid packet: start decoding
   5.131  	    if (buf[buf_cmd_start + CMD_HDR_LENGTH+1] == (buf_pos - buf_cmd_start - CMD_DATA_START))
   5.132  	    {
   5.133 -	        instance->DecodeCmd(&buf[buf_cmd_start],buf_pos);
   5.134 +	        DecodeCmd(&buf[buf_cmd_start],buf_pos);
   5.135  		buf_pos = 0;
   5.136  		buf_cmd_start = 255;
   5.137  	    }
   5.138 @@ -163,21 +165,25 @@
   5.139      }
   5.140  }
   5.141  
   5.142 -
   5.143  void cDriverPICCtl::DecodeCmd(uint8_t * cmd, uint8_t len)
   5.144  {
   5.145 -/*    uint8_t i;
   5.146 +    #ifdef DEBUG
   5.147 +    uint8_t i;
   5.148      printf("cmd(%2d): ",len);
   5.149      for (i=0; i<len; i++) { printf("0x%02x ",cmd[i]);}
   5.150 -    printf("\n"); */
   5.151 +    printf("\n");
   5.152 +    #endif
   5.153  
   5.154      switch (cmd[CMD_HDR_COMMAND])
   5.155      {
   5.156          case CMD_SYS_ACK:	ack_flag = true;
   5.157  	 			break;
   5.158  
   5.159 -	case CMD_SYS_IR:	syslog(LOG_INFO," %s: incoming Key-Event 0x%02x (Source 0x%02x)\n",config->name.c_str(), cmd[CMD_DATA_START+1], cmd[CMD_DATA_START]);
   5.160 -	                         //printf(" %s: incoming Key-Event 0x%02x (Source 0x%02x)\n",config->name.c_str(), cmd[CMD_DATA_START+1], cmd[CMD_DATA_START]);
   5.161 +	case CMD_SYS_IR:	keys[keys_pos] =   256 * cmd[CMD_DATA_START] + cmd[CMD_DATA_START+1];
   5.162 +				keys_pos++;
   5.163 +				#ifdef DEBUG
   5.164 +				printf(" %s: recieved IR Command 0x%x \n",config->name.c_str(), cmd[CMD_DATA_START+1]);
   5.165 +				#endif
   5.166  	  			break;
   5.167  
   5.168  	default:		syslog(LOG_INFO," %s: recieved Message 0x%x \n",config->name.c_str(), cmd[CMD_HDR_COMMAND]);
   5.169 @@ -226,7 +232,7 @@
   5.170      {
   5.171          return -1;
   5.172      }
   5.173 -    if (port->Open(config->device.c_str(), SignalHandler) != 0)
   5.174 +    if (port->Open(config->device.c_str()) != 0)
   5.175          return -1;
   5.176  
   5.177      *oldConfig = *config;
   5.178 @@ -235,7 +241,6 @@
   5.179      Clear();
   5.180      CmdDispClearScreen();
   5.181      CmdDispSetManaged();
   5.182 -//    CmdDispSetBrightness(50);
   5.183  
   5.184      syslog(LOG_INFO, "%s: PICCtl initialized.\n", config->name.c_str());
   5.185      return 0;
   5.186 @@ -244,6 +249,10 @@
   5.187  int cDriverPICCtl::DeInit()
   5.188  {
   5.189      int y;
   5.190 +    
   5.191 +    CmdDispSetUnManaged();
   5.192 +    CmdDispClearScreen();
   5.193 +
   5.194      // free lcd array (wanted state)
   5.195      if (newLCD)
   5.196      {
   5.197 @@ -263,7 +272,6 @@
   5.198          delete[] oldLCD;
   5.199      }
   5.200  
   5.201 -    CmdDispSetUnManaged();
   5.202      
   5.203      if (port->Close() != 0)
   5.204          return -1;
   5.205 @@ -362,21 +370,29 @@
   5.206      CmdDispSetBrightness(percent);
   5.207  }
   5.208  
   5.209 -void cDriverPICCtl::SetClock(unsigned int percent)
   5.210 -{
   5.211 -    CmdDispSetBrightness(percent);
   5.212 -}
   5.213 -
   5.214  int cDriverPICCtl::WaitForAck(void)
   5.215  {
   5.216      int timeout;
   5.217  
   5.218      for (timeout=0; timeout<1000; timeout++)
   5.219      {
   5.220 +        InputHandler();
   5.221      	usleep(100);
   5.222  	if (ack_flag) return 0;
   5.223      }
   5.224      syslog(LOG_INFO, "%s: PICCtl missed a ACK packet!\n", config->name.c_str());
   5.225 +
   5.226 +
   5.227 +#ifdef DEBUG
   5.228 +    int i;
   5.229 +    printf("%s: PICCtl missed a ACK packet!\n", config->name.c_str());
   5.230 +    for (i=0; i<buf_pos; i++)
   5.231 +    {
   5.232 +      printf("0x%02x ",buf[i]);
   5.233 +    }
   5.234 +    printf("; buf_pos = %d, buf_cmd_start = %d\n",buf_pos,buf_cmd_start);
   5.235 +#endif
   5.236 +
   5.237      return 1;
   5.238  }
   5.239  
     6.1 --- a/graphlcd-base/glcddrivers/picctl.h	Mon Mar 30 18:40:54 2009 +0200
     6.2 +++ b/graphlcd-base/glcddrivers/picctl.h	Thu Apr 23 19:10:12 2009 +0200
     6.3 @@ -29,8 +29,6 @@
     6.4      unsigned char ** oldLCD; // current state
     6.5      cDriverConfig * config;
     6.6      cDriverConfig * oldConfig;
     6.7 -    int refreshCounter;
     6.8 -    bool ack_flag;
     6.9  
    6.10      int WaitForAck(void);
    6.11      void CmdDispClearScreen(void);
    6.12 @@ -39,19 +37,21 @@
    6.13      void CmdDispSetUnManaged(void);
    6.14      void CmdDispSetBrightness(uint8_t percent);
    6.15      void CmdDispSetColData(uint8_t yoffset, uint8_t xoffset, uint8_t length, uint8_t * data);
    6.16 +    int  CheckSetup();
    6.17      void DecodeCmd(uint8_t * cmd, uint8_t len);
    6.18 +    void InputHandler();
    6.19  
    6.20 -    int CheckSetup();
    6.21 +    uint8_t buf[255];
    6.22 +    uint8_t buf_pos;
    6.23 +    uint8_t buf_cmd_start;
    6.24 +    bool    buf_flag_escape;
    6.25 +    int     keys[255];
    6.26 +    uint8_t keys_pos;
    6.27 +    uint8_t keys_pos_;
    6.28 +    
    6.29 +    int  refreshCounter;
    6.30 +    bool ack_flag;
    6.31  
    6.32 -    static void SignalHandler(int signal);
    6.33 -    static uint8_t buf[255];
    6.34 -    static uint8_t buf_pos;
    6.35 -    static uint8_t buf_cmd_start;
    6.36 -    static bool buf_flag_escape;
    6.37 -
    6.38 -// singleton
    6.39 -    static cDriverPICCtl* instance;		// die EINE instant
    6.40 -    cDriverPICCtl(cDriverConfig * config);	// Konstruktor
    6.41  
    6.42  public:
    6.43      virtual int Init();
    6.44 @@ -61,11 +61,11 @@
    6.45      virtual void Set8Pixels(int x, int y, unsigned char data);
    6.46      virtual void Refresh(bool refreshAll = false);
    6.47      virtual void SetBrightness(unsigned int percent);
    6.48 -    virtual void SetClock(unsigned int percent);
    6.49 +    virtual int  GetKey();
    6.50 +    virtual bool HasKeys();
    6.51  
    6.52 -// singleton
    6.53 +    cDriverPICCtl(cDriverConfig * config);	// Konstruktor
    6.54      virtual ~cDriverPICCtl();			// Destruktor
    6.55 -    static cDriverPICCtl* getInstance(cDriverConfig * config);
    6.56  };
    6.57  
    6.58  } // end of namespace
     7.1 --- a/graphlcd-base/glcddrivers/port.c	Mon Mar 30 18:40:54 2009 +0200
     7.2 +++ b/graphlcd-base/glcddrivers/port.c	Thu Apr 23 19:10:12 2009 +0200
     7.3 @@ -16,19 +16,12 @@
     7.4  #include <syslog.h>
     7.5  #include <unistd.h>
     7.6  #include <termios.h>
     7.7 -#include <signal.h>
     7.8  #include <sys/io.h>
     7.9  #include <sys/ioctl.h>
    7.10  #include <linux/ppdev.h>
    7.11  #include <linux/parport.h>
    7.12 -
    7.13 -
    7.14 -
    7.15  #include "port.h"
    7.16  
    7.17 -
    7.18 -
    7.19 -
    7.20  namespace GLCD
    7.21  {
    7.22  
    7.23 @@ -286,34 +279,6 @@
    7.24  {
    7.25  }
    7.26  
    7.27 -int cSerialPort::Open(const char * device, void (*FP)(int))
    7.28 -{
    7.29 -    struct sigaction saio;
    7.30 -
    7.31 -    if (FP == NULL) {
    7.32 -        return -1;
    7.33 -    }
    7.34 -
    7.35 -    if (Open(device) == 0) {
    7.36 -    	// install the signal handler before making the device asynchronous/
    7.37 -    	saio.sa_handler = FP;
    7.38 -    	sigemptyset (&saio.sa_mask);
    7.39 -    	saio.sa_flags = 0;
    7.40 -    	saio.sa_restorer = NULL;
    7.41 -    	sigaction(SIGIO,&saio,NULL);
    7.42 -    
    7.43 -    	// allow the process to receive SIGIO
    7.44 -    	fcntl(fd, F_SETOWN, getpid());
    7.45 -    	// Make the file descriptor asynchronous 
    7.46 -    	fcntl(fd, F_SETFL, FASYNC | O_NONBLOCK);
    7.47 -
    7.48 -    	return(0);
    7.49 -    }
    7.50 -    else {
    7.51 -    	return -1;
    7.52 -    }
    7.53 -}
    7.54 -
    7.55  int cSerialPort::Open(const char * device)
    7.56  {
    7.57      struct termios options;
    7.58 @@ -352,17 +317,9 @@
    7.59  
    7.60  int cSerialPort::Close()
    7.61  {
    7.62 -    struct sigaction saio;
    7.63      if (fd == -1)
    7.64          return -1;
    7.65      close(fd);
    7.66 -    
    7.67 -    saio.sa_handler = NULL;
    7.68 -    sigemptyset (&saio.sa_mask);
    7.69 -    saio.sa_flags = 0;
    7.70 -    saio.sa_restorer = NULL;
    7.71 -    sigaction(SIGIO,&saio,NULL);
    7.72 -
    7.73      return 0;
    7.74  }
    7.75  
    7.76 @@ -383,7 +340,6 @@
    7.77      if (fd == -1)
    7.78          return;
    7.79      write(fd, data, length);
    7.80 -//    for (int x=0; x<length; x++)   printf("0x%x ",data[x]);
    7.81  }
    7.82  
    7.83  
     8.1 --- a/graphlcd-base/glcddrivers/port.h	Mon Mar 30 18:40:54 2009 +0200
     8.2 +++ b/graphlcd-base/glcddrivers/port.h	Thu Apr 23 19:10:12 2009 +0200
     8.3 @@ -65,7 +65,6 @@
     8.4      cSerialPort();
     8.5      ~cSerialPort();
     8.6  
     8.7 -    int Open(const char * device, void (*FP)(int));
     8.8      int Open(const char * device);
     8.9      int Close();
    8.10  
     9.1 --- a/graphlcd-base/tools/Makefile	Mon Mar 30 18:40:54 2009 +0200
     9.2 +++ b/graphlcd-base/tools/Makefile	Thu Apr 23 19:10:12 2009 +0200
     9.3 @@ -10,9 +10,6 @@
     9.4  all:
     9.5  	@$(MAKE) -C convpic all
     9.6  	@$(MAKE) -C crtfont all
     9.7 -ifdef HAVE_FREETYPE2
     9.8 -	@$(MAKE) -C genfont all
     9.9 -endif
    9.10  	@$(MAKE) -C showpic all
    9.11  	@$(MAKE) -C showtext all
    9.12  	@$(MAKE) -C lcdtestpattern all
    9.13 @@ -20,9 +17,6 @@
    9.14  install:
    9.15  	@$(MAKE) -C convpic install
    9.16  	@$(MAKE) -C crtfont install
    9.17 -ifdef HAVE_FREETYPE2
    9.18 -	@$(MAKE) -C genfont install
    9.19 -endif
    9.20  	@$(MAKE) -C showpic install
    9.21  	@$(MAKE) -C showtext install
    9.22  	@$(MAKE) -C lcdtestpattern install
    10.1 --- a/graphlcd-base/tools/showpic/showpic.c	Mon Mar 30 18:40:54 2009 +0200
    10.2 +++ b/graphlcd-base/tools/showpic/showpic.c	Thu Apr 23 19:10:12 2009 +0200
    10.3 @@ -199,7 +199,8 @@
    10.4  		delete lcd;
    10.5  		return 7;
    10.6  	}
    10.7 -  lcd->SetBrightness(GLCD::Config.driverConfigs[displayNumber].brightness);
    10.8 +	lcd->SetBrightness(GLCD::Config.driverConfigs[displayNumber].brightness);
    10.9 +	printf("keys = %d\n",lcd->GetKey());
   10.10  
   10.11  	signal(SIGINT, sighandler);
   10.12  	signal(SIGQUIT, sighandler);
   10.13 @@ -228,6 +229,7 @@
   10.14  		while ((bitmap = image.GetBitmap()) != NULL && !stopProgramm)
   10.15  		{
   10.16  			lcd->SetScreen(bitmap->Data(), bitmap->Width(), bitmap->Height(), bitmap->LineSize());
   10.17 +			printf("keys = %d\n",lcd->GetKey());
   10.18  			lcd->Refresh(true);
   10.19  
   10.20  			if (image.Next(0)) // Select next image