From 5ddb960348875d4e177101530136a3d2ca9b49b0 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sat, 14 Oct 2017 15:53:41 +0200 Subject: [PATCH] Now manages 2 motors (or any number algorithmically) --- feature/motheure-simple/source/loop.php | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/feature/motheure-simple/source/loop.php b/feature/motheure-simple/source/loop.php index acd6983..bfbd749 100644 --- a/feature/motheure-simple/source/loop.php +++ b/feature/motheure-simple/source/loop.php @@ -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;