JIAWEI ZHANG / Mbed 2 deprecated ele350ku

Dependencies:   mbed

Dependents:   Exercise8_1-2-3

Fork of ele350 by JIAWEI ZHANG

Files at this revision

API Documentation at this revision

Comitter:
GGHHHH
Date:
Fri Dec 18 16:27:23 2015 +0000
Parent:
53:bbff5bff8b53
Child:
55:2260345179e1
Commit message:
h

Changed in this revision

app.cpp Show annotated file Show diff for this revision Revisions of this file
app.h Show annotated file Show diff for this revision Revisions of this file
constant_app.cpp Show annotated file Show diff for this revision Revisions of this file
sine_app.cpp Show annotated file Show diff for this revision Revisions of this file
sine_app.h Show annotated file Show diff for this revision Revisions of this file
square_app.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/app.cpp	Fri Dec 18 14:04:25 2015 +0000
+++ b/app.cpp	Fri Dec 18 16:27:23 2015 +0000
@@ -1,25 +1,27 @@
 #include "app.h"
 #include "mbed.h"
 
-App::App(string name, Serial* serialPort)
+App::App(string name, Serial* serialPort)                                 //Set name and serialPort attributes.//
 {
     this->name = name;
     this->serialPort = serialPort;
 }
 
-string App::getName()
+string App::getName()                                                    //Return value of name attribute.//
 {
     return this->name;
 }
 
-void App::start()
+void App::start()                                                        //Called when the app starts.Can be overriden by subclasses.//
 {
+    //Send a message (using the serialPort attribute) saying that the app has started. The message contains the app's name.//
     string startMessage = "Started App: " + this->name + ".\r\n";
     this->serialPort->puts(startMessage.c_str());
 }
 
-void App::stop()
+void App::stop()                                                         //Called when the app stops.Can be overriden by subclasses.// 
 {
+    //Send a message (using the serialPort attribute) saying that the app has stoped. The message contains the app's name.//
     string stopMessage = "Stopped App: " + this->name + ".\r\n";
     this->serialPort->puts(stopMessage.c_str());
 }
\ No newline at end of file
--- a/app.h	Fri Dec 18 14:04:25 2015 +0000
+++ b/app.h	Fri Dec 18 16:27:23 2015 +0000
@@ -4,16 +4,16 @@
 #include <string>
 #include "mbed.h"
 
-class App
+class App                                          //Abattract base class for all apps.//
 {
     protected:
         string name;
         Serial* serialPort;
     public:
-        App(string name, Serial* serialPort);
-        string getName();
-        virtual void start();
-        virtual void run() = 0;
-        virtual void stop();
+        App(string name, Serial* serialPort);      //Conatructor.//
+        string getName();                          //Return the name of the app.//
+        virtual void start();                      //Called when the app starts. Can be overriden by subclasses.//
+        virtual void run() = 0;                    //Called repeatedly when app runas. Must be overriden by subclass.//
+        virtual void stop();                       //Called when the app stops. Can be overriden by subclasses.//
 };
 #endif
\ No newline at end of file
--- a/constant_app.cpp	Fri Dec 18 14:04:25 2015 +0000
+++ b/constant_app.cpp	Fri Dec 18 16:27:23 2015 +0000
@@ -1,35 +1,37 @@
 #include "constant_app.h"
 
+//Constructor. Calls the bass class (App) constructor and creact an AnalogOut object.//
 ConstantApp::ConstantApp(Serial* serial) : App("Constant Voltage", serial) {
-    this->analogOut = new AnalogOut (PA_4);
-    this->amplitude = 2.95f;
+    //Set analogOut attribute to a new AnalogOut object.//
+    this->analogOut = new AnalogOut (PA_4);                                               //Set the amplitude value.//
+    this->amplitude = 3.0f;                                                              //Set the frequence value.//
 }
 
-void ConstantApp::start()
+void ConstantApp::start()                                                                 //(Overriden) Method that runs when the app starts.//
 {
-    App::start();
-    this->analogOut->write(this->amplitude/2.95f);
-    this->timer.start();
-    if ( this->amplitude > 2.95f ) {
-       this->analogOut->write(0);
-    } else { this->analogOut->write(this->amplitude/2.95f);} 
+    App::start();                                                                         //Call bass class's start() method.//
+    this->analogOut->write(this->amplitude/3.0f);                                        //Set the output to the amplitude.//
+    this->timer.start();                                                                  //Start timer.//
+    if ( this->amplitude > 3.0f ) {                                                      //Define the max amplitude value and check it.//
+       this->analogOut->write(0);                                                         //If >max value, output 0.//
+    } else { this->analogOut->write(this->amplitude/3.0f);}                              //If <max value, out the right expression.//
 
 }
 
-void ConstantApp::run()
+void ConstantApp::run()                                                                   //(Overriden) Method that is called repeatedly when the app starts.//
 {
 
 }
 
-void ConstantApp::stop()
+void ConstantApp::stop()                                                                 //(Overriden) Method that runs when the app stops.//
 {
-    App::stop();
-    this->analogOut->write(0);
-    this->timer.stop();
+    App::stop();                                                                         //Call bass class's stop() method.//
+    this->analogOut->write(0);                                                           //Set output to 0V.//
+    this->timer.stop();                                                                  //Stop the time and reset it.//
     this->timer.reset();
 }
 
-void ConstantApp::setamplitude(float newamplitude)
+void ConstantApp::setamplitude(float newamplitude)                                       //(Overriden) Method that could set amplitude.//
 {
-    this->amplitude = newamplitude;
+    this->amplitude = newamplitude;                                                      //Set the new amplitude.//
 }
\ No newline at end of file
--- a/sine_app.cpp	Fri Dec 18 14:04:25 2015 +0000
+++ b/sine_app.cpp	Fri Dec 18 16:27:23 2015 +0000
@@ -1,45 +1,47 @@
 #include "sine_app.h"
-
+ 
+ //Constructor. Calls the bass class (App) constructor and creact an AnalogOut object.//
 SineApp::SineApp(Serial* serial) : App("Sine wave", serial) {
+    //Set analogOut attribute to a new AnalogOut object.//
     this->analogOut = new AnalogOut (PA_4);
-    this->amplitude = 2.95f;
-    this->frequence = 50.0f;
+    this->amplitude = 3.0f;                                                          //Set the amplitude value.//
+    this->frequence = 50.0f;                                                          //Set the frequence value.//
 }
 
-void SineApp::start()
-{
-    App::start();
-    this->analogOut->write(this->amplitude/2.95f);
-    this->timer.start(); 
-    if ( this->amplitude > 2.95f ) {
-       this->analogOut->write(0);
-    } else { this->analogOut->write(this->amplitude/2.95f);}
+void SineApp::start()                                                                 //(Overriden) Method that runs when the app starts.//
+{               
+    App::start();                                                                     //Call bass class's start() method.//
+    this->analogOut->write(this->amplitude/3.0f);                                    //Set the output to the amplitude.//
+    this->timer.start();                                                              //Start timer.//
+    if ( this->amplitude > 3.0f ) {                                                  //Define the max amplitude value and check it.//
+       this->analogOut->write(0);                                                     //If >max value, output 0.//
+    } else { this->analogOut->write(this->amplitude/3.0f);}                          //If <max value, out the right expression.//
 
 }
 
-void SineApp::run()
+void SineApp::run()                                                                   //(Overriden) Method that is called repeatedly when the app starts.//
 {
-   this->analogOut->write(this->amplitude+1.0f/3.0f*0.5f*(1.0f+sin(this->frequence*6.28f*timer.read())));
+   this->analogOut->write(this->amplitude/3.0f*0.5f*(1.0f+sin(this->frequence*6.28f*timer.read())));  //Set the output to the sin expression.// 
    
-   if ( this->frequence > 50.0f ) {
-   this->analogOut->write(0);
-    } else { this->analogOut->write(this->amplitude/3.0f*0.5f*(1.0f+sin(this->frequence*6.28f*timer.read())));}
+   if ( this->frequence > 50.0f ) {                                                   //Define the max frequence value and check it.//
+   this->analogOut->write(0);                                                         //If >max value, output 0.//
+    } else { this->analogOut->write(this->amplitude/3.0f*0.5f*(1.0f+sin(this->frequence*6.28f*timer.read())));} //If <max value, out the right expression.//
    
 
 }
 
-void SineApp::stop()
+void SineApp::stop()                                                                   //(Overriden) Method that runs when the app stops.//
 {
-    App::stop();
-    this->analogOut->write(0.0f);
-    this->timer.stop();
+    App::stop();                                                                       //Call bass class's stop() method.//
+    this->analogOut->write(0.0f);                                                      //Set output to 0V.//
+    this->timer.stop();                                                                //Stop the time and reset it.//
     this->timer.reset();
 }
-void SineApp::setamplitude(float newamplitude)
+void SineApp::setamplitude(float newamplitude)                                        //(Overriden) Method that could set amplitude.//
 {
-    this->amplitude = newamplitude;
+    this->amplitude = newamplitude;                                                   //Set the new amplitude.//
 }
-void SineApp::setfrequence(float newfrequence)
+void SineApp::setfrequence(float newfrequence)                                        //(Overriden) Method that could set frequence.//
 {
-    this->frequence = newfrequence;
+    this->frequence = newfrequence;                                                   //Set the new frequence.//
 }
--- a/sine_app.h	Fri Dec 18 14:04:25 2015 +0000
+++ b/sine_app.h	Fri Dec 18 16:27:23 2015 +0000
@@ -3,22 +3,22 @@
 #include "app.h"
 #include "mbed.h"
 
-class SineApp : public App
+class SineApp : public App                                     //Class containing the Sine app.//
 {
     protected:
        AnalogOut* analogOut;
        Timer timer;
-       float amplitude;
-       float frequence;
+       float amplitude;                                       //Define the float amplitude value.//
+       float frequence;                                       //Define the float frequence value.//
        
     public:
-       SineApp(Serial* serialPort);
+       SineApp(Serial* serialPort);                           //Constructor.//
        
-       virtual void start();
-       virtual void run();
-       virtual void stop();
-       void setamplitude (float newamplitude);
-       void setfrequence (float newfrequence);
+       virtual void start();                                  //(Overriden) called when app starts.//
+       virtual void run();                                    //(Overriden) called repeatedly while running and do the sine expression.//
+       virtual void stop();                                   //(Overriden) called when app stops.//
+       void setamplitude (float newamplitude);                //(Overriden) called when app starts, set the new amplitude.//
+       void setfrequence (float newfrequence);                //(Overriden) called when app starts, set the new frequence.//
 };
 
 #endif
\ No newline at end of file
--- a/square_app.cpp	Fri Dec 18 14:04:25 2015 +0000
+++ b/square_app.cpp	Fri Dec 18 16:27:23 2015 +0000
@@ -1,47 +1,49 @@
 #include "square_app.h"
 
+//Constructor. Calls the bass class (App) constructor and creact an AnalogOut object.//
 SquareApp::SquareApp(Serial* serial) : App("Square wave", serial) {
+    //Set analogOut attribute to a new AnalogOut object.//
     this->analogOut = new AnalogOut (PA_4);
-    this->amplitude = 2.95f;
-    this->frequence = 50.0f;
+    this->amplitude = 3.0f;                                                                      //Set the amplitude value.//
+    this->frequence = 50.0f;                                                                      //Set the frequence value.//
 }
 
-void SquareApp::start()
+void SquareApp::start()                                                                           //(Overriden) Method that runs when the app starts.//
 {
-    App::start();
-    this->analogOut->write(this->amplitude/2.95f);
-    this->timer.start(); 
-    if ( this->amplitude > 2.95f ) {
-       this->analogOut->write(0);
-    } else { this->analogOut->write(this->amplitude/2.95f);}
+    App::start();                                                                                 //Call bass class's start() method.//
+    this->analogOut->write(this->amplitude/3.0f);                                                //Set the output to the amplitude.//
+    this->timer.start();                                                                          //Start timer.//
+    if ( this->amplitude > 3.0f ) {                                                              //Define the max amplitude value and check it.//
+       this->analogOut->write(0);                                                                 //If >max value, output 0.//
+    } else { this->analogOut->write(this->amplitude/3.0f);}                                      //If <max value, out the right expression.//
 
 }
 
-void SquareApp::run()
+void SquareApp::run()                                                                             //(Overriden) Method that is called repeatedly when the app starts.//
 {
-   float p;
-   p = (this->frequence*timer.read())-floor(this->frequence*timer.read());
-   if ( p < 0.5f ) {
-       this->analogOut->write(0);
-    } else { this->analogOut->write(this->amplitude/2.95f);} 
+   float p;                                                                                       //Define the float p.//
+   p = (this->frequence*timer.read())-floor(this->frequence*timer.read());                        //p expression.//
+   if ( p < 0.5f ) {                                                                              //Define the mini p value and check it.//
+       this->analogOut->write(0);                                                                 //If < mini value, output 0.//
+    } else { this->analogOut->write(this->amplitude/3.0f);}                                      //Set the output to the sin expression.//
     
-    if ( this->frequence > 50.0f ) {
-       this->analogOut->write(0);
+    if ( this->frequence > 50.0f ) {                                                              //Define the max frequence value and check it.//
+       this->analogOut->write(0);                                                                 //If >max value, output 0.//
     } 
 }
 
-void SquareApp::stop()
+void SquareApp::stop()                                                                            //(Overriden) Method that runs when the app stops.//
 {
-    App::stop();
-    this->analogOut->write(0.0f);
-    this->timer.stop();
+    App::stop();                                                                                  //Call bass class's stop() method.//
+    this->analogOut->write(0.0f);                                                                 //Set output to 0V.//
+    this->timer.stop();                                                                           //Stop the time and reset it.//
     this->timer.reset();
 }
-void SquareApp::setamplitude(float newamplitude)
+void SquareApp::setamplitude(float newamplitude)                                                  //(Overriden) Method that could set amplitude.//
 {
-    this->amplitude = newamplitude;
+    this->amplitude = newamplitude;                                                               //Set the new amplitude.//
 }
-void SquareApp::setfrequence(float newfrequence)
+void SquareApp::setfrequence(float newfrequence)                                                  //(Overriden) Method that could set frequence.//
 {
-    this->frequence = newfrequence;
+    this->frequence = newfrequence;                                                               //Set the new frequence.//
 }