StephaneLenclud@35: // StephaneLenclud@35: // Copyright (C) 2014-2015 Stéphane Lenclud. StephaneLenclud@35: // StephaneLenclud@35: // This file is part of MiniDisplay. StephaneLenclud@35: // StephaneLenclud@35: // MiniDisplay is free software: you can redistribute it and/or modify StephaneLenclud@35: // it under the terms of the GNU General Public License as published by StephaneLenclud@35: // the Free Software Foundation, either version 3 of the License, or StephaneLenclud@35: // (at your option) any later version. StephaneLenclud@35: // StephaneLenclud@35: // MiniDisplay is distributed in the hope that it will be useful, StephaneLenclud@35: // but WITHOUT ANY WARRANTY; without even the implied warranty of StephaneLenclud@35: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the StephaneLenclud@35: // GNU General Public License for more details. StephaneLenclud@35: // StephaneLenclud@35: // You should have received a copy of the GNU General Public License StephaneLenclud@35: // along with MiniDisplay. If not, see . StephaneLenclud@35: // sl@2: sl@2: #include "MiniDisplay.h" sl@8: #include "FutabaGP1212A01.h" sl@10: #include "FutabaGP1212A02.h" StephaneLenclud@25: #include "FutabaMDM166AA.h" sl@2: StephaneLenclud@25: /** StephaneLenclud@25: Make sure you update this list when adding a new display. StephaneLenclud@25: The order has to match the one from TMiniDisplayType. StephaneLenclud@25: */ StephaneLenclud@24: wchar_t* KDisplayNames[]= StephaneLenclud@24: { StephaneLenclud@24: L"Auto-Detect", StephaneLenclud@24: L"Futaba GP1212A01", StephaneLenclud@24: L"Futaba GP1212A02", StephaneLenclud@25: L"Futaba MDM166AA", StephaneLenclud@24: L"Unknown display device" StephaneLenclud@24: }; StephaneLenclud@24: StephaneLenclud@18: MiniDisplayDevice MiniDisplayOpen(TMiniDisplayType aType, bool aAutoDetect) sl@2: { sl@10: GraphicDisplay* device=NULL; sl@10: sl@10: switch (aType) sl@10: { sl@10: case EMiniDisplayAutoDetect: sl@10: case EMiniDisplayFutabaGP1212A01: sl@10: device=new GP1212A01A(); sl@10: break; sl@10: sl@10: case EMiniDisplayFutabaGP1212A02: sl@10: device=new GP1212A02A(); sl@10: break; StephaneLenclud@18: StephaneLenclud@25: case EMiniDisplayFutabaMDM166AA: StephaneLenclud@25: device=new MDM166AA(); StephaneLenclud@25: break; StephaneLenclud@25: StephaneLenclud@18: case EMiniDisplayAutoDetectFailed: StephaneLenclud@18: //Auto detect sequence failed StephaneLenclud@18: return NULL; StephaneLenclud@18: break; sl@10: }; sl@10: sl@2: int success = device->Open(); sl@2: if (!success) sl@2: { sl@2: delete device; sl@10: device=NULL; StephaneLenclud@18: if (aAutoDetect) StephaneLenclud@18: { StephaneLenclud@18: //Go recursive for auto detect StephaneLenclud@18: int typeValue=(int)aType; StephaneLenclud@18: typeValue++; StephaneLenclud@18: TMiniDisplayType nextType=(TMiniDisplayType)typeValue; StephaneLenclud@18: return MiniDisplayOpen(nextType,aAutoDetect); StephaneLenclud@18: } sl@2: } sl@2: sl@2: return device; sl@2: } sl@2: StephaneLenclud@18: StephaneLenclud@18: //Open & Close functions StephaneLenclud@18: MiniDisplayDevice MiniDisplayOpen(TMiniDisplayType aType) StephaneLenclud@18: { StephaneLenclud@18: bool autoDetect=aType==EMiniDisplayAutoDetect; sl@19: //If we want auto detect we need to pass in our first display type sl@19: //If we don't want auto detect we just pass in the given display type. sl@19: return MiniDisplayOpen((autoDetect?EMiniDisplayFutabaGP1212A01:aType),autoDetect); StephaneLenclud@18: } StephaneLenclud@18: StephaneLenclud@18: sl@10: // sl@10: sl@2: void MiniDisplayClose(MiniDisplayDevice aDevice) sl@4: { sl@10: delete ((GraphicDisplay*)aDevice); sl@2: } sl@2: sl@2: StephaneLenclud@24: int MiniDisplayTypeCount() StephaneLenclud@24: { StephaneLenclud@24: return EMiniDisplayAutoDetectFailed; StephaneLenclud@24: } StephaneLenclud@24: StephaneLenclud@24: StephaneLenclud@24: wchar_t* MiniDisplayTypeName(TMiniDisplayType aType) StephaneLenclud@24: { StephaneLenclud@24: if (aType>=EMiniDisplayAutoDetectFailed) StephaneLenclud@24: { StephaneLenclud@24: return KDisplayNames[EMiniDisplayAutoDetectFailed]; StephaneLenclud@24: } StephaneLenclud@24: StephaneLenclud@24: return KDisplayNames[aType]; StephaneLenclud@24: } StephaneLenclud@24: StephaneLenclud@24: sl@2: void MiniDisplayClear(MiniDisplayDevice aDevice) sl@2: { sl@2: if (!aDevice) sl@2: { sl@2: return; sl@2: } sl@2: sl@10: ((GraphicDisplay*)aDevice)->Clear(); sl@2: } sl@2: sl@2: sl@2: void MiniDisplayFill(MiniDisplayDevice aDevice) sl@2: { sl@2: if (!aDevice) sl@2: { sl@2: return; sl@2: } sl@4: sl@10: ((GraphicDisplay*)aDevice)->Fill(); sl@2: } sl@2: sl@2: sl@2: void MiniDisplaySwapBuffers(MiniDisplayDevice aDevice) sl@2: { sl@2: if (!aDevice) sl@2: { sl@2: return; sl@2: } sl@4: sl@10: ((GraphicDisplay*)aDevice)->SwapBuffers(); sl@2: } sl@2: sl@2: //------------------------------------------------------------- sl@2: int MiniDisplayMaxBrightness(MiniDisplayDevice aDevice) sl@2: { sl@2: if (!aDevice) sl@2: { sl@2: return 0; sl@2: } sl@2: sl@10: return ((GraphicDisplay*)aDevice)->MaxBrightness(); sl@2: } sl@2: sl@2: //------------------------------------------------------------- sl@2: int MiniDisplayMinBrightness(MiniDisplayDevice aDevice) sl@2: { sl@2: if (!aDevice) sl@2: { sl@2: return 0; sl@2: } sl@2: sl@10: return ((GraphicDisplay*)aDevice)->MinBrightness(); sl@2: } sl@2: sl@2: //------------------------------------------------------------- sl@2: void MiniDisplaySetBrightness(MiniDisplayDevice aDevice, int aBrightness) sl@2: { sl@2: if (!aDevice) sl@2: { sl@2: return; sl@2: } sl@2: sl@10: ((GraphicDisplay*)aDevice)->SetBrightness(aBrightness); sl@2: } sl@2: sl@3: //------------------------------------------------------------- sl@3: int MiniDisplayWidthInPixels(MiniDisplayDevice aDevice) sl@3: { sl@3: if (!aDevice) sl@3: { sl@3: return 0; sl@3: } sl@3: sl@10: return ((GraphicDisplay*)aDevice)->WidthInPixels(); sl@3: } sl@3: sl@3: //------------------------------------------------------------- sl@3: int MiniDisplayHeightInPixels(MiniDisplayDevice aDevice) sl@3: { sl@3: if (!aDevice) sl@3: { sl@3: return 0; sl@3: } sl@3: sl@10: return ((GraphicDisplay*)aDevice)->HeightInPixels(); sl@3: } sl@3: sl@3: //------------------------------------------------------------- sl@22: void MiniDisplaySetPixel(MiniDisplayDevice aDevice, int aX, int aY, unsigned int aPixel) sl@3: { sl@3: //aValue&=0x00FFFFFF; //Filter out alpha component sl@22: return ((GraphicDisplay*)aDevice)->SetPixel(aX,aY,aPixel); sl@3: } sl@3: sl@4: //------------------------------------------------------------- sl@4: wchar_t* MiniDisplayVendor(MiniDisplayDevice aDevice) sl@4: { sl@15: return ((GraphicDisplay*)aDevice)->Vendor(); sl@4: } sl@4: sl@4: //------------------------------------------------------------- sl@4: wchar_t* MiniDisplayProduct(MiniDisplayDevice aDevice) sl@4: { sl@15: return ((GraphicDisplay*)aDevice)->Product(); sl@4: } sl@4: sl@4: //------------------------------------------------------------- sl@4: wchar_t* MiniDisplaySerialNumber(MiniDisplayDevice aDevice) sl@4: { sl@15: return ((GraphicDisplay*)aDevice)->SerialNumber(); sl@4: } sl@4: sl@4: //------------------------------------------------------------- sl@11: void MiniDisplayRequest(MiniDisplayDevice aDevice, TMiniDisplayRequest aRequest) sl@4: { sl@11: ((GraphicDisplay*)aDevice)->Request(aRequest); sl@4: } sl@4: sl@4: //------------------------------------------------------------- sl@4: bool MiniDisplayRequestPending(MiniDisplayDevice aDevice) sl@4: { sl@12: return ((GraphicDisplay*)aDevice)->RequestPending(); sl@4: } sl@4: sl@4: //------------------------------------------------------------- sl@4: TMiniDisplayRequest MiniDisplayCurrentRequest(MiniDisplayDevice aDevice) sl@4: { sl@12: return ((GraphicDisplay*)aDevice)->CurrentRequest(); sl@4: } sl@4: sl@4: //------------------------------------------------------------- sl@4: void MiniDisplayCancelRequest(MiniDisplayDevice aDevice) sl@4: { sl@15: ((GraphicDisplay*)aDevice)->CancelRequest(); sl@4: } sl@4: sl@5: //------------------------------------------------------------- sl@6: TMiniDisplayRequest MiniDisplayAttemptRequestCompletion(MiniDisplayDevice aDevice) sl@5: { sl@12: return ((GraphicDisplay*)aDevice)->AttemptRequestCompletion(); sl@5: } sl@5: sl@5: //------------------------------------------------------------- sl@5: char* MiniDisplayDeviceId(MiniDisplayDevice aDevice) sl@5: { sl@12: return ((GraphicDisplay*)aDevice)->DeviceId(); sl@5: } sl@5: sl@5: //------------------------------------------------------------- sl@5: char* MiniDisplayFirmwareRevision(MiniDisplayDevice aDevice) sl@5: { sl@12: return ((GraphicDisplay*)aDevice)->FirmwareRevision(); sl@6: } sl@6: sl@6: //------------------------------------------------------------- sl@6: bool MiniDisplayPowerSupplyStatus(MiniDisplayDevice aDevice) sl@6: { sl@16: return ((GraphicDisplay*)aDevice)->IsPowerOn(); sl@16: } sl@16: sl@16: //------------------------------------------------------------- sl@16: void MiniDisplayPowerOn(MiniDisplayDevice aDevice) sl@16: { sl@16: ((GraphicDisplay*)aDevice)->TurnPowerOn(); sl@16: } sl@16: sl@16: //------------------------------------------------------------- sl@16: void MiniDisplayPowerOff(MiniDisplayDevice aDevice) sl@16: { sl@16: ((GraphicDisplay*)aDevice)->TurnPowerOff(); sl@16: } sl@16: sl@16: //------------------------------------------------------------- sl@16: bool MiniDisplaySupportPowerOnOff(MiniDisplayDevice aDevice) sl@16: { sl@16: return ((GraphicDisplay*)aDevice)->SupportPowerOnOff(); sl@17: } sl@17: sl@17: //------------------------------------------------------------- sl@17: void MiniDisplayShowClock(MiniDisplayDevice aDevice) sl@17: { sl@17: ((GraphicDisplay*)aDevice)->ShowClock(); sl@17: } sl@17: sl@17: //------------------------------------------------------------- sl@17: void MiniDisplayHideClock(MiniDisplayDevice aDevice) sl@17: { sl@17: ((GraphicDisplay*)aDevice)->HideClock(); sl@17: } sl@17: sl@17: //------------------------------------------------------------- sl@17: bool MiniDisplaySupportClock(MiniDisplayDevice aDevice) sl@17: { sl@17: return ((GraphicDisplay*)aDevice)->SupportClock(); StephaneLenclud@31: } StephaneLenclud@31: StephaneLenclud@31: //------------------------------------------------------------- StephaneLenclud@32: int MiniDisplayIconCount(MiniDisplayDevice aDevice, TMiniDisplayIconType aIcon) StephaneLenclud@31: { StephaneLenclud@32: return ((GraphicDisplay*)aDevice)->IconCount(aIcon); StephaneLenclud@32: } StephaneLenclud@31: StephaneLenclud@31: //------------------------------------------------------------- StephaneLenclud@32: int MiniDisplayIconStatusCount(MiniDisplayDevice aDevice, TMiniDisplayIconType aIcon) StephaneLenclud@31: { StephaneLenclud@32: return ((GraphicDisplay*)aDevice)->IconStatusCount(aIcon); StephaneLenclud@32: } StephaneLenclud@31: StephaneLenclud@31: //------------------------------------------------------------- StephaneLenclud@32: void MiniDisplaySetIconStatus(MiniDisplayDevice aDevice, TMiniDisplayIconType aIcon, int aIndex, int aStatus) StephaneLenclud@31: { StephaneLenclud@32: ((GraphicDisplay*)aDevice)->SetIconStatus(aIcon,aIndex,aStatus); StephaneLenclud@32: }