Browse Source

Added delayMs and delayUs macros for easier code comprehension.

pull/158/head
Jim Parziale 2 years ago
parent
commit
af313ea5f7
10 changed files with 23 additions and 19 deletions
  1. +2
    -2
      examples/buttons.c
  2. +1
    -1
      examples/buttons2.c
  3. +1
    -1
      examples/clock.c
  4. +2
    -2
      examples/isr-osc.c
  5. +3
    -3
      examples/isr1.c
  6. +2
    -2
      examples/q2w/button.c
  7. +3
    -3
      examples/wfi.c
  8. +2
    -2
      gpio/gpio.c
  9. +1
    -1
      wiringPi/wiringPi.c
  10. +6
    -2
      wiringPi/wiringPi.h

+ 2
- 2
examples/buttons.c View File

@@ -54,7 +54,7 @@ void scanButton (int button)
// Wait for release
while (digitalRead (button) == LOW)
{
delay (1);
delayMs(1);
}
int dur = micros() - start;

@@ -95,7 +95,7 @@ int main (void)
{
scanButton (buttons[i]);
}
delay (1);
delayMs(1);
}

return EXIT_SUCCESS;


+ 1
- 1
examples/buttons2.c View File

@@ -89,7 +89,7 @@ int main (void)
}
}

delay (1);
delayMs(1);

// If pushed, look for release
if (buttonVal[i] == 1)


+ 1
- 1
examples/clock.c View File

@@ -193,7 +193,7 @@ int main (int argc, char *argv [])

now = time (NULL) ;
while (time (NULL) == now)
delay (10) ;
delayMs(10) ;
}



+ 2
- 2
examples/isr-osc.c View File

@@ -125,13 +125,13 @@ int main (void)

while (!terminate_process && (myCounter == globalCounter))
{
delay (250);
delayMs(250);
}

printf ("Done. counter: %2d: %2d\n", globalCounter, globalCounter - myCounter);

digitalWrite (OUT_PIN, 1);
delay (500);
delayMs(500);
digitalWrite (OUT_PIN, 0);

myCounter = globalCounter;


+ 3
- 3
examples/isr1.c View File

@@ -42,8 +42,8 @@
//**********************************************************************************************************************

// What GPIO input are we using?
// This is a wiringPi pin number
#define BUTTON_PIN 3
// This is a wiringPi pin number
#define BUTTON_PIN 3

// LED Pin - wiringPi pin 0 is BCM_GPIO 17.
#define LED 2
@@ -117,7 +117,7 @@ int main(void) {
fflush(stdout);

pthread_mutex_lock( &smb_mutex );
delay(50);
delayMs(50);
isr_state = 0;

button_state = digitalRead(BUTTON_PIN);


+ 2
- 2
examples/q2w/button.c View File

@@ -52,11 +52,11 @@ int main (void)
digitalWrite (LED1, LOW) ;
digitalWrite (LED2, HIGH) ;
while (digitalRead (BUTTON) == HIGH)
delay (1) ;
delayMs(1) ;
digitalWrite (LED1, HIGH) ;
digitalWrite (LED2, LOW) ;
}
delay (1) ;
delayMs(1) ;
}

return 0 ;


+ 3
- 3
examples/wfi.c View File

@@ -96,7 +96,7 @@ PI_THREAD (waitForIt)
// Wait for key to be released

while (digitalRead (BUTTON_PIN) == LOW)
delay (1) ;
delayMs (1) ;

debounceTime = millis () + DEBOUNCE_TIME ;
}
@@ -151,9 +151,9 @@ int main (void)
while (myCounter == lastCounter)
{
piLock (COUNT_KEY) ;
myCounter = globalCounter ;
myCounter = globalCounter ;
piUnlock (COUNT_KEY) ;
delay (500) ;
delayMs(500) ;
}

printf (" Done. myCounter: %5d\n", myCounter) ;


+ 2
- 2
gpio/gpio.c View File

@@ -532,7 +532,7 @@ void doWfi (int argc, char *argv[])
}

for (;;)
delay (9999);
delayMs(9999);
}


@@ -1020,7 +1020,7 @@ void doBlink (int argc, char *argv[])
for (;;)
{
digitalWrite (pin, !digitalRead (pin));
delay (500);
delayMs(500);
}

}


+ 1
- 1
wiringPi/wiringPi.c View File

@@ -1950,7 +1950,7 @@ int wiringPiISR (int pin, int mode, void (*function)(void))
pthread_create (&threadId, NULL, interruptHandler, NULL);
while (pinPass != -1)
{
delay (1);
delayMs(1);
}
pthread_mutex_unlock (&pinMutex);



+ 6
- 2
wiringPi/wiringPi.h View File

@@ -281,9 +281,13 @@ extern int piHiPri (const int pri);

extern void delay (unsigned int milliseconds);
extern void delayMicroseconds (unsigned int microseconds);
// Please use these for code that's easier to comprehend:
#define delayMs(ms) delay(ms)
#define delayUs(us) delayMicroseconds(us)

// These report the amount of time passed since wiringPiSetup* was called.
extern unsigned int millis (void);
extern unsigned int micros (void);
extern unsigned int millis(void);
extern unsigned int micros(void);

#ifdef __cplusplus
}


Loading…
Cancel
Save