File indexing completed on 2024-05-05 05:46:06

0001 /***************************************************************************
0002  *   Copyright (C) 2006 by William Hillerby - william.hillerby@ntlworld.com*
0003  *                                                                         *
0004  *   This program is free software; you can redistribute it and/or modify  *
0005  *   it under the terms of the GNU General Public License as published by  *
0006  *   the Free Software Foundation; either version 2 of the License, or     *
0007  *   (at your option) any later version.                                   *
0008  ***************************************************************************/
0009 
0010 #ifndef LEDBARGRAPHDISPLAY_H
0011 #define LEDBARGRAPHDISPLAY_H
0012 
0013 #include "diode.h"
0014 #include <component.h>
0015 
0016 // #include <q3valuevector.h>
0017 #include <QStringList>
0018 
0019 /**
0020 @author William Hillerby
0021 @short Simulates an LED Bar Graph Display
0022 */
0023 
0024 const unsigned int max_LED_rows = 24;
0025 
0026 class LEDPart
0027 {
0028 public:
0029     LEDPart(Component *pParent, const QString &strPNode, const QString &strNNode);
0030     ~LEDPart();
0031 
0032     void setDiodeSettings(const DiodeSettings &ds);
0033     void setColor(const QColor &color);
0034     void step();
0035 
0036     void draw(QPainter &p, int x, int y, int w, int h);
0037 
0038 private:
0039     Component *m_pParent;
0040     Diode *m_pDiode;
0041     DiodeSettings ds;
0042     QString m_strPNode, m_strNNode;
0043 
0044     double r, g, b;
0045     double lastUpdatePeriod;
0046     double avg_brightness;
0047     uint last_brightness;
0048 };
0049 
0050 class LEDBarGraphDisplay : public Component
0051 {
0052 public:
0053     LEDBarGraphDisplay(ICNDocument *icnDocument, bool newItem, const QString &id = nullptr);
0054     ~LEDBarGraphDisplay() override;
0055 
0056     static Item *construct(ItemDocument *itemDocument, bool newItem, const char *id);
0057     static LibraryItem *libraryItem();
0058 
0059 private:
0060     void initPins();
0061     void dataChanged() override;
0062 
0063     void stepNonLogic() override;
0064     bool doesStepNonLogic() const override
0065     {
0066         return true;
0067     }
0068     void drawShape(QPainter &p) override;
0069 
0070     LEDPart *m_LEDParts[max_LED_rows];
0071     unsigned int m_numRows;
0072 };
0073 
0074 #endif