Now manages 2 motors (or any number algorithmically)

This commit is contained in:
xdrm-brackets 2017-10-14 15:53:41 +02:00
parent ba07ab7bcd
commit 5ddb960348
1 changed files with 12 additions and 13 deletions

View File

@ -8,7 +8,7 @@
$FEATURE = basename(dirname(__DIR__)); $FEATURE = basename(dirname(__DIR__));
$MOTOR_PIN = 19; $MOTOR_PIN = [19, 13];
$LOOP_FREQ = 100; // check frequency in ms $LOOP_FREQ = 100; // check frequency in ms
$THRESHOLD = 4; // maximum number of reads to wait for motor to be active back $THRESHOLD = 4; // maximum number of reads to wait for motor to be active back
@ -26,18 +26,20 @@
/* (1) Motor pin */ /* (1) Motor pin */
global $MOTOR_PIN; global $MOTOR_PIN;
/* [2] Try to read motor state /* [2] Try to read motor state (for each pin)
=========================================================*/ =========================================================*/
/* (1) Get its state */ foreach($MOTOR_PIN as $PIN){
$STATE = syscall( SOURCE_DIR."/lib/gpio/in $MOTOR_PIN" );
/* (1) Get its state */
$STATE = syscall( SOURCE_DIR."/lib/gpio/in $MOTOR_PIN" );
/* (2) If at least one active return TRUE */
if( $STATE === true )
return true;
/* (3) If active, pass */
if( $STATE === true ){
return true;
} }
/* (4) Return FALSE means motor inactive */ /* (3) Return FALSE means every motor is inactive */
// slog('read: 0', 'motheure-simple:loop', 'motheure');
return false; return false;
} }
@ -53,10 +55,7 @@
/* (1) Log history file descriptor */ /* (1) Log history file descriptor */
global $f_data; global $f_data;
/* (2) Motor pin */ /* (2) Loop data */
global $MOTOR_PIN;
/* (3) Loop data */
global $start_ts; global $start_ts;
global $LOOP_FREQ; global $LOOP_FREQ;
global $THRESHOLD; global $THRESHOLD;