Switching our marquee implementation from animator to animation to avoid lags.
1 #include "minidisplay.h"
5 const int KMaxReadAttempt=100;
7 MiniDisplay::MiniDisplay(QQuickItem *parent):
8 QQuickItem(parent),iReadAttempt(0),iBrightness(iDisplay.MaxBrightness())
10 // By default, QQuickItem does not draw anything. If you subclass
11 // QQuickItem to create a visual item, you will need to uncomment the
12 // following line and re-implement updatePaintNode()
14 // setFlag(ItemHasContents, true);
16 //qDebug() << "New MiniDisplay";
19 MiniDisplay::~MiniDisplay()
21 //qDebug() << "Delete MiniDisplay";
26 void MiniDisplay::open()
30 iDisplay.SetBrightness(iBrightness);
41 void MiniDisplay::close()
43 //qDebug() << "MiniDisplay::close";
44 //Try to put back ourframe position to RAM 0,0 which is a multiple of 128
45 if (iDisplay.IsOpen())
49 if (iDisplay.DisplayPositionY()%128!=0)
51 //qDebug() << "SwapBuffer to put back our frame position to zero " << iDisplay.DisplayPositionY();
52 iDisplay.SwapBuffers();
60 bool MiniDisplay::isOpen()
62 return iDisplay.IsOpen();
65 void MiniDisplay::clear()
67 if (!iDisplay.IsOpen()) return;
72 void MiniDisplay::fill()
74 if (!iDisplay.IsOpen()) return;
76 iDisplay.SetAllPixels(0xFF);
79 void MiniDisplay::swapBuffers()
81 if (!iDisplay.IsOpen()) return;
83 iDisplay.SwapBuffers();
86 void MiniDisplay::requestPowerStatus()
88 if (!iDisplay.IsOpen()) return;
90 iDisplay.RequestPowerSupplyStatus();
91 QTimer::singleShot(4, this, SLOT(readTimer()));
95 void MiniDisplay::requestDeviceId()
97 if (!iDisplay.IsOpen()) return;
99 iDisplay.RequestDeviceId();
100 QTimer::singleShot(4, this, SLOT(readTimer()));
104 void MiniDisplay::requestFirmwareVersion()
106 if (!iDisplay.IsOpen()) return;
108 iDisplay.RequestFirmwareRevision();
109 QTimer::singleShot(4, this, SLOT(readTimer()));
119 void MiniDisplay::setFont(const QFont& aFont)
122 iFont.setStyleStrategy(QFont::NoAntialias);
123 QString strDemo="0123456789ABCDEF";
124 QFontMetrics metrics(iFont);
125 int w=metrics.boundingRect(strDemo).width();
126 int h=metrics.height();
127 //int h=metrics.boundingRect(strDemo).height();
129 //Rendering in mono is quite broken we need RGB32
130 QImage image(size,QImage::Format_RGB32);
131 image.fill(0xFFFFFFFF);
132 //Draw some text into our image
134 QPainter painter(&image);
135 painter.setPen(0xFF000000);
136 painter.setFont(iFont);
137 painter.drawText(0,metrics.ascent(),strDemo);
139 //Save image as PNG for validation
140 //image.save("font.png");
146 * @brief MiniDisplay::renderWindow
148 void MiniDisplay::renderOwnWindow()
150 QImage image=window()->grabWindow();
151 //image.save("window.png");
156 * @brief MiniDisplay::render
159 void MiniDisplay::renderWindow(QQuickWindow* aWindow)
161 QImage image=aWindow->grabWindow();
162 //image.save("window.png");
167 * @brief MiniDisplay::render
170 void MiniDisplay::renderImage(QImage* aImage)
172 if (!iDisplay.IsOpen())
177 //Convert our image into a bit array
178 int w=aImage->width();
179 int h=aImage->height();
182 BitArray bits(pixelCount);
184 for (int i=0;i<w;i++)
186 for (int j=0;j<h;j++)
188 QRgb color=aImage->pixel(i,j);
189 if (color!=0xffffffff)
197 iDisplay.BitBlit(bits,w,h,0,0);
201 * @brief MiniDisplay::setPixel
206 void MiniDisplay::setPixel(int x, int y, bool on)
208 if (!iDisplay.IsOpen())
213 iDisplay.SetPixel(x,y,on);
217 * @brief MiniDisplay::offScreenMode
220 bool MiniDisplay::offScreenMode()
222 return iDisplay.OffScreenMode();
226 * @brief MiniDisplay::setOffScreenMode
229 void MiniDisplay::setOffScreenMode(bool aOn)
231 if (!iDisplay.IsOpen())
236 iDisplay.SetOffScreenMode(aOn);
243 * @brief MiniDisplay::vendor
246 QString MiniDisplay::vendor()
248 return QString::fromWCharArray(iDisplay.Vendor());
252 * @brief MiniDisplay::product
255 QString MiniDisplay::product()
257 return QString::fromWCharArray(iDisplay.Product());
261 * @brief MiniDisplay::serialNumber
264 QString MiniDisplay::serialNumber()
266 return QString::fromWCharArray(iDisplay.SerialNumber());
270 * @brief MiniDisplay::readTimer
271 * Called when our read timer completes.
272 * We then attempt to complete our pending display request.
273 * We typically attempt to read an input report from our HID device.
275 void MiniDisplay::readTimer()
277 if (!iDisplay.IsOpen()) return;
278 if (!iDisplay.RequestPending()) return;
281 GP1212A01A::Request request = iDisplay.AttemptRequestCompletion();
285 if (iReadAttempt<KMaxReadAttempt)
287 //Will try again later
288 QTimer::singleShot(4, this, SLOT(readTimer()));
294 //TODO: Find a way to remove device specific stuff from here
295 if (request==GP1212A01A::ERequestFirmwareRevision)
297 QString version=QString::fromLocal8Bit((const char*)iDisplay.InputReport().Buffer()+1);
298 emit firmwareVersion(version);
300 else if (request==GP1212A01A::ERequestDeviceId)
302 QString id=QString::fromLocal8Bit((const char*)iDisplay.InputReport().Buffer()+1);
305 else if (request==GP1212A01A::ERequestPowerSupplyStatus)
307 emit powerStatus(iDisplay.PowerOn());
312 int MiniDisplay::maxBrightness() const
314 return iDisplay.MaxBrightness();
317 int MiniDisplay::minBrightness() const
319 return iDisplay.MinBrightness();
322 int MiniDisplay::brightness() const
327 void MiniDisplay::setBrightness(int aBrightness)
329 //Still track the brightness when disconnected
330 iBrightness=aBrightness;
332 if (!iDisplay.IsOpen()) return;
334 iDisplay.SetBrightness(aBrightness);
338 @brief MiniDisplay::frameDifferencing
341 bool MiniDisplay::frameDifferencing() const
343 return iDisplay.FrameDifferencing();
347 @brief MiniDisplay::setFrameDifferencing
350 void MiniDisplay::setFrameDifferencing(bool aOn)
352 iDisplay.SetFrameDifferencing(aOn);
356 QPoint MiniDisplay::framePosition() const
358 return QPoint(iDisplay.DisplayPositionX(),iDisplay.DisplayPositionX());
361 void MiniDisplay::setFramePosition(const QPoint& aPoint)
363 iFramePosition = aPoint;
365 if (!iDisplay.IsOpen()) return;
367 iDisplay.SetDisplayPosition(aPoint.x(),aPoint.y());