File: switch.h

package info (click to toggle)
gpsim 0.26.1-2.1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 11,200 kB
  • sloc: cpp: 86,839; sh: 18,875; asm: 16,815; ansic: 4,468; makefile: 1,308; lex: 1,129; yacc: 823; pascal: 177; perl: 93; awk: 44
file content (109 lines) | stat: -rw-r--r-- 2,434 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
   Copyright (C) 2002 Ralf Forsberg

This file is part of the libgpsim_modules library of gpsim

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, see 
<http://www.gnu.org/licenses/lgpl-2.1.html>.
*/




#ifndef __SWITCH_H__
#define __SWITCH_H__

/* IN_MODULE should be defined for modules */
#define IN_MODULE

#include "../src/stimuli.h"
#include "../src/modules.h"

#ifdef HAVE_GUI
#include <gtk/gtk.h>
#else
struct GtkToggleButton;
#endif

namespace Switches {
  class SwitchPin;       // defined and implemented in switch.cc
  class SwitchAttribute; //    "            "

  class SwitchBase : public Module, public TriggerObject

  {
  public:

    SwitchBase(const char *_name, const char *_desc);
    ~SwitchBase();


    void update();
    virtual void setState(bool);


    // Inheritances from the Package class
    virtual void create_iopin_map();

    // Inheritance from Module class
    const virtual char *type() { return ("switch"); };


    virtual void do_voltage();
    virtual bool switch_closed() { return m_bCurrentState; }
    virtual SwitchPin * other_pin(SwitchPin *pin);


    // Attributes call back into the switch through here:
    double getZopen();
    double getZclosed();

  protected:
    SwitchPin *m_pinA;
    SwitchPin *m_pinB;

    // State of the switch
    bool m_bCurrentState;
    SwitchAttribute *m_aState;


    // Switch resistance.
    Float *m_Zopen;
    Float *m_Zclosed;

  };


  class Switch : public SwitchBase
  {
  public:
    Switch(const char *_name);
    ~Switch();

    virtual void setState(bool);
    void buttonToggled();

    static Module *construct(const char *new_name);

  protected:
    // The switch's graphical representation.
    GtkToggleButton *m_button;

  private:
    void create_widget(Switch *sw);
    static void cb_buttonToggle(GtkToggleButton *button, SwitchBase *This);
  };

}
#endif //  __SWITCH_H__