| 74 | |
| 75 | |
| 76 | int pseudoPinsSetup(const int pinBase) |
| 77 | { |
| 78 | struct wiringPiNodeStruct *node; |
| 79 | void *ptr; |
| 80 | |
| 81 | node = wiringPiNewNode(pinBase, PSEUDO_PINS); |
| 82 | if (node == NULL) { |
| 83 | fprintf(stderr, "Error creating new wiringPi node"); |
| 84 | return false; |
| 85 | } |
| 86 | |
| 87 | node->fd = shm_open(SHARED_NAME, O_CREAT | O_RDWR, 0666); |
| 88 | if (node->fd < 0) { |
| 89 | perror("Error opening shared memory"); |
| 90 | return false; |
| 91 | } |
| 92 | |
| 93 | if (ftruncate(node->fd, PSEUDO_PINS * sizeof(int)) < 0) { |
| 94 | perror("Error resizing shared memory"); |
| 95 | return false; |
| 96 | } |
| 97 | |
| 98 | ptr = mmap(NULL, PSEUDO_PINS * sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED, node->fd, 0); |
| 99 | if (ptr == MAP_FAILED) { |
| 100 | perror("Error mapping shared memory"); |
| 101 | return false; |
| 102 | } |
| 103 | |
| 104 | node->data0 = (unsigned int)(uintptr_t)ptr; |
| 105 | |
| 106 | node->analogRead = myAnalogRead; |
| 107 | node->analogWrite = myAnalogWrite; |
| 108 | |
| 109 | return true; |
| 110 | } |
no test coverage detected