/*! \file PointController.H c++/PointController.H \brief C++ Switch Point Controller Class Interface \author Zhengrong.Zang@gmail.com \date 2013.10.01 Defines interface to control Train Switch Point */ // The contents of this file are subject to the Mozilla Public License // Version 1.0 (the "License"); you may not use this file except in // compliance with the License. You may obtain a copy of the License // at http://www.mozilla.org/MPL/ // // Software distributed under the License is distributed on an "AS IS" // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See // the License for the specific language governing rights and // limitations under the License. #ifndef _PointController_H_ #define _PointController_H_ #include class PointController { public: static const int SWITCH_DURATION = 50; enum PointDirection {Straight, Curve}; private: Motor *motor; PointDirection mdir; public: PointController(Motor::Port port) { motor = new Motor(port); toStraight(); } ~PointController() { toStraight(); delete motor; } const PointDirection dir() const { return mdir; } const void toStraight() { mdir = PointController::Straight; motor->forward(Motor::max); delay(PointController::SWITCH_DURATION); motor->brake(); } const void toCurve() { mdir = PointController::Curve; motor->backward(Motor::max); delay(PointController::SWITCH_DURATION); motor->brake(); } const void toggle() { if (mdir == PointController::Straight) { toCurve(); } else { toStraight(); } } }; #endif // _PointController_H_