GP1212A02: Implement commands for: font char update, font action and hard reset.
authorsl
Sat, 06 Sep 2014 15:54:51 +0200
changeset 203b7acc7fb64b
parent 19 9f659cde9ee8
child 21 fa7c9f9140aa
GP1212A02: Implement commands for: font char update, font action and hard reset.
FutabaGP1212A02.cpp
FutabaGP1212A02.h
     1.1 --- a/FutabaGP1212A02.cpp	Sat Sep 06 13:28:22 2014 +0200
     1.2 +++ b/FutabaGP1212A02.cpp	Sat Sep 06 15:54:51 2014 +0200
     1.3 @@ -10,6 +10,13 @@
     1.4  const unsigned short KMaxDataMemoryAddress = 0x4FFF;
     1.5  const unsigned short KFrameSizeInBytes = 0x800;
     1.6  
     1.7 +
     1.8 +void sleep(unsigned int mseconds)
     1.9 +	{
    1.10 +    clock_t goal = mseconds + clock();
    1.11 +    while (goal > clock());
    1.12 +	}
    1.13 +
    1.14  //
    1.15  // class GP1212A02A
    1.16  //
    1.17 @@ -94,6 +101,45 @@
    1.18  		//
    1.19  		iNextFrameAddress = 0x0000;
    1.20  
    1.21 +		//Beta font test
    1.22 +		//SendCommandFontAction(EFontDelete);
    1.23 +		
    1.24 +		//SendCommandReset();
    1.25 +
    1.26 +		/*
    1.27 +		unsigned char charPixels[]={	0xFF,0xFF,0xFF,0xFF,
    1.28 +										0x80,0x00,0x00,0x01,
    1.29 +										0x80,0x00,0x00,0x01,
    1.30 +										0x80,0x00,0x00,0x01,
    1.31 +										0x80,0x00,0x00,0x01,
    1.32 +										0x80,0x00,0x00,0x01,
    1.33 +										0x80,0x00,0x00,0x01,
    1.34 +										0x81,0xFF,0xFF,0xE1,
    1.35 +										0x80,0x00,0x00,0x01,
    1.36 +										0x80,0x00,0x00,0x01,
    1.37 +										0x80,0x00,0x00,0x01,
    1.38 +										0x80,0x00,0x00,0x01,
    1.39 +										0x80,0x00,0x00,0x01,
    1.40 +										0x80,0x00,0x00,0x01,
    1.41 +										0x80,0x00,0x00,0x01,
    1.42 +										0xFF,0xFF,0xFF,0xFF};
    1.43 +		
    1.44 +		
    1.45 +		for (unsigned short i=0;i<16;i++)
    1.46 +		{
    1.47 +			SendCommandDefineCharacter(EFont16x32,0x0030+i,charPixels);
    1.48 +			//SendCommandFontAction(EFontStore);
    1.49 +			//sleep(100);
    1.50 +		}
    1.51 +		*/
    1.52 +		
    1.53 +
    1.54 +		//SendCommandDefineCharacter(EFont16x32,0x0031,charPixels);
    1.55 +		//SendCommandFontAction(EFontStore);
    1.56 +
    1.57 +
    1.58 +		//
    1.59 +
    1.60  
    1.61  
    1.62  		}
    1.63 @@ -400,6 +446,31 @@
    1.64  
    1.65  
    1.66  /**
    1.67 +Returns to default setting. 
    1.68 +* The other command is not receive until this command complete. Please don’t send the any data 
    1.69 +from a host during “BUSY” 
    1.70 +* Delete the User definable font to the RAM. 
    1.71 +* If the VFD Power Off, VFD Power turn ON after the RESET command.
    1.72 +*/
    1.73 +void GP1212A02A::SendCommandReset()
    1.74 +	{
    1.75 +    //1BH,4AH,43H,44H
    1.76 +    //Send Clear Display Command
    1.77 +	FutabaVfdReport report;
    1.78 +	report[0]=0x00; //Report ID
    1.79 +	report[1]=0x04; //Report length
    1.80 +	report[2]=0x1B; //Command ID
    1.81 +	report[3]=0x4A; //Command ID
    1.82 +	report[4]=0x52; //Command ID
    1.83 +	report[5]=0x53; //Command ID
    1.84 +	Write(report);
    1.85 +	//Wait until reset is done. Is that needed?
    1.86 +	sleep(2000);
    1.87 +
    1.88 +	}
    1.89 +
    1.90 +
    1.91 +/**
    1.92  Provide Y coordinate of our off screen buffer.
    1.93  */
    1.94  unsigned char GP1212A02A::OffScreenY() const
    1.95 @@ -693,8 +764,9 @@
    1.96  
    1.97  
    1.98  /**
    1.99 -Number of characters for the given clock format.
   1.100 -@return 
   1.101 +Provide the length of our character string for the given clock format.
   1.102 +@param The clock format to evaluate.
   1.103 +@return Number of characters for the given clock format.
   1.104  */
   1.105  int GP1212A02A::ClockCharCount(TClockFormat aFormat)
   1.106  	{
   1.107 @@ -714,7 +786,7 @@
   1.108  	}
   1.109  
   1.110  /**
   1.111 -@return 
   1.112 +@return Clock character width in pixels.
   1.113  */
   1.114  int GP1212A02A::ClockCharWidthInPixels(TClockSize aSize)
   1.115  	{
   1.116 @@ -734,7 +806,7 @@
   1.117  	}
   1.118  
   1.119  /**
   1.120 -@return 
   1.121 +@return Clock character height in pixels.
   1.122  */
   1.123  int GP1212A02A::ClockCharHeightInPixels(TClockSize aSize)
   1.124  	{
   1.125 @@ -894,3 +966,131 @@
   1.126  
   1.127      Write(report);
   1.128  	}
   1.129 +
   1.130 +
   1.131 +/**
   1.132 +@return Size in bytes of a character for a given font size.
   1.133 +*/
   1.134 +int GP1212A02A::CharacterSizeInBytes(TFontSize aFontSize)
   1.135 +	{
   1.136 +	switch (aFontSize)
   1.137 +		{
   1.138 +	case EFont6x8:
   1.139 +		return 6;
   1.140 +	case EFont8x16:
   1.141 +		return 16;
   1.142 +	case EFont12x24:
   1.143 +		return 36;
   1.144 +	case EFont16x32:
   1.145 +		return 64;
   1.146 +	case EFont16x16:
   1.147 +		return 32;
   1.148 +	case EFont24x24:
   1.149 +		return 72;
   1.150 +	case EFont32x32:
   1.151 +		return 128;
   1.152 +		}
   1.153 +
   1.154 +	return 0;
   1.155 +	}
   1.156 +
   1.157 +/**
   1.158 +Define the User definable font (RAM) 
   1.159 +[Code] 1BH,6AH,47H,Pf,cL,(cH),Pd...Pd
   1.160 +[Function] Define the User definable font into RAM. A maximum 16 characters can be defined 
   1.161 +within each font size. 
   1.162 +The User definable fonts are displayed the defined code. It is a same process to normal fonts.  
   1.163 +The User definable fonts are valid until they redefined, Reset command, or the power off. 
   1.164 +If define the user definable font over 16 characters, at first defined user definable font is removed    
   1.165 +If the defined code is specified, existing data is re-written. 
   1.166 +If the 16x16, 24x24, 32x32 size define, it must specify the “cH” 
   1.167 +Pf = Font size 
   1.168 +cL = Lower byte of User definable font code 
   1.169 +cH = Upper byte of User definable font code 
   1.170 +Pd = Definition data 
   1.171 +[Definable area]
   1.172 +Pf = 30H : 6x8 dot  (Pd=6 byte) 
   1.173 +Pf = 31H : 8x16 dot  (Pd=16 byte) 
   1.174 +Pf = 32H : 12x24 dot  (Pd=36 byte) 
   1.175 +Pf = 33H : 16x32 dot  (Pd=64 byte) 
   1.176 +Pf = 34H : 16x16 dot  (Pd=32 byte) 
   1.177 +Pf = 35H : 24x24 dot  (Pd=72 byte) 
   1.178 +Pf = 36H : 32x32 dot  (Pd=128 byte) 
   1.179 +cL = ANK code (Pf=30H~33H : 1 byte code) 
   1.180 +cL,cH = Shift-JIS code (Pf=34H~36H : 2 byte code)
   1.181 +*/
   1.182 +void GP1212A02A::SendCommandDefineCharacter(TFontSize aFontSize, unsigned short aCharacterCode, unsigned char* aPixels)
   1.183 +	{
   1.184 +	unsigned char reportSize=0;
   1.185 +	unsigned char headerSize=0;
   1.186 +	unsigned char dataSize=CharacterSizeInBytes(aFontSize);
   1.187 +	FutabaVfdReport report;
   1.188 +
   1.189 +	if (aFontSize>=EFont16x16)
   1.190 +	{
   1.191 +		//16 bits char code
   1.192 +		headerSize=8;
   1.193 +		reportSize = (dataSize<=report.Size()-headerSize?dataSize+0x06:64); //Report length. -7 is for our header first 7 bytes. +5 is for our Futaba header size
   1.194 +		report[7] = aCharacterCode>>8;	
   1.195 +	}
   1.196 +	else
   1.197 +	{
   1.198 +		//8 bits char code
   1.199 +		headerSize=7;
   1.200 +		reportSize = (dataSize<=report.Size()-headerSize?dataSize+0x05:64); //Report length. -7 is for our header first 7 bytes. +5 is for our Futaba header size
   1.201 +	}
   1.202 +
   1.203 +	
   1.204 +    report[0]=0x00; //Report ID
   1.205 +    report[1]=reportSize; //Report size
   1.206 +    report[2]=0x1B; //Command ID
   1.207 +    report[3]=0x6A; //Command ID
   1.208 +    report[4]=0x47; //Command ID
   1.209 +    report[5]=aFontSize; //
   1.210 +	report[6] = (unsigned char) aCharacterCode;
   1.211 +	//7th byte was set above already
   1.212 +	int sizeWritten=MIN(dataSize,report.Size()-headerSize);
   1.213 +    memcpy(report.Buffer()+headerSize, aPixels, sizeWritten);
   1.214 +    Write(report);
   1.215 +
   1.216 +    int remainingSize=dataSize;
   1.217 +    //We need to keep on sending our pixel data until we are done
   1.218 +    while (report[1]==64)
   1.219 +        {
   1.220 +        report.Reset();
   1.221 +        remainingSize-=sizeWritten;
   1.222 +        report[0]=0x00; //Report ID
   1.223 +        report[1]=(remainingSize<=report.Size()-2?remainingSize:64); //Report length, should be 64 or the remaining size
   1.224 +        sizeWritten=(report[1]==64?63:report[1]);
   1.225 +        memcpy(report.Buffer()+2, aPixels+(dataSize-remainingSize), sizeWritten);
   1.226 +        Write(report);
   1.227 +        }
   1.228 +	}
   1.229 +
   1.230 +
   1.231 +/**
   1.232 +User definable font store / transfer / delete 
   1.233 +[Code] 1BH,6AH,45H,Ps
   1.234 +[Function] Store, transfer, or delete the User definable font to FROM.  
   1.235 +* Define the user definable font, after the user definable font is stored 
   1.236 +* The user definable font store is stored the all defined user definable font data. 
   1.237 +* The use definable font delete is deleted the all defined to FROM and RAM user definable font data. 
   1.238 +Ps = store / transfer / delete 
   1.239 +[Definable area]
   1.240 +Ps = 30H : Store
   1.241 +Ps = 31H : Transfer
   1.242 +Ps = 32H : Delete
   1.243 +*/
   1.244 +
   1.245 +void GP1212A02A::SendCommandFontAction(TFontAction aFontAction)
   1.246 +	{
   1.247 +	FutabaVfdReport report;
   1.248 +    report[0]=0x00; //Report ID
   1.249 +    report[1]=0x04; //Report size
   1.250 +    report[2]=0x1B; //Command ID
   1.251 +    report[3]=0x6A; //Command ID
   1.252 +    report[4]=0x45; //Command ID
   1.253 +    report[5]=aFontAction; //Ps
   1.254 +
   1.255 +    Write(report);
   1.256 +	}
     2.1 --- a/FutabaGP1212A02.h	Sat Sep 06 13:28:22 2014 +0200
     2.2 +++ b/FutabaGP1212A02.h	Sat Sep 06 15:54:51 2014 +0200
     2.3 @@ -114,19 +114,41 @@
     2.4  		EClockLarge		=	0x33
     2.5  	};
     2.6  
     2.7 +	enum TFontSize
     2.8 +	{
     2.9 +		EFont6x8	= 0x30,
    2.10 +		EFont8x16	= 0x31,
    2.11 +		EFont12x24	= 0x32,
    2.12 +		EFont16x32	= 0x33,
    2.13 +		EFont16x16	= 0x34,
    2.14 +		EFont24x24	= 0x35,
    2.15 +		EFont32x32	= 0x36
    2.16 +	};
    2.17 +
    2.18 +	enum TFontAction
    2.19 +	{
    2.20 +		EFontStore		= 0x30,
    2.21 +		EFontTransfer	= 0x31,
    2.22 +		EFontDelete		= 0x32
    2.23 +	};
    2.24 +
    2.25  
    2.26  private:
    2.27  	//Specific to GP1212A02A
    2.28  	//General setting command
    2.29  	void SendCommandClear();
    2.30 +	void SendCommandReset();
    2.31  	//
    2.32  	void BmpDataInput(TTarget aTarget, unsigned short aAddress, TDirection aDirection, unsigned short aSize, unsigned char* aPixels);
    2.33  	//
    2.34  	void SendCommandPower(TPowerStatus aPowerStatus);
    2.35  	//Clock commands
    2.36  	void SendCommandClockSetting(TWeekDay aWeekDay, unsigned char aHour, unsigned char aMinute);
    2.37 -	void SendCommandClockDisplay(TClockFormat aClockFormat, unsigned short aAddress, TClockSize aSize);
    2.38 +	void SendCommandClockDisplay(TClockFormat aClockFormat, unsigned short aAddress, TClockSize aSize);	
    2.39  	void SendCommandClockCancel();
    2.40 +	//Font commands
    2.41 +	void SendCommandDefineCharacter(TFontSize aFontSize, unsigned short aCharacterCode, unsigned char* aPixelData);
    2.42 +	void SendCommandFontAction(TFontAction aFontAction);
    2.43  
    2.44  
    2.45  	//BMP box
    2.46 @@ -140,6 +162,8 @@
    2.47  	int ClockCharWidthInPixels(TClockSize aSize);
    2.48  	int ClockCharHeightInPixels(TClockSize aSize);
    2.49  	unsigned short ClockCenterAddress(TClockFormat aFormat, TClockSize aSize);
    2.50 +	//Font utilities
    2.51 +	int CharacterSizeInBytes(TFontSize aFontSize);
    2.52  
    2.53  private:
    2.54      void RequestDeviceId();