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

0001 /***************************************************************************
0002  *   Copyright (C) 2003 by David Saxton                                    *
0003  *   david@bluehaze.org                                                    *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  ***************************************************************************/
0010 
0011 #ifndef LED_H
0012 #define LED_H
0013 
0014 #include "component.h"
0015 #include "ecdiode.h"
0016 
0017 /**
0018 @short Simulates a LED
0019 @author David Saxton
0020 */
0021 class LED : public ECDiode
0022 {
0023 public:
0024     LED(ICNDocument *icnDocument, bool newItem, const char *id = nullptr);
0025     ~LED() override;
0026 
0027     static Item *construct(ItemDocument *itemDocument, bool newItem, const char *id);
0028     static LibraryItem *libraryItem();
0029 
0030     /**
0031      * Returns the brightness for the given current, from 255 (off) -> 0 (on)
0032      */
0033     static uint brightness(double i);
0034 
0035     void dataChanged() override;
0036     void stepNonLogic() override;
0037     bool doesStepNonLogic() const override
0038     {
0039         return true;
0040     }
0041 
0042 private:
0043     void drawShape(QPainter &p) override;
0044 
0045     double r, g, b;
0046 
0047     double avg_brightness;
0048     uint last_brightness;
0049     double lastUpdatePeriod;
0050 };
0051 
0052 #endif