Exemplo n.º 1
0
int main()
{
  if (!bcm2835_init()) // initialize the library
    return 1;

  bcm2835_gpio_fsel (PIN, BCM2835_GPIO_FSEL_OUTP); // Set the pin to be an output

  while (1)
    {
      bcm2835_gpio_write(PIN, HIGH); // Turn it on
      bcm2835_delay(500); // wait a bit
      bcm2835_gpio_write(PIN, LOW); // turn it off
      bcm2835_delay(500); // wait a bit
    }
  bcm2835_close(); // close the library

  return 0;
}
Exemplo n.º 2
0
int main(){
time_t mytime;

 printf("Start at "); mytime = time(NULL); printf(ctime(&mytime), "\n\n"); // Чисто отладочная запись в консоль, когда была запущена программа


 bcm2835_close();		// Это надо на всякий случай ибо процесс прекращается по ctrl+c и до этой функции дело не доходит
 if (!bcm2835_init())   // Инициализация GPIO и выход с кодом "1" при неудаче
  return 1;

 bcm2835_gpio_set_pud(PIR_SIGNAL, BCM2835_GPIO_PUD_DOWN);	// Подтяжка ножки к нулю
 bcm2835_gpio_fsel(PIR_SIGNAL, BCM2835_GPIO_FSEL_INPT); 	// Установка ножки для PIR на прием

//printf("%u\n", bcm2835_gpio_lev(PIR_SIGNAL)); // Вывод значения ножки

/////////Начало цикла слежения/////////

while (1) {		// Бесконечный цикл... Надо почитать про прерывания...

 while(!bcm2835_gpio_lev(PIR_SIGNAL)) 
 	{/* Ждем первого срабатывания */}	
 	
 time_to_file_first(); // см. выше
 printf("PIR activated at "); mytime = time(NULL); printf(ctime(&mytime), "\n\n");  // То было в файл, а это в консоль
 
 
// Пауза в мс. Аналог чувствительности датчика. Нужна чтобы отсечь ложные срабатывания

 bcm2835_delay(2000);
 

// Проверяем сигнал после паузы (PIR либо потухнет, либо останется активен)
// Если сигнал остался, то в консоль выводим время и ждем пока на ножке не появится ноль

 if(bcm2835_gpio_lev(PIR_SIGNAL))
	{
	 printf("Movement detected at ");
	 mytime = time(NULL); printf(ctime(&mytime), "\n"); //Вывод даты и времени
	 time_to_file_on();		// А заодно и в файл
	 while (bcm2835_gpio_lev(PIR_SIGNAL))
	 	{/* ждем пока сигнал не прекратится */}
	 printf("Movement stopped at ");
	 mytime = time(NULL); printf(ctime(&mytime), "\n"); printf("\n\n"); //Вывод даты и времени
	 time_to_file_off();	// И опять в файл
	 }
 
			
}


// До сюда обычно дело не доходит. Но пусть пока останется.

 printf("End\n");
 return (bcm2835_close());
  
}
Exemplo n.º 3
0
/*
*	Function: out_test
* Description: be used to test output related functions
*/
void out_test(void)
{
	int i;

	printf("--------------->Start Test Pin Output<---------------\n");
  	for(i=0; i < ARRAYLEN; i++)  //led off default
  	{
  		bcm2835_gpio_fsel(bplusGpio[i], BCM2835_GPIO_FSEL_OUTP); //output
		bcm2835_gpio_write(bplusGpio[i], LOW);
  	}	

	for(i=0; i< ARRAYLEN; i++)
	{
		bcm2835_gpio_write(bplusGpio[i], HIGH); //led on
		bcm2835_delay(1000);
		bcm2835_gpio_write(bplusGpio[i], LOW); //led off
		bcm2835_delay(1000);
	}
	printf("--------------->Test Over Of Pin Output<---------------\n");
}
Exemplo n.º 4
0
int main()
{
    //int i = bcm2835_init();
    if(!bcm2835_init())
    {
        printf("Error!\n");
        return 0;
    }
    bcm2835_gpio_fsel(PIN,BCM2835_GPIO_FSEL_OUTP);
    bcm2835_gpio_write(PIN,LOW);
    while(1)
    {
        bcm2835_gpio_write(PIN,HIGH);
        bcm2835_delay(1000);
        bcm2835_gpio_write(PIN,LOW);
        bcm2835_delay(1000);

    }
    return 0;
}
Exemplo n.º 5
0
int main(int argc, char *argv[]) 
{
	bcm2835_init();
	 
	if(comparse(argc, argv) == EXIT_FAILURE) return 0;
	 
	// setting PWM_PIN as pwm from channel 0 in markspace mode with range = RANGE
	bcm2835_gpio_fsel(PWM_PIN, BCM2835_GPIO_FSEL_ALT5);  //ALT5 is pwm mode
	bcm2835_pwm_set_clock(BCM2835_PWM_CLOCK_DIVIDER_16); // pwm freq = 19.2 / 16 MHz
	bcm2835_pwm_set_mode(PWM_CHANNEL, 1, 1);		     // markspace mode
	bcm2835_pwm_set_range(PWM_CHANNEL, RANGE);
	
	
	bcm2835_gpio_fsel(OE_SHIFTER, BCM2835_GPIO_FSEL_OUTP);
	bcm2835_gpio_set_pud(OE_SHIFTER, BCM2835_GPIO_PUD_DOWN); //pull-down for output enable of logic shifters

	bcm2835_gpio_fsel(MOTOR_D3, BCM2835_GPIO_FSEL_OUTP);
	bcm2835_gpio_set_pud(MOTOR_D3, BCM2835_GPIO_PUD_DOWN); //pull-down for motor enable
	
	bcm2835_gpio_fsel(PA0, BCM2835_GPIO_FSEL_OUTP);
	bcm2835_gpio_set_pud(PA0, BCM2835_GPIO_PUD_UP);
	bcm2835_gpio_write(PA0, HIGH);
	
	bcm2835_gpio_write(OE_SHIFTER, HIGH);
	bcm2835_gpio_write(MOTOR_D3, LOW);
	
	// creating and running threads
	pthread_t th1, th2, th3, th4, th5, th6, th7;
	pthread_create(&th1, NULL, (void*)encoder_time_thread, NULL);
	pthread_create(&th2, NULL, (void*)magnet_time_thread, NULL);
	pthread_create(&th3, NULL, (void*)encoder_thread, NULL);
	pthread_create(&th4, NULL, (void*)magnet_thread, NULL);
	pthread_create(&th5, NULL, (void*)energy_time_thread, NULL);
	pthread_create(&th6, NULL, (void*)calculate_energy, NULL);
	pthread_create(&th7, NULL, (void*)calculate_I_ref, NULL);
	
	bcm2835_delay(100); // delay to make sure that all threads are initialised and iC-MU is conofigured
	printf("\nPress enter to start the motor.");
	getchar(); 
	bcm2835_gpio_write(MOTOR_D3, HIGH);
	
	start = 1;
	printf("Started.\n");

	printf("\nPress enter to stop the motor.\n");
	getchar();
	bcm2835_gpio_write(MOTOR_D3, LOW);
	
	bcm2835_spi_end();
	bcm2835_close();
	
	
	return 0;
}
Exemplo n.º 6
0
int main(int argc, char **argv) {
    register_signalhandlers();

    ControlBlock controlBlock = ControlBlock();
    while (doRun) {
        controlBlock.update();
        bcm2835_delay(50);
    }

    return 0;
}
Exemplo n.º 7
0
int main(int argc, char **argv) {
    if (!bcm2835_init()) {
        printf("cannot init\n");
	return 1;
    }

    bcm2835_gpio_fsel(BUZ_PIN, BCM2835_GPIO_FSEL_OUTP);

    for (int i = 0; i < 10; i++) {
	printf("buzzer pin high\n");
	bcm2835_gpio_write(BUZ_PIN, HIGH);
	bcm2835_delay(1000);

	printf("buzzer pin low\n");
        bcm2835_gpio_write(BUZ_PIN, LOW);
	bcm2835_delay(1000);
    }

    bcm2835_close();
    return 0;
}
Exemplo n.º 8
0
void LCD_test(void)
{
	u16  temp,num;
	u8 n,i;

	en_lcd();	

	post_cmd(0x210,0x00);
	post_cmd(0x212,0x0000);
	post_cmd(0x211,0xEF);
	post_cmd(0x213,0x013F);
	
	post_cmd(0x200,0x0000);
	post_cmd(0x201,0x0000);

	en_lcd_index();
	post_data(0x202);
	en_lcd_data();
	for(n=0;n<8;n++)
	{
	    temp=colorfol[n];
		for(num=40*240;num>0;num--)
		{
			post_data(temp);
		}
	}
	bcm2835_delay(500);
	for(n=0;n<1;n++)
	{
		post_cmd(0x210,0x00);
		post_cmd(0x212,0x0000);
		post_cmd(0x211,0xEF);
		post_cmd(0x213,0x013F);

		post_cmd(0x200,0x0000);
		post_cmd(0x201,0x0000);
		
		en_lcd_index();
		post_data(0x202);
		en_lcd_data();
	    temp=colorfol[n];
		for(i=0;i<240;i++)
		{
			for(num=0;num<320;num++)
			{
		  		post_data(temp);
			}
		}
	//	bcm2835_delay(50);
	}
	dis_lcd();
}
Exemplo n.º 9
0
static PyObject *
PyBCM2835_delay(PyObject *self, PyObject *args)
{
	unsigned int millis;

	if (!PyArg_ParseTuple(args,"i",&millis)) {
		return NULL;
	}

	bcm2835_delay(millis);
	
	Py_RETURN_NONE;
}
Exemplo n.º 10
0
/**************************************************************************
    Function:	spi_lcd_init
    Purpose:	Initialize SPI device	
    Returns:	
    Note:	Sets defaults	
 *************************************************************************/
int spi_lcd_init(struct spi_lcd_dev *dev)
{
	// wait for 100ms for power up delay - could probably skip this.
	bcm2835_delay(100);

	bcm2835_spi_begin();
	bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST);
	bcm2835_spi_setDataMode(BCM2835_SPI_MODE0);
	bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_65536);
	bcm2835_spi_chipSeclect(BCM2835_SPI_CS0);
	bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0,LOW);
	
	return 0;
}
Exemplo n.º 11
0
Arquivo: led.c Projeto: bambreeze/rpi
int main(int argc, char **argv)
{
    uint8_t counter = 0;

	if (!bcm2835_init())  
		return 1;  

	// Set the pin to be an output
	bcm2835_gpio_fsel(LED, BCM2835_GPIO_FSEL_OUTP);  
    
	// Blinking the LED
	while (counter++ < 10) {
        bcm2835_gpio_write(LED, LOW);
		bcm2835_delay(1000);

        bcm2835_gpio_write(LED, HIGH);
	    bcm2835_delay(1000);
	}
    bcm2835_gpio_write(LED, LOW);

	bcm2835_close();  
	return 0;  
}
Exemplo n.º 12
0
int main(int argc, char **argv)
{
    if (!bcm2835_init())
        return 1;
    bcm2835_gpio_fsel(PIN, BCM2835_GPIO_FSEL_INPT);
    bcm2835_gpio_set_pud(PIN, BCM2835_GPIO_PUD_UP);
printf("irm test start: \n");
char turn;    
char n,p,result;
unsigned long i;
unsigned long buff[33];
while (1)
{	
	i++;delayMicroseconds(60);	
	if(bcm2835_gpio_lev(PIN)==1)
	{
	turn=1;
	}	
	else
	{
	if(turn==1)
		{
		if((n>0)&&(n<=33)) 
			{
			buff[n-1]=i;
			
			}
		n++;i=0;

		if(n==34)
			{
			n=0;
			//for(p=0;p<33;p++){printf("%d-%d;",p,buff[p]);}

			if(buff[0]>180 && buff[0]<250 && buff[1]<25 && buff[2]<25 && buff[3]<25 && buff[4]<25 && buff[5]<25 && buff[6]<25 && buff[7]<25 && buff[8]<25 && buff[9]>25 && buff[10]>25 && buff[11]>25 && buff[12]>25 && buff[13]>25) 
				{
				for(p=0;p<8;p++)
					{
					result>>=1;
					if(buff[25+p]>25) {result|=0x80;}
					}	
				printf("get the irm key code-hex ox%x \n",result);
				}
			bcm2835_delay(200);
			}
		}
	turn=0;
	}
}
Exemplo n.º 13
0
uint8_t my_spi_WEH001602_init(void)
 {

   bcm2835_gpio_fsel(MY_MISO, BCM2835_GPIO_FSEL_INPT);
   bcm2835_gpio_fsel(MY_MOSI, BCM2835_GPIO_FSEL_OUTP);
   bcm2835_gpio_fsel(MY_CLK, BCM2835_GPIO_FSEL_OUTP);
   bcm2835_gpio_fsel(MY_CS0, BCM2835_GPIO_FSEL_OUTP);

   bcm2835_gpio_write(MY_CLK, HIGH);
   bcm2835_gpio_write(MY_CS0, HIGH);
   bcm2835_gpio_write(MY_MOSI, LOW);

   G_clkval = 0;

   usleep(1000);

   my_spi_WEH001602_out_cmd(0b00111011);  // Function set: 8bit, 2 Zeilen, 5x8 Punkte, Westeurop (table 2). Charset
   bcm2835_delay(10);
   my_spi_WEH001602_out_cmd(0b00001100);  // Display on. Display an, Cursor aus, Blinken aus.
   bcm2835_delay(10);
   my_spi_WEH001602_out_cmd(0b00000001);  // Display clear
   bcm2835_delay(10);
   my_spi_WEH001602_out_cmd(0b00000010);  // Display home
   bcm2835_delay(10);
   my_spi_WEH001602_out_cmd(0b00000110);  // Entry mode: Dekrement, no shift.

   //my_spi_WEH001602_def_char(1,0x001F13151315131F); // small negative B
   //my_spi_WEH001602_def_char(2,0x001F181515151B1F); // small negative Q
   //my_spi_WEH001602_def_char(4,0x001F17171317111F); // small negative F
   //my_spi_WEH001602_def_char(3,0x001F17111011171F); // small vertical arrow ("play" indicator)
   //my_spi_WEH001602_def_char(5,0x00041F0E0E0E0E04); // bell icon (alarm active)
   //sleep(2);

   return 1;

 }
Exemplo n.º 14
0
/*================< readLight >================*
 * Read from the light sensor                  *
 *=============================================*/
int readLight(){
  if(!bcm2835_init) return 1;
  while(1){
    int value = 0;
    bcm2835_gpio_fsel(PIN18, BCM2835_GPIO_FSEL_OUTP); // set pin to output
    bcm2835_gpio_write(PIN18, LOW); //drive pin low
    bcm2835_delay(100); // wait for cap to discharge
    bcm2835_gpio_fsel(PIN18, BCM2835_GPIO_FSEL_INPT); // set pin to input
    // see how long it takes to charge cap
    while(bcm2835_gpio_lev(PIN18) == LOW){
      value++;
      if(value == 8) break;
    }
    return value;
  }
}
Exemplo n.º 15
0
void SetupGpio(uint8_t gpioIn, uint8_t gpioOut) {
    if (!bcm2835_init()) {
        exit(EXIT_FAILURE);
    }

    // Set output pin to HIGH.
    // Informs power circuit that pi is on.
    bcm2835_gpio_fsel(gpioOut, BCM2835_GPIO_FSEL_OUTP);
    bcm2835_gpio_write(gpioOut, HIGH);

    // Set PIN_IN to be an input with a pull-down resistor
    bcm2835_gpio_fsel(gpioIn, BCM2835_GPIO_FSEL_INPT);
    bcm2835_gpio_set_pud(gpioIn, BCM2835_GPIO_PUD_DOWN);

    // Wait a while
    bcm2835_delay(100);
}
Exemplo n.º 16
0
int main(int argc, char **argv)
{


      if (!bcm2835_init())
	return 1;
	char temp[1];				//temporary values
	int ret;
	int ad[2];

	bcm2835_i2c_begin();
	bcm2835_i2c_setSlaveAddress(0x29);      // addr pin attached to ground
	bcm2835_i2c_set_baudrate(1000);         // Default

	temp[0] = 0xa0;				//select the control register
	bcm2835_i2c_write(temp,1);
	temp[0] = 0x03;				//Power up the device
   	bcm2835_i2c_write(temp,1);
	bcm2835_delay(500);

	bcm2835_i2c_read(temp,1);
	printf("%x - if 33 the device is turned on\n",temp[0]);

	temp[0] = 0xac;				//Channel 0 lower byte
    	bcm2835_i2c_write(temp,1);		
	bcm2835_i2c_read(temp,1);

	ad[1]= (int)temp[0];

        temp[0] = 0xad;				//channel 0 upper byte
        bcm2835_i2c_write(temp,1);
        bcm2835_i2c_read(temp,1); 

	ad[0] = (int)temp[0];
	printf("ad value:%d\n",ad[0]*256+ad[1]);

	bcm2835_i2c_end();
	bcm2835_close();
	
	return 0;
}
Exemplo n.º 17
0
void my_spi_WEH001602_def_char(uint8_t char_idx, uint64_t bitmap)
 {

   uint8_t i, row;
   uint64_t mask = 255;
 
   if(char_idx > 7) 
    return;

   my_spi_WEH001602_out_cmd(0x40 + (char_idx*8));

   bcm2835_delay(10);

   for(i=0; i < 8; i++)
    {
     row = bitmap & mask;
     my_spi_WEH001602_out_data(row);
     bitmap = bitmap >> 8;
    }

 }
Exemplo n.º 18
0
int main(int argc, char **argv)
{
  Lcd22inch *lcd = new Lcd22inch();
  lcd->init(LCD_TO_TOP);
  lcd->drawTestChart();
  
  lcd->drawString("Hellow LCD 2.2 inch !!", 0, 0);

  time_t timer;
  
  for (int i=0; i<4; i++)
  {
    time(&timer);
    lcd->drawString(ctime(&timer), 0, 8); 
    bcm2835_delay(500);
  }

  delete lcd;

  return 0;
}
Exemplo n.º 19
0
int main(int argc, char **argv) {
  printf("HMC5883L 3-axis acceleromter example program\n");
  I2Cdev::initialize();
  HMC5883L mag ;
  if ( mag.testConnection() ) 
    printf("HMC5883L connection test successful\n") ;
  else {
    fprintf( stderr, "HMC5883L connection test failed! something maybe wrong, continueing anyway though ...\n");
    //return 1;
  }
  mag.initialize();
  mag.setSampleAveraging(HMC5883L_AVERAGING_8);
  mag.setGain(HMC5883L_GAIN_1090);
  int16_t mx, my, mz;
  float heading ;
  while (true) {
    mag.getHeading(&mx, &my, &mz);
    heading = atan2(my, mx)  * 180 / PI;
    printf("  mx:  %d       my:  %d      mz:  %d     heading:  %3.1f deg\r", mx, my, mz, heading);
    fflush(stdout);
    bcm2835_delay(200);
  }
  return 1; 
}
Exemplo n.º 20
0
int main(int argc, char **argv)
{

    int i;

    if (!bcm2835_init())
        return 1;

    // Set the pins to be an output
    bcm2835_gpio_fsel(PIN0, BCM2835_GPIO_FSEL_OUTP);
    bcm2835_gpio_fsel(PIN1, BCM2835_GPIO_FSEL_OUTP);
    bcm2835_gpio_fsel(PIN2, BCM2835_GPIO_FSEL_OUTP);
    bcm2835_gpio_fsel(PIN3, BCM2835_GPIO_FSEL_OUTP);
    bcm2835_gpio_fsel(PIN4, BCM2835_GPIO_FSEL_OUTP);
    bcm2835_gpio_fsel(PIN5, BCM2835_GPIO_FSEL_OUTP);
    bcm2835_gpio_fsel(PIN6, BCM2835_GPIO_FSEL_OUTP);
    bcm2835_gpio_fsel(PIN7, BCM2835_GPIO_FSEL_OUTP);

    while(1)
    {
        bcm2835_gpio_set(PIN0);
        bcm2835_delay(500);
        bcm2835_gpio_clr(PIN0);
        bcm2835_delay(500);

        bcm2835_gpio_set(PIN1);
        bcm2835_delay(500);
        bcm2835_gpio_clr(PIN1);
        bcm2835_delay(500);
        bcm2835_gpio_set(PIN2);
        bcm2835_delay(500);
        bcm2835_gpio_clr(PIN2);
        bcm2835_delay(500);

        bcm2835_gpio_set(PIN3);
        bcm2835_delay(500);
        bcm2835_gpio_clr(PIN3);
        bcm2835_delay(500);

        bcm2835_gpio_set(PIN4);
        bcm2835_delay(500);
        bcm2835_gpio_clr(PIN4);
        bcm2835_delay(500);

        bcm2835_gpio_set(PIN5);
        bcm2835_delay(500);
        bcm2835_gpio_clr(PIN5);
        bcm2835_delay(500);

        bcm2835_gpio_set(PIN6);
        bcm2835_delay(500);
        bcm2835_gpio_clr(PIN6);
        bcm2835_delay(500);

        bcm2835_gpio_set(PIN7);
        bcm2835_delay(500);
        bcm2835_gpio_clr(PIN7);
        bcm2835_delay(500);
    }

    bcm2835_close();
    return 0;
}
Exemplo n.º 21
0
int main(int argc, char **argv)
{
    int16_t ledIndexCounter = 0, scanPasses=0, colourIndex=0;
	
	initData();
	
	//Initiate the SPI Data Frame
	if (!bcm2835_init())
    {
      printf("bcm2835_init failed. Are you running as root??\n");
      return 1;
    }
    if (!bcm2835_spi_begin())
    {
      printf("bcm2835_spi_begin failedg. Are you running as root??\n");
      return 1;
    }
    bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST);      // The default
    bcm2835_spi_setDataMode(BCM2835_SPI_MODE0);                   // The default
	/*
		
	BCM2835_SPI_MODE0 		CPOL = 0, CPHA = 0
	BCM2835_SPI_MODE1 		CPOL = 0, CPHA = 1
	BCM2835_SPI_MODE2 		CPOL = 1, CPHA = 0
	BCM2835_SPI_MODE3 		CPOL = 1, CPHA = 1	
	*/
    bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_16); // The default
	/*

		BCM2835_SPI_CLOCK_DIVIDER_65536 	65536 = 262.144us = 3.814697260kHz
		BCM2835_SPI_CLOCK_DIVIDER_32768 	32768 = 131.072us = 7.629394531kHz
		BCM2835_SPI_CLOCK_DIVIDER_16384 	16384 = 65.536us = 15.25878906kHz
		BCM2835_SPI_CLOCK_DIVIDER_8192 		8192 = 32.768us = 30/51757813kHz
		BCM2835_SPI_CLOCK_DIVIDER_4096 		4096 = 16.384us = 61.03515625kHz
		BCM2835_SPI_CLOCK_DIVIDER_2048 		2048 = 8.192us = 122.0703125kHz
		BCM2835_SPI_CLOCK_DIVIDER_1024 		1024 = 4.096us = 244.140625kHz
		BCM2835_SPI_CLOCK_DIVIDER_512 		512 = 2.048us = 488.28125kHz
		BCM2835_SPI_CLOCK_DIVIDER_256 		256 = 1.024us = 976.5625kHz
		BCM2835_SPI_CLOCK_DIVIDER_128 		128 = 512ns = = 1.953125MHz
		BCM2835_SPI_CLOCK_DIVIDER_64 		64 = 256ns = 3.90625MHz
		BCM2835_SPI_CLOCK_DIVIDER_32 		32 = 128ns = 7.8125MHz
		BCM2835_SPI_CLOCK_DIVIDER_16 		16 = 64ns = 15.625MHz
		BCM2835_SPI_CLOCK_DIVIDER_8 		8 = 32ns = 31.25MHz
		BCM2835_SPI_CLOCK_DIVIDER_4 		4 = 16ns = 62.5MHz
		BCM2835_SPI_CLOCK_DIVIDER_2 		2 = 8ns = 125MHz, fastest you can get	
	
	*/
    bcm2835_spi_chipSelect(BCM2835_SPI_CS0);                      // The default
    bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, LOW);      // the default
    
	for(colourIndex=0; colourIndex<rainbowSize*10; colourIndex+=5)
	{
		getColour(colourIndex%rainbowSize, tmpColour);
		//set 1st Pixel
		ledDataBlock[8]=255;
		ledDataBlock[9]=tmpColour[2];
		ledDataBlock[10]=tmpColour[1];
		ledDataBlock[11]=tmpColour[0];
		//push the array
		for(ledIndexCounter=(spiFrameLength-(endFrameLength*bytesPerLED))-bytesPerLED; ledIndexCounter>8; ledIndexCounter-=bytesPerLED)
		{
			ledDataBlock[ledIndexCounter] = ledDataBlock[ledIndexCounter-bytesPerLED];
			ledDataBlock[ledIndexCounter+1] = ledDataBlock[ledIndexCounter+1-bytesPerLED];
			ledDataBlock[ledIndexCounter+2] = ledDataBlock[ledIndexCounter+2-bytesPerLED];
			ledDataBlock[ledIndexCounter+3] = ledDataBlock[ledIndexCounter+3-bytesPerLED];
		}
		//send to LEDs
		bcm2835_spi_writenb(ledDataBlock, spiFrameLength);
		bcm2835_delay(5);
	}
    //clear and render
	initData();
	bcm2835_spi_writenb(ledDataBlock, spiFrameLength);
	//close the spi bus
	bcm2835_spi_end();
    bcm2835_close();
    return 0;
}
Exemplo n.º 22
0
/**
 * @brief Delay in ms.
 * @param ms Delay in milliseconds
 * @return none
 */	
void delay_ms(unsigned int ms)
{
	bcm2835_delay(ms);
}
Exemplo n.º 23
0
int main(int argc, char *argv[]) {
	int opt;
	bool daemon = true;

	atexit(close_sockets);
	while ((opt = getopt(argc, argv, "m:vf")) != -1)
		switch (opt) {
		case 'm':
			mux = connect_block(optarg, 5678);
			break;
		case 'v':
			verbose = true;
			daemon = false;
			break;
		case 'f':
			daemon = false;
			break;
		default:
			fatal("Usage: %s: -m mux:port [-v] [-f]\n", argv[0]);
		}
	if (mux < 0)
		mux = connect_block("localhost", 5678);
		
	if (daemon)
		daemon_mode();

	if (!bcm2835_init())
		fatal("initialising bcm2835\n");

	bcm2835_gpio_fsel(pin, BCM2835_GPIO_FSEL_OUTP);

	signal(SIGINT, signal_handler);
	signal(SIGPIPE, SIG_IGN);

	struct timeval last, now;
	last.tv_sec = 0;

	char buf[256];
	for (;;) {
		fd_set rd;
		FD_ZERO(&rd);
		FD_SET(mux, &rd);

		gettimeofday(&now, 0);
		if (now.tv_sec - last.tv_sec > idle_secs)
			bcm2835_gpio_write(pin, LOW);

		struct timeval dt;
		dt.tv_sec = idle_secs;
		dt.tv_usec = 0;
		if (0 > select(mux+1, &rd, 0, 0, &dt))
			fatal("select: %s\n", strerror(errno));

		if (FD_ISSET(mux, &rd)) {
			int n = sock_read_line(mux, buf, sizeof(buf));
			if (verbose)
				printf("%d: %d [%s]\n", mux, n, buf);
			if (n > 0) {
				sensor s;
				s.from_csv(buf);
				if (s.is_wireless()) {
					last.tv_sec = now.tv_sec;
					bcm2835_gpio_write(pin, LOW);
					bcm2835_delay(20);
					bcm2835_gpio_write(pin, HIGH);
				}
			} else if (n == 0)
				fatal("Mux died\n");
		}
	}
}
Exemplo n.º 24
0
// this is a simple test program that prints out what it will do rather than 
// actually doing it
int main(int argc, char **argv)
{
    // Be non-destructive
    bcm2835_set_debug(1);

    if (!bcm2835_init())
	return 1;

    // Configure some GPIO pins fo some testing
    // Set RPI pin P1-11 to be an output
    bcm2835_gpio_fsel(RPI_GPIO_P1_11, BCM2835_GPIO_FSEL_OUTP);
    // Set RPI pin P1-15 to be an input
    bcm2835_gpio_fsel(RPI_GPIO_P1_15, BCM2835_GPIO_FSEL_INPT);
    //  with a pullup
    bcm2835_gpio_set_pud(RPI_GPIO_P1_15, BCM2835_GPIO_PUD_UP);
    // And a low detect enable
    bcm2835_gpio_len(RPI_GPIO_P1_15);
    // and input hysteresis disabled on GPIOs 0 to 27
    bcm2835_gpio_set_pad(BCM2835_PAD_GROUP_GPIO_0_27, BCM2835_PAD_SLEW_RATE_UNLIMITED|BCM2835_PAD_DRIVE_8mA);

#if 1
    // Blink
    while (1)
    {
	// Turn it on
	bcm2835_gpio_write(RPI_GPIO_P1_11, HIGH);
	
	// wait a bit
	bcm2835_delay(500);
	
	// turn it off
	bcm2835_gpio_write(RPI_GPIO_P1_11, LOW);
	
	// wait a bit
	bcm2835_delay(500);
    }
#endif

#if 0
    // Read input
    while (1)
    {
	// Read some data
	uint8_t value = bcm2835_gpio_lev(RPI_GPIO_P1_15);
	printf("read from pin 15: %d\n", value);
	
	// wait a bit
	bcm2835_delay(500);
    }
#endif

#if 0
    // Look for a low event detection
    // eds will be set whenever pin 15 goes low
    while (1)
    {
	if (bcm2835_gpio_eds(RPI_GPIO_P1_15))
	{
	    // Now clear the eds flag by setting it to 1
	    bcm2835_gpio_set_eds(RPI_GPIO_P1_15);
	    printf("low event detect for pin 15\n");
	}

	// wait a bit
	bcm2835_delay(500);
    }
#endif

    if (!bcm2835_close())
	return 1;

    return 0;
}
Exemplo n.º 25
0
/* ======================================================================
Function: initRadioModule
Purpose : initialize a module
Input   : Module Index from modules table
Output  : -
Comments: -
====================================================================== */
bool initRadioModule( uint8_t index) {
  RHGenericDriver * driver = drivers[index];
  //RH_RF69 * driver = (RH_RF69 *) drivers[index];

  // Module Information
  printf( "%s (CS=GPIO%d, IRQ=GPIO%d, RST=GPIO%d, LED=GPIO%d)", 
          MOD_name[index], CSN_pins[index], IRQ_pins[index], RST_pins[index], LED_pins[index] );

  // Light Module LED
  pinMode(LED_pins[index], OUTPUT);

  // IRQ Pin, as input with Pull down (in case no module connected)
  pinMode(IRQ_pins[index], INPUT);
  bcm2835_gpio_set_pud(IRQ_pins[index], BCM2835_GPIO_PUD_DOWN);

  // we enable rising edge detection 
  bcm2835_gpio_ren(IRQ_pins[index]);

  // Reset module and blink the module LED 
  digitalWrite(LED_pins[index], HIGH);
  pinMode(RST_pins[index], OUTPUT);
  digitalWrite(RST_pins[index], LOW);
  bcm2835_delay(150);
  digitalWrite(RST_pins[index], HIGH);
  bcm2835_delay(100);
  digitalWrite(LED_pins[index], LOW);

  if (!driver->init()) {
    fprintf( stderr, "\n%s init failed, Please verify wiring/module\n", MOD_name[index] );
  } else {
    // Since we'll check IRQ line with bcm_2835 Rising edge detection
    // In case radio already have a packet, IRQ is high and will never
    // go to low until cleared, so never fire IRQ LOW to HIGH again 
    // Except if we clear IRQ flags and discard packet if any!
    // ==> This is now done before reset
    //driver->available();
    // now we can enable rising edge detection 
    //bcm2835_gpio_ren(IRQ_pins[index]);

    // set Node ID
    driver->setThisAddress(MOD_id[index]); // filtering address when receiving
    driver->setHeaderFrom(MOD_id[index]);  // Transmit From Node

    // Get all frame, we're in demo mode
    driver->setPromiscuous(true);   

    // We need to check module type since generic driver does
    // not expose driver specific methods
    switch (index) {
      // RF95
      case IDX_MOD1:
      case IDX_MOD2:
        // Defaults RF95 after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on
        // The default transmitter power is 13dBm, using PA_BOOST.
        // If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then
        // you can set transmitter powers from 5 to 23 dBm:
        // check your country max power useable, in EU it's +14dB
        ((RH_RF95 *) driver)->setTxPower(14, false);
        // If you are using Modtronix inAir4 or inAir9,or any other module which uses the
        // transmitter RFO pins and not the PA_BOOST pins
        // then you can configure the power transmitter power for -1 to 14 dBm and with useRFO true.
        // Failure to do that will result in extremely low transmit powers.
        // rf95.setTxPower(14, true);

        // You can optionally require this module to wait until Channel Activity
        // Detection shows no activity on the channel before transmitting by setting
        // the CAD timeout to non-zero:
        //rf95.setCADTimeout(10000);

        // Adjust Frequency
        ((RH_RF95 *) driver)->setFrequency( MOD_freq[index] );
      break;

      // RF69
      case IDX_MOD3:
        // Adjust Frequency
        ((RH_RF69 *) driver)->setFrequency( MOD_freq[index] );
        
        // Set TX power to High power RFMH69
        //((RH_RF69 *) driver)->setTxPower(13);
        ((RH_RF69 *) driver)->setTxPower(20);

        // Change default radioHead modem configuration to moteino one
        ((RH_RF69 *) driver)->setModemConfig( RH_RF69::FSK_MOTEINO);

        // set Network ID (by sync words)
        uint8_t syncwords[2];
        syncwords[0] = 0x2d;
        syncwords[1] = RF69_3_GROUP_ID;
        ((RH_RF69 *) driver)->setSyncWords(syncwords, sizeof(syncwords));
      break;
    }

    printf( " OK!, NodeID=%d @ %3.2fMHz\n", MOD_id[index], MOD_freq[index] );
    return true;
  }
  
  return false;
}
Exemplo n.º 26
0
int main(int argc, char *argv[]) {

	uint8_t ctr = 0;
	GPAD_ST gpads[GPADSNUM];
	BTN_DEV_ST button;
	int16_t clockpin;
	int16_t strobepin;
	int16_t data1pin;
	int16_t data2pin;
	int16_t clockpin_v2;
	int16_t strobepin_v2;
	int16_t data1pin_v2;
	int16_t data2pin_v2;

	if (!bcm2835_init())
		return 1;
	
	if (readConfigurationfile() != 0 ) {
		return 1;
	}

	if (strcmp(confres.adapter_version,"1x")==0) {
		clockpin = RPI_GPIO_P1_19;
		strobepin = RPI_GPIO_P1_23;
		data1pin = RPI_GPIO_P1_05;
		data2pin = RPI_GPIO_P1_07;
		clockpin_v2 = RPI_V2_GPIO_P1_19;
		strobepin_v2 = RPI_V2_GPIO_P1_23;
		data1pin_v2 = RPI_V2_GPIO_P1_05;
		data2pin_v2 = RPI_V2_GPIO_P1_07;
		printf("[SNESDev-Rpi] Using pin setup for RetroPie GPIO-Adapter Version 1.X\n");

	} else if (strcmp(confres.adapter_version,"2x")==0) {
		clockpin = RPI_GPIO_P1_16;
		strobepin = RPI_GPIO_P1_18;
		data1pin = RPI_GPIO_P1_15;
		data2pin = RPI_GPIO_P1_13;
		clockpin_v2 = RPI_V2_GPIO_P1_16;
		strobepin_v2 = RPI_V2_GPIO_P1_18;
		data1pin_v2 = RPI_V2_GPIO_P1_15;
		data2pin_v2 = RPI_V2_GPIO_P1_13;
		printf("[SNESDev-Rpi] Using pin setup for RetroPie GPIO-Adapter Version 2.X\n");

	} else {
		clockpin = RPI_GPIO_P1_16;
		strobepin = RPI_GPIO_P1_18;
		data1pin = RPI_GPIO_P1_15;
		data2pin = RPI_GPIO_P1_13;
		clockpin_v2 = RPI_V2_GPIO_P1_16;
		strobepin_v2 = RPI_V2_GPIO_P1_18;
		data1pin_v2 = RPI_V2_GPIO_P1_15;
		data2pin_v2 = RPI_V2_GPIO_P1_13;
		printf("[SNESDev-Rpi] Using pin setup for RetroPie GPIO-Adapter Version 2.X\n");
	}


	if (confres.gamepad1_enabled || confres.gamepad2_enabled) {

		gpads[0].port = 1;
		gpads[1].port = 1;
		// check board revision and set pins to be used
		// these are acutally also used by the gamecon driver
		if (get_rpi_revision()==1)
		{
			gpads[0].pin_clock = clockpin;
			gpads[0].pin_strobe = strobepin;
			gpads[0].pin_data = data1pin;
			gpads[1].pin_clock = clockpin;
			gpads[1].pin_strobe = strobepin;
			gpads[1].pin_data = data2pin;		
		} else {
			gpads[0].pin_clock = clockpin_v2;
			gpads[0].pin_strobe = strobepin_v2;
			gpads[0].pin_data = data1pin_v2;
			gpads[1].pin_clock = clockpin_v2;
			gpads[1].pin_strobe = strobepin_v2;
			gpads[1].pin_data = data2pin_v2;		
		}
		if (strcmp(confres.gamepad1_type,"nes")==0) {
			gpads[0].type = GPAD_TYPE_NES;
		} else {
			gpads[0].type = GPAD_TYPE_SNES;
		}
		if (strcmp(confres.gamepad2_type,"nes")==0) {
			gpads[1].type = GPAD_TYPE_NES;
		} else {
			gpads[1].type = GPAD_TYPE_SNES;
		}

		if (confres.gamepad1_enabled) {
			printf("[SNESDev-Rpi] Enabling game pad 1 with type '%s'.\n", confres.gamepad1_type);
			gpad_open(&gpads[0]);
			switch (gpads->type) {
			case GPAD_TYPE_SNES:
				uinput_gpad_open(&uinp_gpads[0], UINPUT_GPAD_TYPE_SNES);
				break;
			case GPAD_TYPE_NES:
				uinput_gpad_open(&uinp_gpads[0], UINPUT_GPAD_TYPE_NES);
				break;
			default:
				break;
			}
		}
		if (confres.gamepad2_enabled) {
			printf("[SNESDev-Rpi] Enabling game pad 2 with type '%s'.\n", confres.gamepad2_type);
			gpad_open(&gpads[1]);
			switch (gpads->type) {
			case GPAD_TYPE_SNES:
				uinput_gpad_open(&uinp_gpads[1], UINPUT_GPAD_TYPE_SNES);
				break;
			case GPAD_TYPE_NES:
				uinput_gpad_open(&uinp_gpads[1], UINPUT_GPAD_TYPE_NES);
				break;
			default:
				break;
			}
		}
	}

	if (confres.button_enabled) {
		printf("[SNESDev-Rpi] Enabling button.\n");
		button.port = 1;
		if (get_rpi_revision()==1) {
			button.pin = BUTTONPIN;
		} else {
			button.pin = BUTTONPIN_V2;
		}		
		btn_open(&button);
		uinput_kbd_open(&uinp_kbd);
	}

	register_signalhandlers();

	///* enter the main loop */
	doRun = 1;
	while (doRun) {
		if (confres.gamepad1_enabled || confres.gamepad2_enabled) {						
			/* read states of the buttons */
			for (ctr = 0; ctr < GPADSNUM; ctr++) {
				gpad_read(&gpads[ctr]);
			}

			///* send an event (pressed or released) for each button */
			for (ctr = 0; ctr < GPADSNUM; ctr++) {
				if ((ctr==0 && !(confres.gamepad1_enabled)) || 
					(ctr==1 && !(confres.gamepad2_enabled))) {
					continue;
				}

				gpad_read(&gpads[ctr]);
				processPadBtn(gpads[ctr].state, EV_KEY, GPAD_SNES_A, BTN_A,
						&uinp_gpads[ctr]);
				processPadBtn(gpads[ctr].state, EV_KEY, GPAD_SNES_B, BTN_B,
						&uinp_gpads[ctr]);
				processPadBtn(gpads[ctr].state, EV_KEY, GPAD_SNES_X, BTN_X,
						&uinp_gpads[ctr]);
				processPadBtn(gpads[ctr].state, EV_KEY, GPAD_SNES_Y, BTN_Y,
						&uinp_gpads[ctr]);
				processPadBtn(gpads[ctr].state, EV_KEY, GPAD_SNES_L, BTN_TL,
						&uinp_gpads[ctr]);
				processPadBtn(gpads[ctr].state, EV_KEY, GPAD_SNES_R, BTN_TR,
						&uinp_gpads[ctr]);
				processPadBtn(gpads[ctr].state, EV_KEY, GPAD_SNES_SELECT,
						BTN_SELECT, &uinp_gpads[ctr]);
				processPadBtn(gpads[ctr].state, EV_KEY, GPAD_SNES_START,
						BTN_START, &uinp_gpads[ctr]);

				if ((gpads[ctr].state & GPAD_SNES_LEFT) == GPAD_SNES_LEFT) {
					uinput_gpad_write(&uinp_gpads[ctr], ABS_X, 0, EV_ABS);
				} else if ((gpads[ctr].state & GPAD_SNES_RIGHT) == GPAD_SNES_RIGHT) {
					uinput_gpad_write(&uinp_gpads[ctr], ABS_X, 4, EV_ABS);
				} else {
					uinput_gpad_write(&uinp_gpads[ctr], ABS_X, 2, EV_ABS);
				}
				if ((gpads[ctr].state & GPAD_SNES_UP) == GPAD_SNES_UP) {
					uinput_gpad_write(&uinp_gpads[ctr], ABS_Y, 0, EV_ABS);
				} else if ((gpads[ctr].state & GPAD_SNES_DOWN) == GPAD_SNES_DOWN) {
					uinput_gpad_write(&uinp_gpads[ctr], ABS_Y, 4, EV_ABS);
				} else {
					uinput_gpad_write(&uinp_gpads[ctr], ABS_Y, 2, EV_ABS);
				}
			}
		}

		if (confres.button_enabled) {
			btn_read(&button);

			switch (button.state) {
			case BTN_STATE_IDLE:
				break;
			case BTN_STATE_PRESSED:
				if (button.pressedCtr == 1 && button.duration >= 1) {
					uinput_kbd_write(&uinp_kbd, KEY_R, 1, EV_KEY);
				}
				break;
			case BTN_STATE_RELEASED:
					if (button.pressedCtr == 1 && button.duration >= 1) {
						uinput_kbd_write(&uinp_kbd, KEY_R, 0, EV_KEY);
					} else if (button.pressedCtr == 3 && button.duration >= 1) {
						// Sending ESC
						uinput_kbd_write(&uinp_kbd, KEY_ESC, 1, EV_KEY);
						usleep(50000);
						uinput_kbd_write(&uinp_kbd, KEY_ESC, 0, EV_KEY);
					} else if (button.pressedCtr == 5 && button.duration >= 1) {
						uinput_kbd_write(&uinp_kbd, KEY_F4, 1, EV_KEY);
						usleep(50000);
						uinput_kbd_write(&uinp_kbd, KEY_F4, 0, EV_KEY);
						// shutting down
						system("shutdown -t 3 -h now");
					}
				break;
			}
		}

		/* wait for some time to keep the CPU load low */
		if (confres.button_enabled && !(confres.gamepad1_enabled || confres.gamepad2_enabled)) {
			bcm2835_delay(FRAMEWAITLONG);
		} else {
			bcm2835_delay(FRAMEWAIT);
		}
	}

	return 0;

}
Exemplo n.º 27
0
/* ======================================================================
Function: main
Purpose : not sure ;)
Input   : command line parameters
Output  : -
Comments: -
====================================================================== */
int main (int argc, const char* argv[] )
{
  // LED blink ms timer saving
  unsigned long led_blink[NB_MODULES] = {0,0,0};
  
  // caught CTRL-C to do clean-up
  signal(SIGINT, sig_handler);
  
  // Display app name
  printf( "%s\n", __BASEFILE__);
  for (uint8_t i=0; i<strlen(__BASEFILE__); i++) {
    printf( "=");
  }
  printf("\n");

  // Init GPIO bcm
  if (!bcm2835_init()) {
    fprintf( stderr, "bcm2835_init() Failed\n\n" );
    return 1;
  }

  //save driver instances pointer
  drivers[IDX_MOD1] = &rf95_1;
  drivers[IDX_MOD2] = &rf95_2;
  drivers[IDX_MOD3] = &rf69_3;

  // light onboard LEDs 
  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, HIGH);

  // configure all modules I/O CS pins to 1 before anything else
  // to avoid any problem with SPI sharing
  for (uint8_t i=0 ; i<NB_MODULES; i++) {
    // CS Ping as output and set to 1
    pinMode(CSN_pins[i], OUTPUT);
    digitalWrite(CSN_pins[i], HIGH);
  }

  // configure all modules I/O pins 
  for (uint8_t i=0 ; i<NB_MODULES; i++) {
    // configure all modules
    if (!initRadioModule(i)){
      force_exit = true;
    }
  }

  // All init went fine, continue specific init if any
  if (!force_exit) {
    // Set all modules in receive mode
    rf95_1.setModeRx();
    rf95_2.setModeRx();
    rf69_3.setModeRx();
    printf( "Listening for incoming packets...\n" );
  }

  // Begin the main loop code 
  // ========================
  while (!force_exit) { 
    // Loop thru modules
    for (uint8_t idx=0 ; idx<NB_MODULES ; idx++) {
      // Rising edge fired ?
      if (bcm2835_gpio_eds(IRQ_pins[idx])) {
        // Now clear the eds flag by setting it to 1
        bcm2835_gpio_set_eds(IRQ_pins[idx]);
        //printf("Packet Received, Rising event detect for pin GPIO%d\n", IRQ_pins[idx]);
  
        // Start associated led blink
        led_blink[idx] = millis();
        digitalWrite(LED_pins[idx], HIGH);
        getReceivedData(idx); 
      } // has IRQ

      // A module led blink timer expired ? Light off
      if (led_blink[idx] && millis()-led_blink[idx]>LED_BLINK_MS) {
        led_blink[idx] = 0;
        digitalWrite(LED_pins[idx], LOW);
      } // Led timer expired

      getReceivedData(idx); 

    } // For Modules
    
    // On board led blink (500ms off / 500ms On)
    digitalWrite(LED_PIN, (millis()%1000)<500?LOW:HIGH);

    // Let OS doing other tasks
    // For timed critical appliation receiver, you can reduce or delete
    // this delay, but this will charge CPU usage, take care and monitor
    bcm2835_delay(5);
  }

  // We're here because we need to exit, do it clean
  // Light off on board LED
  digitalWrite(LED_PIN, LOW);
  // All module LEDs off, all modules CS line High
  for (uint8_t i=0 ; i<NB_MODULES; i++) {
    digitalWrite(LED_pins[i], LOW);
    digitalWrite(CSN_pins[i], HIGH);
  }
  printf( "\n%s, done my job!\n", __BASEFILE__ );
  bcm2835_close();
  return 0;
}
//void bcm2835_delay (unsigned int millis);
/// Call bcm2835_delay with 1 parameter
/// \par            Refer
/// \par            Modify
void ope_delay(void)
{
    get_int_code();
    bcm2835_delay( *((uint32_t *)(buff+1)) );
}
Exemplo n.º 29
0
//--------------------------------------------------------------------------------------------------
// Name:    	SleepMs
// Function:  	Sleep /Delay in Milliseconds
//            
// Parameter: 	Milliseconds
// Return:      -
//--------------------------------------------------------------------------------------------------
void SleepMs(uint32 ms)
{
	bcm2835_delay(ms);
}
Exemplo n.º 30
0
int get(uint8_t DIS_num, uint8_t cmd) {
	uint8_t curr_total_att = ATT_TOTAL;
	uint8_t curr_a5_att = ATT_A5;
	uint8_t curr_got_a5_att = ATT_GOT_A5;

	char read_tmp_buf[7];
	char dummy_byte = 0x55;
	char tmp = 0x55;
	uint8_t success = 0;

	// Стандартный стартовый байт
	write_packet.write_pos.start_byte = 0xAA;

	// Запишем команду
	write_packet.write_pos.cmd_number = cmd;

	// Данные - нули
	for (uint8_t i = 0; i < 4; i++) {
		write_packet.write_pos.data[i] = 0x00;
	}
	// Считаем CRC
	write_packet.write_pos.crc = Crc8(write_packet.write_frame, 6);

	// Начинаем пробовать получить 0хА5
	while (curr_total_att) {
		curr_total_att--;
//		printf("Chip select... \n");
		chipSelect(DIS_num);
//		printf("Done Chip select... \n");

		bcm2835_spi_transfernb((char*) write_packet.write_frame, read_tmp_buf, 7);
//		printf("Transferred cmd... \n");

		// ждем получения 0хА5
		while (curr_a5_att) {
			curr_a5_att--;
			bcm2835_spi_transfernb(&dummy_byte, &tmp, 1);
			bcm2835_delay(1);

			// если получили, то перестаем ждать
			if (0xA5 == tmp) {
				break;
			}
		}

		// если был получен А5
		if (tmp == 0xA5) {
//			printf("Got 0xA5 \n");
			// ждем пока пройдут все A5
			while (((tmp == 0xA5) || (tmp == 0x55)) && curr_got_a5_att) {
				curr_got_a5_att--;
				bcm2835_spi_transfernb(&dummy_byte, &tmp, 1);
			}
			// получаем сами данные
			if (curr_got_a5_att) {
//				printf("Got data \n");
				bcm2835_spi_transfernb(&dummy_byte, (char*) read_packet.read_frame, 5);

				success = 1;
				chipSelect(DIS_NONE);
				break;
			}
			curr_got_a5_att = ATT_GOT_A5;
		} else {
			curr_a5_att = ATT_A5;
		}

		chipSelect(DIS_NONE);
	}

	if (success == 1) {
		// скопируем в буфер данные
		for(uint8_t i = 0; i < 4; i++){
			usr_data_buf_ptr[i] = read_packet.read_pos.data[i];
			read_packet.read_pos.data[i] = 0;
		}
		return 0;
	} else {
		printf("Failed to get \n");
		return 1;
	}
}