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

0001 /***************************************************************************
0002  *   Copyright (C) 2003-2005 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 EC4BITCOUNTER_H
0012 #define EC4BITCOUNTER_H
0013 
0014 #include "component.h"
0015 #include "logic.h"
0016 
0017 /**
0018 Simple logic counter. 4 Inputs, 4 Outputs.
0019 
0020 Outputs (A-D) represent the stored value (0-15).
0021 The inputs are:
0022 @li en - Enable incrementing of value
0023 @li in - Input (trigger high)
0024 @li r - Reset stored value to 0
0025 @li ud - Up/Down increment
0026 
0027 @short 4 Bit Binary Counter
0028 @author David Saxton
0029 */
0030 class BinaryCounter : public CallbackClass, public Component
0031 {
0032 public:
0033     BinaryCounter(ICNDocument *icnDocument, bool newItem, const char *id = nullptr);
0034     ~BinaryCounter() override;
0035 
0036     static Item *construct(ItemDocument *itemDocument, bool newItem, const char *id);
0037     static LibraryItem *libraryItem();
0038 
0039 public: // internal interfaces
0040     void inStateChanged(bool state); // Input
0041     void rStateChanged(bool state);  // Reset
0042     void enStateChanged(bool state); // Enable
0043     void udStateChanged(bool state); // Up/Down
0044 protected:
0045     void outputValue();
0046     void dataChanged() override;
0047     void initPins(unsigned numBits);
0048 
0049     LogicIn *enLogic, *inLogic, *rLogic, *udLogic;
0050     LogicOut *m_pLogicOut[26];
0051 
0052     unsigned m_numBits;
0053     bool b_triggerHigh;
0054     bool b_en; // Enable
0055     bool b_ud; // Up/Down
0056     bool b_oldIn;
0057     bool b_reset;
0058     long m_value;
0059     long m_maxValue;
0060     bool m_bDoneLogicIn;
0061 };
0062 
0063 #endif