1. Pierre Surply
  2. RoadMaster

Commits

Pierre Surply  committed 468008b

Creation classe calibration

  • Participants
  • Parent commits 720a5aa
  • Branches master

Comments (0)

Files changed (11)

File roadmaster.pro

View file
  • Ignore whitespace
 CONFIG -= buildQuicklaunch
 DESTDIR = $(PWD)
 
-HEADERS = src/roadmaster.h \
-          src/gpio.h       \
-          src/sensor.h     
+HEADERS = src/calibration.h \
+          src/gpio.h        \
+          src/sensor.h      \
+          src/roadmaster.h 
+          
+          
 
-SOURCES = src/roadmaster.cpp \
-          src/gpio.cpp       \
-          src/sensor.cpp     
+SOURCES = src/gpio.cpp        \
+          src/calibration.cpp \
+          src/sensor.cpp      \
+          src/roadmaster.cpp  \
 
 SOURCES += src/main.cpp
 

File src/calibration.cpp

View file
  • Ignore whitespace
+/*
+  calibration.cpp
+
+  Pierre Surply
+  Time-stamp: <2012-04-12 22:22:53 surply_p>
+ */
+
+#include "sensor.h"
+#include "calibration.h"
+
+Calibr::Calibr(Sensor* sensor)
+{
+  m_run = false;
+  m_sensor = sensor;
+}
+
+Calibr::~Calibr()
+{
+}
+
+void Calibr::set(const bool run)
+{
+  m_run = run;
+  if (m_run)
+    {
+      m_sensor->set_tpm(1);
+    }
+}
+
+bool Calibr::is_running() const
+{
+  return m_run;
+}

File src/calibration.h

View file
  • Ignore whitespace
+/*
+  calibration.h
+
+  Pierre Surply
+  Time-stamp: <2012-04-12 22:11:41 surply_p>
+ */
+
+#ifndef CAL_H
+#define CAL_H
+
+class Sensor;
+
+class Calibr
+{
+ public:
+  Calibr(Sensor* sensor);
+  ~Calibr();
+  void set(const bool run);
+  bool is_running() const;
+
+ private:
+  bool m_run;
+  Sensor* m_sensor;
+};
+
+#endif

File src/gpio.cpp

View file
  • Ignore whitespace
   gpio.cpp
 
   Pierre Surply
-  Time-stamp: <2012-04-11 21:20:23 surply_p>
+  Time-stamp: <2012-04-12 22:22:39 surply_p>
  */
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
+
 #include "gpio.h"
 
 GPIO::GPIO()

File src/gpio.h

View file
  • Ignore whitespace
   gpio.h
 
   Pierre Surply
-  Time-stamp: <2012-04-11 21:20:17 surply_p>
+  Time-stamp: <2012-04-12 22:20:53 surply_p>
  */
 #ifndef GPIO_H
 #define GPIO_H

File src/main.cpp

View file
  • Ignore whitespace
    main.cpp
 
    Pierre Surply
-   Time-stamp: <2012-04-11 18:29:27 surply_p>
+   Time-stamp: <2012-04-12 22:19:26 surply_p>
 */
 
 #include "roadmaster.h"

File src/roadmaster.cpp

View file
  • Ignore whitespace
   RoadMaster.cpp
 
   Pierre Surply
-  Time-stamp: <2012-04-11 18:28:54 surply_p>
+  Time-stamp: <2012-04-12 22:26:29 surply_p>
  */
 
 #include "roadmaster.h"
 
-RoadMaster::RoadMaster(QWidget* parent,
-		       const char* name,
-		       WFlags fl):
-  RoadMasterBase(parent, name, fl)
+#include <qpushbutton.h>
+
+RoadMaster::RoadMaster(QWidget* parent, const char* name, WFlags fl):RoadMasterBase(parent, name, fl)
 {
+  m_sensor = new Sensor(this);
+  m_calibr = new Calibr(m_sensor);
+
+  connect(SetEta, SIGNAL(clicked()), this, SLOT(run_calibr()));
 }
 
 RoadMaster::~RoadMaster()
 {
 }
+
+void RoadMaster::update()
+{
+  if (m_calibr->is_running())
+    {
+    }
+}
+
+void RoadMaster::run_calibr()
+{
+  if (!m_calibr->is_running())
+    {
+      m_calibr->set(true);
+      SetEta->setText("Arreter l'etalonage");
+    }
+  else
+    {
+      m_calibr->set(false);
+      SetEta->setText("Recommencer l'etalonage");
+    }
+}

File src/roadmaster.h

View file
  • Ignore whitespace
   RoadMaster.h
 
   Pierre Surply
-  Time-stamp: <2012-04-11 21:21:45 surply_p>
+  Time-stamp: <2012-04-12 22:21:47 surply_p>
 */
 #ifndef ROADMASTER_H
 #define ROADMASTER_H
 
 #include "roadmaster_base.h"
+#include "calibration.h"
 #include "sensor.h"
 
 class RoadMaster : public RoadMasterBase
 {
-  
+  Q_OBJECT
+
  public:
-  RoadMaster(QWidget* parent = 0,
-	     const char* name = 0,
-	     WFlags fl = 0);
+  RoadMaster(QWidget* parent = 0, const char* name = 0, WFlags fl = 0);
   ~RoadMaster();
+  void update();
+  
+ public slots:
+  void run_calibr();
 
  private:
   Sensor* m_sensor;
+  Calibr* m_calibr;
 };
 
 #endif

File src/roadmaster_base.ui

View file
  • Ignore whitespace
         </property>
     </widget>
     <widget>
-        <class>QGroupBox</class>
-        <property stdset="1">
-            <name>name</name>
-            <cstring>Time</cstring>
-        </property>
-        <property stdset="1">
-            <name>geometry</name>
-            <rect>
-                <x>0</x>
-                <y>210</y>
-                <width>241</width>
-                <height>70</height>
-            </rect>
-        </property>
-        <property stdset="1">
-            <name>title</name>
-            <string>Temps</string>
-        </property>
-        <widget>
-            <class>QLabel</class>
-            <property stdset="1">
-                <name>name</name>
-                <cstring>Temps</cstring>
-            </property>
-            <property stdset="1">
-                <name>geometry</name>
-                <rect>
-                    <x>10</x>
-                    <y>20</y>
-                    <width>220</width>
-                    <height>40</height>
-                </rect>
-            </property>
-            <property stdset="1">
-                <name>frameShape</name>
-                <enum>Panel</enum>
-            </property>
-            <property stdset="1">
-                <name>frameShadow</name>
-                <enum>Raised</enum>
-            </property>
-            <property stdset="1">
-                <name>text</name>
-                <string>0:00:00</string>
-            </property>
-            <property stdset="1">
-                <name>alignment</name>
-                <set>AlignVCenter|AlignRight</set>
-            </property>
-            <property>
-                <name>hAlign</name>
-            </property>
-        </widget>
-    </widget>
-    <widget>
         <class>QLabel</class>
         <property stdset="1">
             <name>name</name>
         </property>
     </widget>
     <widget>
-        <class>QGroupBox</class>
-        <property stdset="1">
-            <name>name</name>
-            <cstring>Vitesse</cstring>
-        </property>
-        <property stdset="1">
-            <name>geometry</name>
-            <rect>
-                <x>0</x>
-                <y>101</y>
-                <width>240</width>
-                <height>100</height>
-            </rect>
-        </property>
-        <property stdset="1">
-            <name>title</name>
-            <string>Vitesse (km/h)</string>
-        </property>
-        <widget>
-            <class>QLabel</class>
-            <property stdset="1">
-                <name>name</name>
-                <cstring>TextLabel3</cstring>
-            </property>
-            <property stdset="1">
-                <name>geometry</name>
-                <rect>
-                    <x>10</x>
-                    <y>60</y>
-                    <width>60</width>
-                    <height>20</height>
-                </rect>
-            </property>
-            <property stdset="1">
-                <name>text</name>
-                <string>Moyenne</string>
-            </property>
-        </widget>
-        <widget>
-            <class>QLabel</class>
-            <property stdset="1">
-                <name>name</name>
-                <cstring>TxtMoyenne</cstring>
-            </property>
-            <property stdset="1">
-                <name>geometry</name>
-                <rect>
-                    <x>10</x>
-                    <y>19</y>
-                    <width>61</width>
-                    <height>31</height>
-                </rect>
-            </property>
-            <property stdset="1">
-                <name>text</name>
-                <string>Instant.</string>
-            </property>
-        </widget>
-        <widget>
-            <class>QLCDNumber</class>
-            <property stdset="1">
-                <name>name</name>
-                <cstring>VitesseMoy</cstring>
-            </property>
-            <property stdset="1">
-                <name>geometry</name>
-                <rect>
-                    <x>90</x>
-                    <y>60</y>
-                    <width>141</width>
-                    <height>30</height>
-                </rect>
-            </property>
-            <property stdset="1">
-                <name>numDigits</name>
-                <number>9</number>
-            </property>
-            <property stdset="1">
-                <name>segmentStyle</name>
-                <enum>Flat</enum>
-            </property>
-        </widget>
-        <widget>
-            <class>QLCDNumber</class>
-            <property stdset="1">
-                <name>name</name>
-                <cstring>VitesseInst</cstring>
-            </property>
-            <property stdset="1">
-                <name>geometry</name>
-                <rect>
-                    <x>90</x>
-                    <y>20</y>
-                    <width>141</width>
-                    <height>30</height>
-                </rect>
-            </property>
-            <property stdset="1">
-                <name>numDigits</name>
-                <number>9</number>
-            </property>
-            <property stdset="1">
-                <name>segmentStyle</name>
-                <enum>Flat</enum>
-            </property>
-        </widget>
-    </widget>
-    <widget>
-        <class>QGroupBox</class>
+        <class>QTabWidget</class>
         <property stdset="1">
             <name>name</name>
-            <cstring>Distance</cstring>
+            <cstring>Tab</cstring>
         </property>
         <property stdset="1">
             <name>geometry</name>
                 <x>0</x>
                 <y>0</y>
                 <width>240</width>
-                <height>100</height>
+                <height>270</height>
             </rect>
         </property>
-        <property stdset="1">
-            <name>title</name>
-            <string>Distance (km)</string>
-        </property>
-        <widget>
-            <class>Line</class>
-            <property stdset="1">
-                <name>name</name>
-                <cstring>Line1</cstring>
-            </property>
-            <property stdset="1">
-                <name>geometry</name>
-                <rect>
-                    <x>170</x>
-                    <y>30</y>
-                    <width>20</width>
-                    <height>20</height>
-                </rect>
-            </property>
-            <property stdset="1">
-                <name>orientation</name>
-                <enum>Horizontal</enum>
-            </property>
-        </widget>
         <widget>
-            <class>QLCDNumber</class>
+            <class>QWidget</class>
             <property stdset="1">
                 <name>name</name>
-                <cstring>DistanceTot</cstring>
-            </property>
-            <property stdset="1">
-                <name>geometry</name>
-                <rect>
-                    <x>10</x>
-                    <y>20</y>
-                    <width>220</width>
-                    <height>30</height>
-                </rect>
-            </property>
-            <property stdset="1">
-                <name>numDigits</name>
-                <number>15</number>
-            </property>
-            <property stdset="1">
-                <name>segmentStyle</name>
-                <enum>Flat</enum>
-            </property>
+                <cstring>home</cstring>
+            </property>
+            <attribute>
+                <name>title</name>
+                <string>Home</string>
+            </attribute>
+            <widget>
+                <class>QGroupBox</class>
+                <property stdset="1">
+                    <name>name</name>
+                    <cstring>Distance</cstring>
+                </property>
+                <property stdset="1">
+                    <name>geometry</name>
+                    <rect>
+                        <x>0</x>
+                        <y>0</y>
+                        <width>240</width>
+                        <height>100</height>
+                    </rect>
+                </property>
+                <property stdset="1">
+                    <name>title</name>
+                    <string>Distance (km)</string>
+                </property>
+                <widget>
+                    <class>Line</class>
+                    <property stdset="1">
+                        <name>name</name>
+                        <cstring>Line1</cstring>
+                    </property>
+                    <property stdset="1">
+                        <name>geometry</name>
+                        <rect>
+                            <x>170</x>
+                            <y>30</y>
+                            <width>20</width>
+                            <height>20</height>
+                        </rect>
+                    </property>
+                    <property stdset="1">
+                        <name>orientation</name>
+                        <enum>Horizontal</enum>
+                    </property>
+                </widget>
+                <widget>
+                    <class>QPushButton</class>
+                    <property stdset="1">
+                        <name>name</name>
+                        <cstring>ResetPart</cstring>
+                    </property>
+                    <property stdset="1">
+                        <name>geometry</name>
+                        <rect>
+                            <x>10</x>
+                            <y>20</y>
+                            <width>80</width>
+                            <height>32</height>
+                        </rect>
+                    </property>
+                    <property stdset="1">
+                        <name>text</name>
+                        <string>Reset</string>
+                    </property>
+                </widget>
+                <widget>
+                    <class>QLCDNumber</class>
+                    <property stdset="1">
+                        <name>name</name>
+                        <cstring>DistancePart</cstring>
+                    </property>
+                    <property stdset="1">
+                        <name>geometry</name>
+                        <rect>
+                            <x>100</x>
+                            <y>20</y>
+                            <width>130</width>
+                            <height>30</height>
+                        </rect>
+                    </property>
+                    <property stdset="1">
+                        <name>numDigits</name>
+                        <number>8</number>
+                    </property>
+                    <property stdset="1">
+                        <name>segmentStyle</name>
+                        <enum>Flat</enum>
+                    </property>
+                </widget>
+                <widget>
+                    <class>QLCDNumber</class>
+                    <property stdset="1">
+                        <name>name</name>
+                        <cstring>DistanceTot</cstring>
+                    </property>
+                    <property stdset="1">
+                        <name>geometry</name>
+                        <rect>
+                            <x>10</x>
+                            <y>60</y>
+                            <width>220</width>
+                            <height>30</height>
+                        </rect>
+                    </property>
+                    <property stdset="1">
+                        <name>numDigits</name>
+                        <number>15</number>
+                    </property>
+                    <property stdset="1">
+                        <name>segmentStyle</name>
+                        <enum>Flat</enum>
+                    </property>
+                </widget>
+            </widget>
+            <widget>
+                <class>QGroupBox</class>
+                <property stdset="1">
+                    <name>name</name>
+                    <cstring>Vitesse</cstring>
+                </property>
+                <property stdset="1">
+                    <name>geometry</name>
+                    <rect>
+                        <x>0</x>
+                        <y>100</y>
+                        <width>240</width>
+                        <height>60</height>
+                    </rect>
+                </property>
+                <property stdset="1">
+                    <name>title</name>
+                    <string>Vitesse (km/h)</string>
+                </property>
+                <widget>
+                    <class>QLCDNumber</class>
+                    <property stdset="1">
+                        <name>name</name>
+                        <cstring>VitesseInst</cstring>
+                    </property>
+                    <property stdset="1">
+                        <name>geometry</name>
+                        <rect>
+                            <x>130</x>
+                            <y>20</y>
+                            <width>100</width>
+                            <height>30</height>
+                        </rect>
+                    </property>
+                    <property stdset="1">
+                        <name>numDigits</name>
+                        <number>9</number>
+                    </property>
+                    <property stdset="1">
+                        <name>segmentStyle</name>
+                        <enum>Flat</enum>
+                    </property>
+                </widget>
+                <widget>
+                    <class>QLCDNumber</class>
+                    <property stdset="1">
+                        <name>name</name>
+                        <cstring>VitesseMoy</cstring>
+                    </property>
+                    <property stdset="1">
+                        <name>geometry</name>
+                        <rect>
+                            <x>10</x>
+                            <y>20</y>
+                            <width>100</width>
+                            <height>30</height>
+                        </rect>
+                    </property>
+                    <property stdset="1">
+                        <name>numDigits</name>
+                        <number>9</number>
+                    </property>
+                    <property stdset="1">
+                        <name>segmentStyle</name>
+                        <enum>Flat</enum>
+                    </property>
+                </widget>
+            </widget>
+            <widget>
+                <class>QGroupBox</class>
+                <property stdset="1">
+                    <name>name</name>
+                    <cstring>Time</cstring>
+                </property>
+                <property stdset="1">
+                    <name>geometry</name>
+                    <rect>
+                        <x>0</x>
+                        <y>160</y>
+                        <width>241</width>
+                        <height>80</height>
+                    </rect>
+                </property>
+                <property stdset="1">
+                    <name>title</name>
+                    <string>Temps</string>
+                </property>
+                <widget>
+                    <class>QLCDNumber</class>
+                    <property stdset="1">
+                        <name>name</name>
+                        <cstring>Heure</cstring>
+                    </property>
+                    <property stdset="1">
+                        <name>geometry</name>
+                        <rect>
+                            <x>10</x>
+                            <y>30</y>
+                            <width>70</width>
+                            <height>20</height>
+                        </rect>
+                    </property>
+                    <property stdset="1">
+                        <name>numDigits</name>
+                        <number>9</number>
+                    </property>
+                    <property stdset="1">
+                        <name>segmentStyle</name>
+                        <enum>Flat</enum>
+                    </property>
+                </widget>
+                <widget>
+                    <class>QLCDNumber</class>
+                    <property stdset="1">
+                        <name>name</name>
+                        <cstring>Minuterie</cstring>
+                    </property>
+                    <property stdset="1">
+                        <name>geometry</name>
+                        <rect>
+                            <x>10</x>
+                            <y>50</y>
+                            <width>70</width>
+                            <height>20</height>
+                        </rect>
+                    </property>
+                    <property stdset="1">
+                        <name>numDigits</name>
+                        <number>9</number>
+                    </property>
+                    <property stdset="1">
+                        <name>segmentStyle</name>
+                        <enum>Flat</enum>
+                    </property>
+                </widget>
+                <widget>
+                    <class>QLCDNumber</class>
+                    <property stdset="1">
+                        <name>name</name>
+                        <cstring>LCDNumber7</cstring>
+                    </property>
+                    <property stdset="1">
+                        <name>geometry</name>
+                        <rect>
+                            <x>91</x>
+                            <y>30</y>
+                            <width>140</width>
+                            <height>40</height>
+                        </rect>
+                    </property>
+                    <property stdset="1">
+                        <name>segmentStyle</name>
+                        <enum>Flat</enum>
+                    </property>
+                </widget>
+            </widget>
         </widget>
         <widget>
-            <class>QLCDNumber</class>
+            <class>QWidget</class>
             <property stdset="1">
                 <name>name</name>
-                <cstring>DistancePart</cstring>
-            </property>
-            <property stdset="1">
-                <name>geometry</name>
-                <rect>
-                    <x>10</x>
-                    <y>60</y>
-                    <width>130</width>
-                    <height>30</height>
-                </rect>
-            </property>
-            <property stdset="1">
-                <name>numDigits</name>
-                <number>8</number>
-            </property>
-            <property stdset="1">
-                <name>segmentStyle</name>
-                <enum>Flat</enum>
-            </property>
+                <cstring>etalonage</cstring>
+            </property>
+            <attribute>
+                <name>title</name>
+                <string>Etalonage</string>
+            </attribute>
+            <widget>
+                <class>QPushButton</class>
+                <property stdset="1">
+                    <name>name</name>
+                    <cstring>SetEta</cstring>
+                </property>
+                <property stdset="1">
+                    <name>geometry</name>
+                    <rect>
+                        <x>8</x>
+                        <y>53</y>
+                        <width>221</width>
+                        <height>50</height>
+                    </rect>
+                </property>
+                <property stdset="1">
+                    <name>text</name>
+                    <string>Commencer l'étalonage</string>
+                </property>
+            </widget>
+            <widget>
+                <class>QLCDNumber</class>
+                <property stdset="1">
+                    <name>name</name>
+                    <cstring>NbrImpuls</cstring>
+                </property>
+                <property stdset="1">
+                    <name>geometry</name>
+                    <rect>
+                        <x>9</x>
+                        <y>3</y>
+                        <width>220</width>
+                        <height>41</height>
+                    </rect>
+                </property>
+                <property stdset="1">
+                    <name>numDigits</name>
+                    <number>12</number>
+                </property>
+                <property stdset="1">
+                    <name>segmentStyle</name>
+                    <enum>Flat</enum>
+                </property>
+            </widget>
         </widget>
         <widget>
-            <class>QPushButton</class>
+            <class>QWidget</class>
             <property stdset="1">
                 <name>name</name>
-                <cstring>ResetPart</cstring>
-            </property>
-            <property stdset="1">
-                <name>geometry</name>
-                <rect>
-                    <x>150</x>
-                    <y>60</y>
-                    <width>80</width>
-                    <height>32</height>
-                </rect>
-            </property>
-            <property stdset="1">
-                <name>text</name>
-                <string>Reset</string>
+                <cstring>tab</cstring>
             </property>
+            <attribute>
+                <name>title</name>
+                <string>Paramètres</string>
+            </attribute>
         </widget>
     </widget>
 </widget>

File src/sensor.cpp

View file
  • Ignore whitespace
   sensor.cpp
 
   Pierre Surply
-  Time-stamp: <2012-04-11 21:17:45 surply_p>
+  Time-stamp: <2012-04-12 22:17:20 surply_p>
  */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <time.h>
+#include "gpio.h"
+#include "calibration.h"
 #include "sensor.h"
+#include "roadmaster.h"
 
-Sensor::Sensor()
+Sensor::Sensor(RoadMaster* parent)
 {
+
+  m_parent = parent;
+
+#ifdef __arm__
   m_gpio = new GPIO();
   m_gpio->open_port(PORT);
-  m_accu = 0;
-  m_rec = false;
+#endif
+
+  m_rec = true;
+  m_tpm = 1;
 }
 
 Sensor::~Sensor()
 {
 }
 
+void Sensor::set_tpm(const int tpm)
+{
+  m_tpm = tpm;
+}
+
+void Sensor::reset()
+{
+  double current_tps = (double) time(NULL);
+  m_begin_tps = current_tps;
+  m_last_tps = current_tps;
+
+  m_accu = 0;
+}
+
 void Sensor::count()
 {
-  bool last_state;
+  bool last_state = false;
   bool state;
 
   while(m_rec)
       if (state && !last_state)
 	{
 	  m_accu++;
+	  if (m_accu >= m_tpm)
+	    {
+	      this->add_distance(10);
+	      m_parent->update();
+	      m_accu = 0;
+	    }
 	  last_state = state;
 	}
       last_state = state;
     }
 }
 
-void Sensor::set_rec(const bool rec)
+void Sensor::add_distance(const int step)
 {
-  m_rec = rec;
+  m_distance_tot += step;
+  m_distance_part += step;
 }

File src/sensor.h

View file
  • Ignore whitespace
   sensor.h
 
   Pierre Surply
-  Time-stamp: <2012-04-11 21:16:59 surply_p>
+  Time-stamp: <2012-04-12 22:20:29 surply_p>
  */
 #ifndef SENSOR_H
 #define SENSOR_H
 
-#include "gpio.h"
-
 #define PORT 192
 
-/*
-class Counter
-{
- public:
-  Counter(const int init);
-  ~Counter();
-  
- private:
-  int m_unit;
-  int m_dix;
-};
-*/
+#include "gpio.h"
+
+class RoadMaster;
 
 class Sensor
 {
  public:
-  Sensor();
+  Sensor(RoadMaster* parent);
   ~Sensor();
+  void set_tpm(const int tpm);
+  void reset();
   void count();
-  void set_rec(const bool rec);
+  void add_distance(const int step);
 
  private:
+  RoadMaster* m_parent;
+  int m_distance_tot;  // m
+  int m_distance_part; // m
+  int m_accu;
+  int m_tpm;
   bool m_rec;
-  int  m_accu;
+  double m_begin_tps;
+  double m_last_tps;
   GPIO* m_gpio;
 };