File indexing completed on 2024-04-21 05:43:41

0001 /***************************************************************************
0002  *   Copyright (C) 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 OSCILLOSCOPE_H
0012 #define OSCILLOSCOPE_H
0013 
0014 #ifndef PROBE_H
0015 #ifndef KTECHLAB_H
0016 #ifndef OSCILLOSCOPEDATA_H
0017 #include <ui_oscilloscopewidget.h>
0018 #endif
0019 #endif
0020 #endif
0021 
0022 #include "simulator.h"
0023 
0024 #include <QMap>
0025 #include <QWidget>
0026 
0027 #include <stdint.h>
0028 
0029 class FloatingProbeData;
0030 class LogicProbe;
0031 class LogicProbeData;
0032 class KTechlab;
0033 class Oscilloscope;
0034 class Probe;
0035 class ProbeData;
0036 class VoltageProbe;
0037 class QTimer;
0038 namespace KateMDI
0039 {
0040 class ToolView;
0041 }
0042 
0043 typedef QMap<int, ProbeData *> ProbeDataMap;
0044 typedef QMap<int, LogicProbeData *> LogicProbeDataMap;
0045 typedef QMap<int, FloatingProbeData *> FloatingProbeDataMap;
0046 
0047 #if 0
0048 const double MAX_BITS_PER_S = 100000;
0049 
0050 // NOTE: The 10 has to agree with the 2^10 = 1024.0
0051 const int MIN_MAX_LOG_2_DIFF = 10;
0052 const double MIN_BITS_PER_S = MAX_BITS_PER_S / 1024.0;
0053 #else
0054 const double MAX_BITS_PER_S = LOGIC_UPDATE_RATE * 4;
0055 
0056 // NOTE: The 18 has to agree with the 2^18 = 262144.0
0057 const int MIN_MAX_LOG_2_DIFF = 18;
0058 const double MIN_BITS_PER_S = MAX_BITS_PER_S / 262144.0;
0059 #endif
0060 
0061 /*
0062 Due to strangeness with generation of .[cpp/h] files from .ui files (that is,
0063 my inability to sort it out neatly), files other than those in /src/gui can't
0064 see header files such as "oscilloscopewidget.h", so we have to provide some
0065 interface functions for accessing the functionality in this class
0066 */
0067 ProbeData *registerProbe(Probe *probe);
0068 void unregisterProbe(int id);
0069 void addOscilloscopeAsToolView(KTechlab *ktechlab);
0070 
0071 #ifndef PROBE_H
0072 #ifndef KTECHLAB_H
0073 #ifndef OSCILLOSCOPEDATA_H
0074 /**
0075 @author David Saxton
0076 */
0077 class Oscilloscope : public QWidget, public Ui::OscilloscopeWidget
0078 {
0079     Q_OBJECT
0080 public:
0081     static Oscilloscope *self(KateMDI::ToolView *parent = nullptr);
0082     static QString toolViewIdentifier()
0083     {
0084         return "Oscilloscope";
0085     }
0086     ~Oscilloscope() override;
0087 
0088     static bool isInstantiated();
0089 
0090     /**
0091      * Register a probe (that outputs boolean data) with the oscilloscope.
0092      * Returns a unique id that the probe can use to add data points
0093      */
0094     ProbeData *registerProbe(Probe *probe);
0095     void unregisterProbe(int id);
0096     /**
0097      * Returns the Simulator time since recording started.
0098      */
0099     uint64_t time() const;
0100     /**
0101      * Returns how much of an increment in value of the oscilloscope slider
0102      * is equivalent to one second.
0103      */
0104     int sliderTicksPerSecond() const;
0105     /**
0106      * Returns the number of pixels per second the user has requested to be
0107      * displayed.
0108      */
0109     double pixelsPerSecond() const;
0110     /**
0111      * Zoom level; a value between 0 and 1. 0 is maximum zoom out, and 1 is
0112      * maximum zoom in.
0113      */
0114     double zoomLevel() const
0115     {
0116         return m_zoomLevel;
0117     }
0118     /**
0119      * Sets the zoom level (and in the process, checks that it is within the
0120      * bounds allowed).
0121      */
0122     void setZoomLevel(double zoomLevel);
0123     /**
0124      * Returns the Simulator time as given by the current scrollbar
0125      * position.
0126      */
0127     int64_t scrollTime() const;
0128     /**
0129      * @returns pointer to probe with given id, or nullptr if no such probe exists
0130      */
0131     ProbeData *probeData(int id) const;
0132     /**
0133      * @returns the total number of probes
0134      */
0135     int numberOfProbes() const;
0136     /**
0137      * @returns number of the probe with the given id, starting from 0, or -1 if no such probe
0138      */
0139     int probeNumber(int id) const;
0140 
0141 signals:
0142     /**
0143      * Emitted when a probe is registered
0144      */
0145     void probeRegistered(int id, ProbeData *probe);
0146     /**
0147      * Emitted when a probe is unregistered
0148      */
0149     void probeUnregistered(int id);
0150 
0151 public slots:
0152     /**
0153      * Resets all recorded data
0154      */
0155     void reset();
0156     /**
0157      * Called when the zoom slider value was changed.
0158      */
0159     void slotZoomSliderChanged(int value);
0160     /**
0161      * Called when the horizontal scrollbar was scrolled by the user
0162      */
0163     void slotSliderValueChanged(int value);
0164     /**
0165      * Pause the data capture (e.g. user clicked on pause button)
0166      */
0167     void slotTogglePause();
0168 
0169 protected:
0170     void getOldestProbe();
0171 
0172     int m_nextId;
0173     ProbeData *m_oldestProbe;
0174     int m_oldestId;
0175     int m_nextColor; // For giving the probes colours
0176 
0177     ProbeDataMap m_probeDataMap;
0178     LogicProbeDataMap m_logicProbeDataMap;
0179     FloatingProbeDataMap m_floatingProbeDataMap;
0180 
0181     Simulator *m_pSimulator;
0182 
0183 protected slots:
0184     void updateScrollbars();
0185 
0186 private:
0187     Oscilloscope(KateMDI::ToolView *parent);
0188 
0189     static Oscilloscope *m_pSelf;
0190     double m_zoomLevel;
0191 
0192     friend class OscilloscopeView;
0193     friend class ProbePositioner;
0194 };
0195 
0196 #endif // OSCILLOSCOPEDATA_H
0197 #endif // KTECHLAB_H
0198 #endif // PROBE_H
0199 
0200 #endif // OSCILLOSCOPE_H