Dependents:   ShootingSystem

Committer:
inst
Date:
Wed Oct 14 03:52:41 2015 +0000
Revision:
1:2a43c09cc3be
Parent:
0:49a747f09bd2

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
inst 0:49a747f09bd2 1 #include "mbed.h"
inst 0:49a747f09bd2 2 #include "AmmoSupplier.h"
inst 0:49a747f09bd2 3 #include "I2CMotor.h"
inst 1:2a43c09cc3be 4 #include "ShootingSystem.h"
inst 0:49a747f09bd2 5
inst 1:2a43c09cc3be 6 AmmoSupplier::AmmoSupplier( char address ) : I2CDevice( address ){
inst 1:2a43c09cc3be 7 mSupplyCommand = false;
inst 1:2a43c09cc3be 8 mIsSupplying = false;
inst 1:2a43c09cc3be 9 mHasSupplied = false;
inst 0:49a747f09bd2 10 }
inst 0:49a747f09bd2 11
inst 1:2a43c09cc3be 12 int AmmoSupplier::write(){
inst 1:2a43c09cc3be 13 int val = 0;
inst 0:49a747f09bd2 14
inst 1:2a43c09cc3be 15 if ( mSupplyCommand ){
inst 1:2a43c09cc3be 16 char buf = 1;
inst 1:2a43c09cc3be 17 val = I2CDevice::write( &buf, 1 );
inst 1:2a43c09cc3be 18 mSupplyCommand = false;
inst 0:49a747f09bd2 19 }
inst 0:49a747f09bd2 20
inst 1:2a43c09cc3be 21 return val;
inst 1:2a43c09cc3be 22 }
inst 1:2a43c09cc3be 23
inst 1:2a43c09cc3be 24 int AmmoSupplier::read(){
inst 1:2a43c09cc3be 25 char buf;
inst 1:2a43c09cc3be 26 int val = I2CDevice::read( &buf, 1 );
inst 1:2a43c09cc3be 27
inst 1:2a43c09cc3be 28 mHasSupplied = ( mIsSupplying && !buf );
inst 1:2a43c09cc3be 29 mIsSupplying = buf;
inst 1:2a43c09cc3be 30
inst 1:2a43c09cc3be 31 //printf( "%d\n", buf );
inst 1:2a43c09cc3be 32
inst 1:2a43c09cc3be 33 /*
inst 1:2a43c09cc3be 34 if ( mHasSupplied ){
inst 1:2a43c09cc3be 35 wait( 1.0f );
inst 0:49a747f09bd2 36 }
inst 1:2a43c09cc3be 37 */
inst 1:2a43c09cc3be 38
inst 1:2a43c09cc3be 39 return val;
inst 0:49a747f09bd2 40 }