Now manages 2 motors (or any number algorithmically)
This commit is contained in:
parent
ba07ab7bcd
commit
5ddb960348
|
@ -8,7 +8,7 @@
|
|||
|
||||
$FEATURE = basename(dirname(__DIR__));
|
||||
|
||||
$MOTOR_PIN = 19;
|
||||
$MOTOR_PIN = [19, 13];
|
||||
|
||||
$LOOP_FREQ = 100; // check frequency in ms
|
||||
$THRESHOLD = 4; // maximum number of reads to wait for motor to be active back
|
||||
|
@ -26,18 +26,20 @@
|
|||
/* (1) Motor pin */
|
||||
global $MOTOR_PIN;
|
||||
|
||||
/* [2] Try to read motor state
|
||||
/* [2] Try to read motor state (for each pin)
|
||||
=========================================================*/
|
||||
/* (1) Get its state */
|
||||
$STATE = syscall( SOURCE_DIR."/lib/gpio/in $MOTOR_PIN" );
|
||||
foreach($MOTOR_PIN as $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 */
|
||||
// slog('read: 0', 'motheure-simple:loop', 'motheure');
|
||||
/* (3) Return FALSE means every motor is inactive */
|
||||
return false;
|
||||
|
||||
}
|
||||
|
@ -53,10 +55,7 @@
|
|||
/* (1) Log history file descriptor */
|
||||
global $f_data;
|
||||
|
||||
/* (2) Motor pin */
|
||||
global $MOTOR_PIN;
|
||||
|
||||
/* (3) Loop data */
|
||||
/* (2) Loop data */
|
||||
global $start_ts;
|
||||
global $LOOP_FREQ;
|
||||
global $THRESHOLD;
|
||||
|
|
Loading…
Reference in New Issue