Advertisement
AndiTails

C program to control ENER002 sockets.

Jan 16th, 2016
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.29 KB | None | 0 0
  1. #include "app_main.h"
  2. #include "dev_HRF.h"
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <time.h>
  6. #include <bcm2835.h>
  7. #include <stdbool.h>
  8. uint8_t relayState;
  9. // receive in variable length packet mode, display and send to R1 and Legacy socket.
  10. int main(int argc, char **argv){
  11.         if (!bcm2835_init())
  12.                 return 1;
  13.  
  14.         time_t currentTime, legacyTime, monitorControlTime;
  15.  
  16.         // LED INIT
  17.         bcm2835_gpio_fsel(LEDG, BCM2835_GPIO_FSEL_OUTP);                        // LED green
  18.         bcm2835_gpio_fsel(LEDR, BCM2835_GPIO_FSEL_OUTP);                        // LED red
  19.         bcm2835_gpio_write(LEDG, LOW);
  20.         bcm2835_gpio_write(LEDR, LOW);
  21.         // SPI INIT
  22.         bcm2835_spi_begin();
  23.         bcm2835_spi_setClockDivider(SPI_CLOCK_DIVIDER_26);                      // 250MHz / 26 = 9.6MHz
  24.         bcm2835_spi_setDataMode(BCM2835_SPI_MODE0);                             // CPOL = 0, CPHA = 0
  25.         bcm2835_spi_chipSelect(BCM2835_SPI_CS1);                                        // chip select 1
  26.  
  27.         HRF_config_FSK();
  28.         HRF_wait_for(ADDR_IRQFLAGS1, MASK_MODEREADY, true);                     // wait until ready after mode switching
  29.         HRF_clr_fifo();
  30.  
  31.         HRF_send_OOK_msg(1);
  32.  
  33.         bcm2835_spi_end();
  34.         return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement