Dependents:   ShootingSystem

AmmoPusher.cpp

Committer:
inst
Date:
2015-08-21
Revision:
1:42d2772575c5
Parent:
0:fac139a6b77c
Child:
2:5ec2a3097d4c

File content as of revision 1:42d2772575c5:

#include "AmmoPusher.h"
#include "mbed.h"
#include "I2CMotor.h"

const float AmmoPusher::mDuty = 0.8f;
const PinName AmmoPusher::mDrawingLimitSwitchPinName = D7;
const PinName AmmoPusher::mPushingLimitSwitchPinName = D6;

AmmoPusher::AmmoPusher( I2CMotor* drawerMotor ){
    mDrawerMotor = drawerMotor;
    mDrawerMotor->setDuty( mDuty );
    mDrawingLimitSwitch = new DigitalIn( mDrawingLimitSwitchPinName );
    mPushingLimitSwitch = new DigitalIn( mPushingLimitSwitchPinName );
}

void AmmoPusher::update(){
    // スイッチが押されたらブレーキ
    if ( mDrawingLimitSwitch->read() || mPushingLimitSwitch->read() ){
        mDrawerMotor->setActionType( I2CMotor::BRAKE );
    }
}

void AmmoPusher::draw(){
    // スイッチが押されたらブレーキ
    if ( mDrawingLimitSwitch->read() || mPushingLimitSwitch->read() ){
        mDrawerMotor->setActionType( I2CMotor::BRAKE );
    } else {
        mDrawerMotor->setActionType( I2CMotor::REVERSE );
    }
}

void AmmoPusher::push(){
    // スイッチが押されたらブレーキ
    if ( mDrawingLimitSwitch->read() || mPushingLimitSwitch->read() ){
        mDrawerMotor->setActionType( I2CMotor::BRAKE );
    } else {
        mDrawerMotor->setActionType( I2CMotor::FORWARD );
    }
}

bool AmmoPusher::hasPusherFinishedPushing(){
    if ( mPushingLimitSwitch->read() ){
        mDrawerMotor->setActionType( I2CMotor::BRAKE );
        return true;
    }
    return false;
}

bool AmmoPusher::hasPusherFinishedDrawing(){
    if ( mDrawingLimitSwitch->read() ){
        mDrawerMotor->setActionType( I2CMotor::BRAKE );
        return true;
    }
    return false;
}