MiniDisplay.cpp
author StephaneLenclud
Thu, 05 Feb 2015 11:41:19 +0100
changeset 27 949be5444c57
parent 24 9c233658ab28
child 31 0a2b658e0d56
permissions -rw-r--r--
MDM166AA swap buffers now working.
     1 
     2 #include "MiniDisplay.h"
     3 #include "FutabaGP1212A01.h"
     4 #include "FutabaGP1212A02.h"
     5 #include "FutabaMDM166AA.h"
     6 
     7 /**
     8 Make sure you update this list when adding a new display.
     9 The order has to match the one from TMiniDisplayType.
    10 */
    11 wchar_t* KDisplayNames[]=
    12 	{
    13 	L"Auto-Detect",
    14 	L"Futaba GP1212A01",
    15 	L"Futaba GP1212A02",
    16 	L"Futaba MDM166AA",
    17 	L"Unknown display device"
    18 	};
    19 
    20 MiniDisplayDevice MiniDisplayOpen(TMiniDisplayType aType, bool aAutoDetect)
    21 	{
    22 	GraphicDisplay* device=NULL;
    23 
    24 	switch (aType)
    25 		{
    26 	case EMiniDisplayAutoDetect:
    27 	case EMiniDisplayFutabaGP1212A01:
    28 		device=new GP1212A01A();
    29 		break;
    30 		
    31 	case EMiniDisplayFutabaGP1212A02:
    32 		device=new GP1212A02A();
    33 		break;
    34 
    35 	case EMiniDisplayFutabaMDM166AA:
    36 		device=new MDM166AA();
    37 		break;
    38 
    39 	case EMiniDisplayAutoDetectFailed:
    40 		//Auto detect sequence failed
    41 		return NULL;
    42 		break;
    43 		};
    44 
    45 	int success = device->Open();
    46 	if (!success)
    47 		{
    48 		delete device;
    49 		device=NULL;
    50 		if (aAutoDetect)
    51 			{
    52 			//Go recursive for auto detect
    53 			int typeValue=(int)aType;
    54 			typeValue++;
    55 			TMiniDisplayType nextType=(TMiniDisplayType)typeValue;
    56 			return MiniDisplayOpen(nextType,aAutoDetect);
    57 			}
    58 		}
    59 
    60 	return device;
    61 	}
    62 
    63 
    64 //Open & Close functions
    65 MiniDisplayDevice MiniDisplayOpen(TMiniDisplayType aType)
    66 	{
    67 	bool autoDetect=aType==EMiniDisplayAutoDetect;
    68 	//If we want auto detect we need to pass in our first display type
    69 	//If we don't want auto detect we just pass in the given display type. 
    70 	return MiniDisplayOpen((autoDetect?EMiniDisplayFutabaGP1212A01:aType),autoDetect);
    71 	}
    72 
    73 
    74 //
    75 
    76 void MiniDisplayClose(MiniDisplayDevice aDevice)
    77 	{
    78 	delete ((GraphicDisplay*)aDevice);
    79 	}
    80 
    81 
    82 int MiniDisplayTypeCount()
    83 	{
    84 	return EMiniDisplayAutoDetectFailed;
    85 	}
    86 
    87 
    88 wchar_t* MiniDisplayTypeName(TMiniDisplayType aType)
    89 	{
    90 		if (aType>=EMiniDisplayAutoDetectFailed)
    91 		{
    92 			return KDisplayNames[EMiniDisplayAutoDetectFailed];
    93 		}
    94 
    95 		return KDisplayNames[aType];
    96 	}
    97 
    98 
    99 void MiniDisplayClear(MiniDisplayDevice aDevice)
   100 	{
   101 	if (!aDevice)
   102 		{
   103 		return;
   104 		}
   105 
   106 	((GraphicDisplay*)aDevice)->Clear();
   107 	}
   108 
   109 
   110 void MiniDisplayFill(MiniDisplayDevice aDevice)
   111 	{
   112 	if (!aDevice)
   113 		{
   114 		return;
   115 		}
   116 
   117 	((GraphicDisplay*)aDevice)->Fill();
   118 	}
   119 
   120 
   121 void MiniDisplaySwapBuffers(MiniDisplayDevice aDevice)
   122 	{
   123 	if (!aDevice)
   124 		{
   125 		return;
   126 		}
   127 
   128 	((GraphicDisplay*)aDevice)->SwapBuffers();
   129 	}
   130 
   131 //-------------------------------------------------------------
   132 int MiniDisplayMaxBrightness(MiniDisplayDevice aDevice)
   133 	{
   134 	if (!aDevice)
   135 		{
   136 		return 0;
   137 		}
   138 
   139 	return ((GraphicDisplay*)aDevice)->MaxBrightness();
   140 	}
   141 
   142 //-------------------------------------------------------------
   143 int MiniDisplayMinBrightness(MiniDisplayDevice aDevice)
   144 	{
   145 	if (!aDevice)
   146 		{
   147 		return 0;
   148 		}
   149 
   150 	return ((GraphicDisplay*)aDevice)->MinBrightness();
   151 	}
   152 
   153 //-------------------------------------------------------------
   154 void MiniDisplaySetBrightness(MiniDisplayDevice aDevice, int aBrightness)
   155 	{
   156 	if (!aDevice)
   157 		{
   158 		return;
   159 		}
   160 
   161 	((GraphicDisplay*)aDevice)->SetBrightness(aBrightness);
   162 	}
   163 
   164 //-------------------------------------------------------------
   165 int MiniDisplayWidthInPixels(MiniDisplayDevice aDevice)
   166 	{
   167 	if (!aDevice)
   168 		{
   169 		return 0;
   170 		}
   171 
   172 	return ((GraphicDisplay*)aDevice)->WidthInPixels();
   173 	}
   174 
   175 //-------------------------------------------------------------
   176 int MiniDisplayHeightInPixels(MiniDisplayDevice aDevice)
   177 	{
   178 	if (!aDevice)
   179 		{
   180 		return 0;
   181 		}
   182 
   183 	return ((GraphicDisplay*)aDevice)->HeightInPixels();
   184 	}
   185 
   186 //-------------------------------------------------------------
   187 void MiniDisplaySetPixel(MiniDisplayDevice aDevice, int aX, int aY, unsigned int aPixel)
   188 	{
   189 	//aValue&=0x00FFFFFF; //Filter out alpha component
   190 	return ((GraphicDisplay*)aDevice)->SetPixel(aX,aY,aPixel);
   191 	}
   192 
   193 //-------------------------------------------------------------
   194 wchar_t* MiniDisplayVendor(MiniDisplayDevice aDevice)
   195     {
   196     return ((GraphicDisplay*)aDevice)->Vendor();
   197     }
   198 
   199 //-------------------------------------------------------------
   200 wchar_t* MiniDisplayProduct(MiniDisplayDevice aDevice)
   201     {
   202     return ((GraphicDisplay*)aDevice)->Product();
   203     }
   204 
   205 //-------------------------------------------------------------
   206 wchar_t* MiniDisplaySerialNumber(MiniDisplayDevice aDevice)
   207     {
   208     return ((GraphicDisplay*)aDevice)->SerialNumber();
   209     }
   210 
   211 //-------------------------------------------------------------
   212 void MiniDisplayRequest(MiniDisplayDevice aDevice, TMiniDisplayRequest aRequest)
   213     {
   214     ((GraphicDisplay*)aDevice)->Request(aRequest);
   215     }
   216 
   217 //-------------------------------------------------------------
   218 bool MiniDisplayRequestPending(MiniDisplayDevice aDevice)
   219     {
   220     return ((GraphicDisplay*)aDevice)->RequestPending();
   221     }
   222 
   223 //-------------------------------------------------------------
   224 TMiniDisplayRequest MiniDisplayCurrentRequest(MiniDisplayDevice aDevice)
   225     {
   226     return ((GraphicDisplay*)aDevice)->CurrentRequest();
   227     }
   228 
   229 //-------------------------------------------------------------
   230 void MiniDisplayCancelRequest(MiniDisplayDevice aDevice)
   231     {
   232     ((GraphicDisplay*)aDevice)->CancelRequest();
   233     }
   234 
   235 //-------------------------------------------------------------
   236 TMiniDisplayRequest MiniDisplayAttemptRequestCompletion(MiniDisplayDevice aDevice)
   237 	{
   238 	return ((GraphicDisplay*)aDevice)->AttemptRequestCompletion();
   239 	}
   240 
   241 //-------------------------------------------------------------
   242 char* MiniDisplayDeviceId(MiniDisplayDevice aDevice)
   243 	{
   244 	return ((GraphicDisplay*)aDevice)->DeviceId();
   245 	}
   246 
   247 //-------------------------------------------------------------
   248 char* MiniDisplayFirmwareRevision(MiniDisplayDevice aDevice)
   249 	{
   250 	return ((GraphicDisplay*)aDevice)->FirmwareRevision();
   251 	}
   252 
   253 //-------------------------------------------------------------
   254 bool MiniDisplayPowerSupplyStatus(MiniDisplayDevice aDevice)
   255 	{
   256 	return ((GraphicDisplay*)aDevice)->IsPowerOn();
   257 	}
   258 
   259 //-------------------------------------------------------------
   260 void MiniDisplayPowerOn(MiniDisplayDevice aDevice)
   261     {
   262     ((GraphicDisplay*)aDevice)->TurnPowerOn();
   263     }
   264 
   265 //-------------------------------------------------------------
   266 void MiniDisplayPowerOff(MiniDisplayDevice aDevice)
   267     {
   268     ((GraphicDisplay*)aDevice)->TurnPowerOff();
   269     }
   270 
   271 //-------------------------------------------------------------
   272 bool MiniDisplaySupportPowerOnOff(MiniDisplayDevice aDevice)
   273     {
   274     return ((GraphicDisplay*)aDevice)->SupportPowerOnOff();
   275     }
   276 
   277 //-------------------------------------------------------------
   278 void MiniDisplayShowClock(MiniDisplayDevice aDevice)
   279     {
   280     ((GraphicDisplay*)aDevice)->ShowClock();
   281     }
   282 
   283 //-------------------------------------------------------------
   284 void MiniDisplayHideClock(MiniDisplayDevice aDevice)
   285     {
   286     ((GraphicDisplay*)aDevice)->HideClock();
   287     }
   288 
   289 //-------------------------------------------------------------
   290 bool MiniDisplaySupportClock(MiniDisplayDevice aDevice)
   291     {
   292     return ((GraphicDisplay*)aDevice)->SupportClock();
   293     }