Horia Carbune / Mbed 2 deprecated nRF51822_BLE_Control_Refactor

Dependencies:   BLE_API mbed nRF51822

Fork of nRF51822_SimpleChat by Cristi Stoican

Files at this revision

API Documentation at this revision

Comitter:
carbune92
Date:
Tue May 09 06:13:54 2017 +0000
Parent:
5:fca87573ed92
Child:
7:806b08205b25
Commit message:
Added PWM and analog input functions in ProcessInterface

Changed in this revision

ProcessInterface.cpp Show annotated file Show diff for this revision Revisions of this file
ProcessInterface.hpp Show annotated file Show diff for this revision Revisions of this file
--- a/ProcessInterface.cpp	Mon May 08 21:57:59 2017 +0000
+++ b/ProcessInterface.cpp	Tue May 09 06:13:54 2017 +0000
@@ -1,7 +1,15 @@
 #include "ProcessInterface.hpp"
 
-ProcessInterface::ProcessInterface() : Output(0), cmd(0) {
+ProcessInterface::ProcessInterface() : Output(0), cmd(0), processRead(P0_4), cmdPin(P0_0) {
 	this->Ctrl = 0;
+	this->Btd = 0;
+	cmdPin.period(MIN_PWM_PERIOD);
+}
+
+ProcessInterface::ProcessInterface(PinName _analogPin, PinName _pwmPin) : Output(0), cmd(0), processRead(_analogPin), cmdPin(_pwmPin) {
+	this->Ctrl = 0;
+	this->Btd = 0;
+	cmdPin.period(MIN_PWM_PERIOD);
 }
 
 void ProcessInterface::attachController(Controller *_Ctrl) {
@@ -13,7 +21,7 @@
 }
 
 void ProcessInterface::getProcOutput() {
-	Output = input.read();
+	Output = processRead.read();
 }
 
 void ProcessInterface::exportOutput() {
@@ -29,12 +37,12 @@
 	cmd =_cmd;
 }
 
-void ProcessInterface::applyCmd() {}
+void ProcessInterface::applyCmd() {
+	cmdPin.write(cmd);	
+}
 
 
 ProcessInterface::~ProcessInterface() {
 	delete Ctrl;
 	delete Btd;
 }
-
-
--- a/ProcessInterface.hpp	Mon May 08 21:57:59 2017 +0000
+++ b/ProcessInterface.hpp	Tue May 09 06:13:54 2017 +0000
@@ -5,12 +5,17 @@
 #include "Controller.hpp"
 #include "BTDevice.hpp"
 
-static AnalogIn input(P0_4);
+#define MIN_PWM_PERIOD 0.00001f
+
+//static AnalogIn processRead(P0_4);
+
+// TODO fct de scalat intre 0 si 1 pentru comenzi date de controller care nu se incadreaza
 
 class ProcessInterface{
 	
 	public:
 		ProcessInterface();
+		ProcessInterface(PinName, PinName);
 		void getProcOutput();
 		void attachController(Controller *);
 		void attachBTDevice(BTDevice *);
@@ -18,7 +23,6 @@
 		void updateCmd();
 		void updateCmd(float);
 		void applyCmd();
-		
 		~ProcessInterface();
 		
 	private:
@@ -26,7 +30,8 @@
 		BTDevice *Btd;
 		float Output;
 		float cmd;
-	
+		AnalogIn processRead;
+		PwmOut cmdPin;
 };
 
 #endif