MiniDisplay.cpp
author StephaneLenclud
Wed, 06 May 2015 21:25:49 +0200
changeset 37 d3b88ef66bfe
parent 32 2c844ef1ff4b
permissions -rw-r--r--
Trying to sort out our interop nicely.
     1 //
     2 // Copyright (C) 2014-2015 Stéphane Lenclud.
     3 //
     4 // This file is part of MiniDisplay.
     5 //
     6 // MiniDisplay is free software: you can redistribute it and/or modify
     7 // it under the terms of the GNU General Public License as published by
     8 // the Free Software Foundation, either version 3 of the License, or
     9 // (at your option) any later version.
    10 //
    11 // MiniDisplay is distributed in the hope that it will be useful,
    12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14 // GNU General Public License for more details.
    15 //
    16 // You should have received a copy of the GNU General Public License
    17 // along with MiniDisplay.  If not, see <http://www.gnu.org/licenses/>.
    18 //
    19 
    20 #include "MiniDisplay.h"
    21 #include "FutabaGP1212A01.h"
    22 #include "FutabaGP1212A02.h"
    23 #include "FutabaMDM166AA.h"
    24 
    25 /**
    26 Make sure you update this list when adding a new display.
    27 The order has to match the one from TMiniDisplayType.
    28 */
    29 wchar_t* KDisplayNames[]=
    30 	{
    31 	L"Auto-Detect",
    32 	L"Futaba GP1212A01",
    33 	L"Futaba GP1212A02",
    34 	L"Futaba MDM166AA",
    35 	L"Unknown display device"
    36 	};
    37 
    38 MiniDisplayDevice MiniDisplayOpen(TMiniDisplayType aType, bool aAutoDetect)
    39 	{
    40 	GraphicDisplay* device=NULL;
    41 
    42 	switch (aType)
    43 		{
    44 	case EMiniDisplayAutoDetect:
    45 	case EMiniDisplayFutabaGP1212A01:
    46 		device=new GP1212A01A();
    47 		break;
    48 		
    49 	case EMiniDisplayFutabaGP1212A02:
    50 		device=new GP1212A02A();
    51 		break;
    52 
    53 	case EMiniDisplayFutabaMDM166AA:
    54 		device=new MDM166AA();
    55 		break;
    56 
    57 	case EMiniDisplayAutoDetectFailed:
    58 		//Auto detect sequence failed
    59 		return NULL;
    60 		break;
    61 		};
    62 
    63 	int success = device->Open();
    64 	if (!success)
    65 		{
    66 		delete device;
    67 		device=NULL;
    68 		if (aAutoDetect)
    69 			{
    70 			//Go recursive for auto detect
    71 			int typeValue=(int)aType;
    72 			typeValue++;
    73 			TMiniDisplayType nextType=(TMiniDisplayType)typeValue;
    74 			return MiniDisplayOpen(nextType,aAutoDetect);
    75 			}
    76 		}
    77 
    78 	return device;
    79 	}
    80 
    81 
    82 //Open & Close functions
    83 MiniDisplayDevice MiniDisplayOpen(TMiniDisplayType aType)
    84 	{
    85 	bool autoDetect=aType==EMiniDisplayAutoDetect;
    86 	//If we want auto detect we need to pass in our first display type
    87 	//If we don't want auto detect we just pass in the given display type. 
    88 	return MiniDisplayOpen((autoDetect?EMiniDisplayFutabaGP1212A01:aType),autoDetect);
    89 	}
    90 
    91 
    92 //
    93 
    94 void MiniDisplayClose(MiniDisplayDevice aDevice)
    95 	{
    96 	delete ((GraphicDisplay*)aDevice);
    97 	}
    98 
    99 
   100 int MiniDisplayTypeCount()
   101 	{
   102 	return EMiniDisplayAutoDetectFailed;
   103 	}
   104 
   105 
   106 wchar_t* MiniDisplayTypeName(TMiniDisplayType aType)
   107 	{
   108 		if (aType>=EMiniDisplayAutoDetectFailed)
   109 		{
   110 			return KDisplayNames[EMiniDisplayAutoDetectFailed];
   111 		}
   112 
   113 		return KDisplayNames[aType];
   114 	}
   115 
   116 
   117 void MiniDisplayClear(MiniDisplayDevice aDevice)
   118 	{
   119 	if (!aDevice)
   120 		{
   121 		return;
   122 		}
   123 
   124 	((GraphicDisplay*)aDevice)->Clear();
   125 	}
   126 
   127 
   128 void MiniDisplayFill(MiniDisplayDevice aDevice)
   129 	{
   130 	if (!aDevice)
   131 		{
   132 		return;
   133 		}
   134 
   135 	((GraphicDisplay*)aDevice)->Fill();
   136 	}
   137 
   138 
   139 void MiniDisplaySwapBuffers(MiniDisplayDevice aDevice)
   140 	{
   141 	if (!aDevice)
   142 		{
   143 		return;
   144 		}
   145 
   146 	((GraphicDisplay*)aDevice)->SwapBuffers();
   147 	}
   148 
   149 //-------------------------------------------------------------
   150 int MiniDisplayMaxBrightness(MiniDisplayDevice aDevice)
   151 	{
   152 	if (!aDevice)
   153 		{
   154 		return 0;
   155 		}
   156 
   157 	return ((GraphicDisplay*)aDevice)->MaxBrightness();
   158 	}
   159 
   160 //-------------------------------------------------------------
   161 int MiniDisplayMinBrightness(MiniDisplayDevice aDevice)
   162 	{
   163 	if (!aDevice)
   164 		{
   165 		return 0;
   166 		}
   167 
   168 	return ((GraphicDisplay*)aDevice)->MinBrightness();
   169 	}
   170 
   171 //-------------------------------------------------------------
   172 void MiniDisplaySetBrightness(MiniDisplayDevice aDevice, int aBrightness)
   173 	{
   174 	if (!aDevice)
   175 		{
   176 		return;
   177 		}
   178 
   179 	((GraphicDisplay*)aDevice)->SetBrightness(aBrightness);
   180 	}
   181 
   182 //-------------------------------------------------------------
   183 int MiniDisplayWidthInPixels(MiniDisplayDevice aDevice)
   184 	{
   185 	if (!aDevice)
   186 		{
   187 		return 0;
   188 		}
   189 
   190 	return ((GraphicDisplay*)aDevice)->WidthInPixels();
   191 	}
   192 
   193 //-------------------------------------------------------------
   194 int MiniDisplayHeightInPixels(MiniDisplayDevice aDevice)
   195 	{
   196 	if (!aDevice)
   197 		{
   198 		return 0;
   199 		}
   200 
   201 	return ((GraphicDisplay*)aDevice)->HeightInPixels();
   202 	}
   203 
   204 //-------------------------------------------------------------
   205 void MiniDisplaySetPixel(MiniDisplayDevice aDevice, int aX, int aY, unsigned int aPixel)
   206 	{
   207 	//aValue&=0x00FFFFFF; //Filter out alpha component
   208 	return ((GraphicDisplay*)aDevice)->SetPixel(aX,aY,aPixel);
   209 	}
   210 
   211 //-------------------------------------------------------------
   212 wchar_t* MiniDisplayVendor(MiniDisplayDevice aDevice)
   213     {
   214     return ((GraphicDisplay*)aDevice)->Vendor();
   215     }
   216 
   217 //-------------------------------------------------------------
   218 wchar_t* MiniDisplayProduct(MiniDisplayDevice aDevice)
   219     {
   220     return ((GraphicDisplay*)aDevice)->Product();
   221     }
   222 
   223 //-------------------------------------------------------------
   224 wchar_t* MiniDisplaySerialNumber(MiniDisplayDevice aDevice)
   225     {
   226     return ((GraphicDisplay*)aDevice)->SerialNumber();
   227     }
   228 
   229 //-------------------------------------------------------------
   230 void MiniDisplayRequest(MiniDisplayDevice aDevice, TMiniDisplayRequest aRequest)
   231     {
   232     ((GraphicDisplay*)aDevice)->Request(aRequest);
   233     }
   234 
   235 //-------------------------------------------------------------
   236 bool MiniDisplayRequestPending(MiniDisplayDevice aDevice)
   237     {
   238     return ((GraphicDisplay*)aDevice)->RequestPending();
   239     }
   240 
   241 //-------------------------------------------------------------
   242 TMiniDisplayRequest MiniDisplayCurrentRequest(MiniDisplayDevice aDevice)
   243     {
   244     return ((GraphicDisplay*)aDevice)->CurrentRequest();
   245     }
   246 
   247 //-------------------------------------------------------------
   248 void MiniDisplayCancelRequest(MiniDisplayDevice aDevice)
   249     {
   250     ((GraphicDisplay*)aDevice)->CancelRequest();
   251     }
   252 
   253 //-------------------------------------------------------------
   254 TMiniDisplayRequest MiniDisplayAttemptRequestCompletion(MiniDisplayDevice aDevice)
   255 	{
   256 	return ((GraphicDisplay*)aDevice)->AttemptRequestCompletion();
   257 	}
   258 
   259 //-------------------------------------------------------------
   260 char* MiniDisplayDeviceId(MiniDisplayDevice aDevice)
   261 	{
   262 	return ((GraphicDisplay*)aDevice)->DeviceId();
   263 	}
   264 
   265 //-------------------------------------------------------------
   266 char* MiniDisplayFirmwareRevision(MiniDisplayDevice aDevice)
   267 	{
   268 	return ((GraphicDisplay*)aDevice)->FirmwareRevision();
   269 	}
   270 
   271 //-------------------------------------------------------------
   272 bool MiniDisplayPowerSupplyStatus(MiniDisplayDevice aDevice)
   273 	{
   274 	return ((GraphicDisplay*)aDevice)->IsPowerOn();
   275 	}
   276 
   277 //-------------------------------------------------------------
   278 void MiniDisplayPowerOn(MiniDisplayDevice aDevice)
   279     {
   280     ((GraphicDisplay*)aDevice)->TurnPowerOn();
   281     }
   282 
   283 //-------------------------------------------------------------
   284 void MiniDisplayPowerOff(MiniDisplayDevice aDevice)
   285     {
   286     ((GraphicDisplay*)aDevice)->TurnPowerOff();
   287     }
   288 
   289 //-------------------------------------------------------------
   290 bool MiniDisplaySupportPowerOnOff(MiniDisplayDevice aDevice)
   291     {
   292     return ((GraphicDisplay*)aDevice)->SupportPowerOnOff();
   293     }
   294 
   295 //-------------------------------------------------------------
   296 void MiniDisplayShowClock(MiniDisplayDevice aDevice)
   297     {
   298     ((GraphicDisplay*)aDevice)->ShowClock();
   299     }
   300 
   301 //-------------------------------------------------------------
   302 void MiniDisplayHideClock(MiniDisplayDevice aDevice)
   303     {
   304     ((GraphicDisplay*)aDevice)->HideClock();
   305     }
   306 
   307 //-------------------------------------------------------------
   308 bool MiniDisplaySupportClock(MiniDisplayDevice aDevice)
   309     {
   310     return ((GraphicDisplay*)aDevice)->SupportClock();
   311     }
   312 
   313 //-------------------------------------------------------------
   314 int MiniDisplayIconCount(MiniDisplayDevice aDevice, TMiniDisplayIconType aIcon)
   315 	{
   316 	return ((GraphicDisplay*)aDevice)->IconCount(aIcon);
   317 	}
   318 
   319 //-------------------------------------------------------------
   320 int MiniDisplayIconStatusCount(MiniDisplayDevice aDevice, TMiniDisplayIconType aIcon)
   321 	{
   322 	return ((GraphicDisplay*)aDevice)->IconStatusCount(aIcon);
   323 	}
   324 
   325 //-------------------------------------------------------------
   326 void MiniDisplaySetIconStatus(MiniDisplayDevice aDevice, TMiniDisplayIconType aIcon, int aIndex, int aStatus)
   327 	{
   328 	((GraphicDisplay*)aDevice)->SetIconStatus(aIcon,aIndex,aStatus);
   329 	}