mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +03:00
HCSR04: Fixing static analysis issues
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
This commit is contained in:
parent
b90c5a7710
commit
60379fca37
@ -46,29 +46,35 @@ hcsr04_context hcsr04_init(int triggerPin, int echoPin) {
|
|||||||
dev->trigPin = mraa_gpio_init(triggerPin);
|
dev->trigPin = mraa_gpio_init(triggerPin);
|
||||||
if(!dev->trigPin) {
|
if(!dev->trigPin) {
|
||||||
printf("Unable to initialize the trigger pin\n");
|
printf("Unable to initialize the trigger pin\n");
|
||||||
|
free(dev);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
dev->echoPin = mraa_gpio_init(echoPin);
|
dev->echoPin = mraa_gpio_init(echoPin);
|
||||||
if(!dev->echoPin) {
|
if(!dev->echoPin) {
|
||||||
printf("Unable to initialize the echo pin\n");
|
printf("Unable to initialize the echo pin\n");
|
||||||
|
free(dev);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setting direction for the GPIO pins
|
// Setting direction for the GPIO pins
|
||||||
if(mraa_gpio_dir(dev->trigPin, MRAA_GPIO_OUT) != MRAA_SUCCESS) {
|
if(mraa_gpio_dir(dev->trigPin, MRAA_GPIO_OUT) != MRAA_SUCCESS) {
|
||||||
printf("Unable to set the direction of the trigger Pin\n");
|
printf("Unable to set the direction of the trigger Pin\n");
|
||||||
|
free(dev);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mraa_gpio_dir(dev->echoPin, MRAA_GPIO_IN) != MRAA_SUCCESS) {
|
if(mraa_gpio_dir(dev->echoPin, MRAA_GPIO_IN) != MRAA_SUCCESS) {
|
||||||
printf("Unable to set the direction of the echo Pin\n");
|
printf("Unable to set the direction of the echo Pin\n");
|
||||||
|
free(dev);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setting the trigger pin to logic level 0
|
// Setting the trigger pin to logic level 0
|
||||||
if(mraa_gpio_write(dev->trigPin, 0) != MRAA_SUCCESS)
|
if(mraa_gpio_write(dev->trigPin, 0) != MRAA_SUCCESS) {
|
||||||
|
free(dev);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// initialize the interrupt counter
|
// initialize the interrupt counter
|
||||||
dev->interruptCounter = 0;
|
dev->interruptCounter = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user