Last active
October 4, 2017 21:06
-
-
Save C47D/4288a51a402a9742fb088bef1c1fa5f4 to your computer and use it in GitHub Desktop.
setter y getter para las direcciones de los pipe del nrf24
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdint.h> | |
#include <string.h> | |
enum nrf24_addresses { | |
NRF24_PIPE_O = 0, | |
NRF24_PIPE_1 = 1, | |
NRF24_PIPE_2 = 2, | |
NRF24_PIPE_3 = 3, | |
NRF24_PIPE_4 = 4, | |
NRF24_PIPE_5 = 5, | |
}; | |
enum { | |
NRF24_ADDR_WIDTH = 5, | |
NRF24_PIPES = 6, | |
}; | |
// Direcciones por default del sensor | |
uint8_t ADDRESSES[NRF24_PIPES][NRF24_ADDR_WIDTH] = { | |
{0xCE, 0xCE, 0xCE, 0xCE, 0xCE}, | |
{0xC1, 0xC2, 0xC3, 0xC4, 0xC0}, | |
{0xC1, 0xC2, 0xC3, 0xC4, 0xC1}, | |
{0xC1, 0xC2, 0xC3, 0xC4, 0xC2}, | |
{0xC1, 0xC2, 0xC3, 0xC4, 0xC3}, | |
{0xC1, 0xC2, 0xC3, 0xC4, 0xC4} | |
}; | |
// en pipe2, 3, 4 y 5 solo se puede cambiar el byte menos significativo. | |
void setPipe5Address(const uint8_t addr_lsb) | |
{ | |
ADDRESSES[NRF24_PIPE_5][5] = addr_lsb; | |
} | |
void getPipe5Address(uint8_t *pipeAddr, size_t size) | |
{ | |
if ( NRF24_ADDR_WIDTH < size ) { | |
printf("size %d is an invalid size ", size); | |
return; | |
} | |
memcpy(pipeAddr, ADDRESSES[NRF24_PIPE_5], NRF24_ADDR_WIDTH); | |
} | |
int main() | |
{ | |
uint8_t pipe5[5] = {0}; | |
getPipe5Address(pipe5, 5); | |
for(uint8_t i = 0; i < 5; i++) { | |
printf("0x%02x ", pipe5[i]); | |
} | |
printf("\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment