File: switch.h

package info (click to toggle)
gpsim 0.32.1-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 16,644 kB
  • sloc: cpp: 121,258; asm: 54,223; ansic: 13,576; python: 9,708; sh: 4,695; makefile: 1,688; lex: 1,139; yacc: 854; pascal: 511; perl: 93; awk: 44; xml: 41
file content (107 lines) | stat: -rw-r--r-- 2,421 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
/*
   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 MODULES_SWITCH_H_
#define MODULES_SWITCH_H_

/* IN_MODULE should be defined for modules */
#define IN_MODULE
#include "../config.h"
#include "../src/modules.h"
#include "../src/trigger.h"
class Float;

#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:
  explicit Switch(const char *_name = nullptr);
  ~Switch();

  void setState(bool) override;
  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 //  MODULES_SWITCH_H_