Merge pull request #229 from WiringPi/warnings

Warnings
This commit is contained in:
Manfred Wallner
2024-05-03 21:27:24 +02:00
committed by GitHub
6 changed files with 118 additions and 71 deletions

View File

@@ -43,15 +43,20 @@
*********************************************************************************
*/
void waitForConversion (int fd, unsigned char *buffer, int n)
void waitForConversion(int fd, unsigned char *buffer, int n)
{
for (;;)
{
read (fd, buffer, n) ;
if ((buffer [n-1] & 0x80) == 0)
break ;
delay (1) ;
}
for (;;) {
ssize_t bytes_read = read(fd, buffer, n);
if (bytes_read != n) {
perror("Error reading from file descriptor");
return;
}
if ((buffer[n - 1] & 0x80) == 0)
break;
delay(1);
}
}
/*

View File

@@ -24,6 +24,7 @@
*/
#include <unistd.h>
#include <stdio.h>
#include "wiringPi.h"
#include "wiringPiI2C.h"
@@ -41,7 +42,10 @@ static void myAnalogWrite (struct wiringPiNodeStruct *node, UNU int pin, int val
unsigned char b [2] ;
b [0] = 0x40 ;
b [1] = value & 0xFF ;
write (node->fd, b, 2) ;
ssize_t bytes_written = write(node->fd, b, 2);
if (bytes_written != 2) {
perror("Error writing to file descriptor");
}
}

View File

@@ -35,9 +35,12 @@
#define SHARED_NAME "wiringPiPseudoPins"
#define PSEUDO_PINS 64
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <stdint.h>
#include <sys/stat.h>
#include <fcntl.h>
@@ -45,21 +48,20 @@
#include "pseudoPins.h"
static int myAnalogRead (struct wiringPiNodeStruct *node, int pin)
static int myAnalogRead(struct wiringPiNodeStruct *node, int pin)
{
int *ptr = (int *)node->data0 ;
int myPin = pin - node->pinBase ;
int *ptr = (int *)(intptr_t)node->data0; // Cast to intptr_t to handle pointer-to-integer conversion
int myPin = pin - node->pinBase;
return *(ptr + myPin) ;
return *(ptr + myPin);
}
static void myAnalogWrite (struct wiringPiNodeStruct *node, int pin, int value)
static void myAnalogWrite(struct wiringPiNodeStruct *node, int pin, int value)
{
int *ptr = (int *)node->data0 ;
int myPin = pin - node->pinBase ;
int *ptr = (int *)(intptr_t)node->data0;
int myPin = pin - node->pinBase;
*(ptr + myPin) = value ;
*(ptr + myPin) = value;
}
@@ -69,27 +71,39 @@ static void myAnalogWrite (struct wiringPiNodeStruct *node, int pin, int value)
*********************************************************************************
*/
int pseudoPinsSetup (const int pinBase)
int pseudoPinsSetup(const int pinBase)
{
struct wiringPiNodeStruct *node ;
void *ptr ;
struct wiringPiNodeStruct *node;
void *ptr;
node = wiringPiNewNode (pinBase, PSEUDO_PINS) ;
node = wiringPiNewNode(pinBase, PSEUDO_PINS);
if (node == NULL) {
fprintf(stderr, "Error creating new wiringPi node");
return FALSE;
}
node->fd = shm_open (SHARED_NAME, O_CREAT | O_RDWR, 0666) ;
node->fd = shm_open(SHARED_NAME, O_CREAT | O_RDWR, 0666);
if (node->fd < 0) {
perror("Error opening shared memory");
return FALSE;
}
if (node->fd < 0)
return FALSE ;
if (ftruncate(node->fd, PSEUDO_PINS * sizeof(int)) < 0) {
perror("Error resizing shared memory");
return FALSE;
}
if (ftruncate (node->fd, PSEUDO_PINS * sizeof (int)) < 0)
return FALSE ;
ptr = mmap(NULL, PSEUDO_PINS * sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED, node->fd, 0);
if (ptr == MAP_FAILED) {
perror("Error mapping shared memory");
return FALSE;
}
ptr = mmap (NULL, PSEUDO_PINS * sizeof (int), PROT_READ | PROT_WRITE, MAP_SHARED, node->fd, 0) ;
node->data0 = (unsigned int)(uintptr_t)ptr;
node->data0 = (unsigned int)ptr ;
node->analogRead = myAnalogRead;
node->analogWrite = myAnalogWrite;
node->analogRead = myAnalogRead ;
node->analogWrite = myAnalogWrite ;
return TRUE ;
return TRUE;
}

View File

@@ -536,31 +536,6 @@ const int _0v=-1;
const int _3v=-1;
static int physToSysGPIOPi5 [41] =
{
-1, // 0
_3v, _5v, // 1, 2
401, _5v,
402, _0v,
403, 413,
_0v, 414,
416, 417,
426, _0v,
421, 422,
_3v, 423,
409, _0v,
408, 424,
410, 407,
_0v, 406,
399, 400,
404, _0v,
405, 411,
412, _0v,
418, 415,
425, 419,
_0v, 420, //39, 40
} ;
int GPIOToSysFS(const int pin) {
int sysfspin = pin;
if (RaspberryPiModel<0) { //need to detect pi model

View File

@@ -153,9 +153,12 @@ void serialClose (const int fd)
*********************************************************************************
*/
void serialPutchar (const int fd, const unsigned char c)
void serialPutchar(const int fd, const unsigned char c)
{
write (fd, &c, 1) ;
ssize_t bytes_written = write(fd, &c, 1);
if (bytes_written != 1) {
perror("Error writing to file descriptor");
}
}
@@ -165,9 +168,13 @@ void serialPutchar (const int fd, const unsigned char c)
*********************************************************************************
*/
void serialPuts (const int fd, const char *s)
void serialPuts(const int fd, const char *s)
{
write (fd, s, strlen (s)) ;
size_t len = strlen(s);
ssize_t bytes_written = write(fd, s, len);
if (bytes_written != (ssize_t)len) {
perror("Error writing to file descriptor");
}
}
/*