Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of CoilGun by
Diff: coilgun.h
- Revision:
- 6:4c75db8a43db
- Parent:
- 4:0e2bdd3d52bc
- Child:
- 8:eee78d8bfdb9
--- a/coilgun.h Wed Sep 18 10:50:22 2013 +0000
+++ b/coilgun.h Wed Sep 18 11:20:31 2013 +0000
@@ -1,49 +1,37 @@
#ifndef COILGUN_H
#define COILGUN_H
-
+
#include "mbed.h"
-
-/** Interface to the CoilGun*/
-class CoilGun {
+
+/** Class for controlling coilgun */
+class Coilgun {
public:
- /** Create an instance of the CoilGun connected to specfied pins.
- *
- * @param chargePinName The charge pin.
- * @param kickPinName The kick pin.
- * @param donePinName The done pin.
- */
- CoilGun(PinName chargePinName, PinName kickPinName, PinName donePinName);
-
- /** Kick with coilgun.
- *
- * @param length The length of the kick in uS
- */
+ Coilgun(PinName kickPinName ,PinName chargePinName, PinName donePinName);
void kick(unsigned int length);
-
- /** Discharge coilgun */
- void discharge(void);
-
- /** turn charging on or off
- *
- * @param chargeState Set true to charge. False, to not charge.
- */
- void setCharge(bool chargeState);
-
-private:
- DigitalOut chargePin;
- DigitalOut kickPin;
- InterruptIn donePin;
- void doneCallback(void);
-
- bool kicking; //True while kick is in progress
- Timeout kickTimeout; // This will end kicking
void kickEnd(void);
- bool discharging; //True as long discharging is in progress
+ void charge(void);
+ void chargeEnd(void);
+
+ void discharge(void);
+ void dischargeEnd(void);
+
+
+private:
+ enum State {idle, kicking, charging, discharging};
+ State state;
+
+ DigitalOut kickPin;
+ DigitalOut chargePin;
+ InterruptIn donePin;
+
+ Timeout kickTimeout; // This will end kicking
Timeout dischargeTimeout; // This will end discharging
Ticker discharger; // Calls short kicks during discharge
- void dischargeKick(void); //Short kick for discharging
- void dischargeEnd(void); //Method that ends discharging (dischargeTimeout calls this)
+
+ void changeState(State new_state);
+ void dischargeKick(void);
+ void kick(unsigned int length, bool change_state);
};
-
+
#endif
\ No newline at end of file
