Ver código fonte

Added delayMs and delayUs macros for easier code comprehension.

pull/158/head
Jim Parziale 2 anos atrás
pai
commit
af313ea5f7
10 arquivos alterados com 23 adições e 19 exclusões
  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 Ver arquivo

@@ -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 Ver arquivo

@@ -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 Ver arquivo

@@ -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 Ver arquivo

@@ -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 Ver arquivo

@@ -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 Ver arquivo

@@ -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 Ver arquivo

@@ -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 Ver arquivo

@@ -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 Ver arquivo

@@ -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 Ver arquivo

@@ -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
}


Carregando…
Cancelar
Salvar