예제 #1
0
/** helper functions to switch direction of comms */
void setTX(int id){
  #if defined(ARBOTIX_PLUS) || defined(SERVO_STIK)
    if(dynamixel_bus_config[id-1] > 0)
        setRX_WR();
    else
        setAX_WR();
  #else
    // emulate half-duplex on ArbotiX, ArbotiX w/ RX Bridge
    #ifdef ARBOTIX_WITH_RX
      PORTD |= 0x10;
    #endif
    bitClear(UCSR2B, RXEN2);    
    bitSet(UCSR2B, TXEN2);
    bitClear(UCSR2B, RXCIE2);
    ax_tx_Pointer = 0;
  #endif
}
예제 #2
0
void setRX(){ 
	
    bitClear(UCSR0B, TXEN0);
    bitSet(UCSR0B, RXCIE0);
    bitSet(UCSR0B, RXEN0);
    ax_rx_int_Pointer = 0;
    ax_rx_Pointer = 0;
}
예제 #3
0
void ds3231_clear_alarm2()
{
	uint8_t reg;

	reg = ds3231_read_reg(DS3231_STAT_ADDR);
	bitClear(reg, 1);
	ds3231_write_reg(DS3231_STAT_ADDR, reg);
}
예제 #4
0
void SXLoco::toggleF1() {
   if (bitRead(_sxData,7)) {
      bitClear(_sxData,7);
   } else {
      bitSet(_sxData,7);
   }
   _changed=1;
}
예제 #5
0
void loop()
{
  if (stop_ints) //data in buffer
  {
    unsigned long binary = 1;
    //byte i = 0;
    for (byte j = 0; j < 46; j++)
    {
      //printf(binary);
      if ((bufor[j] > 220) &&
          (bufor[j] < 400))
      {
        binary <<= 1;
        //binary |= 1;
        //i++;
        bitSet(binary,0);
      }
      else if ((bufor[j] > 90) &&
               (bufor[j] < 220) && (bufor[j + 1] > 90) &&
               (bufor[j + 1] < 220)) {
        binary <<= 1;
        j++;
        
      }
      else if ((bufor[j] > 90) &&
               (bufor[j] < 220) && (bufor[j + 1] > 220) &&
               (bufor[j + 1] < 400)) {
        binary <<= 1;
        bitSet(binary,0);
        //i += 2;
        j++;
      }
      else break;
          }
    if (bitRead(binary,23))
    {
      bitClear(binary,23);
      printf("remoteID:");
      printf((binary / 128) & 65535);
      printf(" - ");
      printf("key code:");
      printf(binary & 127);
      printf("\n");
    }
    else {
      printf("wrong code  ");
      printf("\n");
      printf(binary, BIN);
      printf("\n");
    }
    delay (1000);
    header = false;
    impulse = 0;
    stop_ints = false;

    // }
  }
}
예제 #6
0
void Timer::update_tp()
{

    bitClear(status, Q_ONS);

    if(bitRead(status, INPUT) || bitRead(status, Q)){

        if(current < setpoint){ // on continue de compter si on a pas déjà atteint la consigne
            switch(base){

                case MILLIS:
                    current += 100;
                    break;
                case SECOND:
                    if(++temp>=10){
                        temp=0;
                        current++;
                    }
                    break;
                case MINUTE:
                    if(++temp>=600){
                        temp=0;
                        current++;
                    }
                break;
            }

            bitSet(status, Q);

        }else{ // on a terminé de compter

            if(bitRead(status, Q)) // si on ne compte plus et qu'on a pas encore basculé la sortie on bascule le one shot
                bitSet(status, Q_ONS);

            current=0;
            temp=0;
            bitClear(status, Q);

        }

    }

    bitClear(status, INPUT); // on efface le flag d'entrée, il doit normalement être remis à vrai dans le scenario. Si ce n'est pas le cas, la tempo est remise à zéro.

}
void ModemATBased::clearFlags ()
{
    /*
     *  This value refer to modem_read_... consts
     */
    ModemATBased::vculFlags  =  0x00FFFFFF;
    
    bitClear ( ModemATBased::vculFlags, modem_read_continue );
}
예제 #8
0
 /* Write to RX bus */
 void setRX_WR(){
   #ifdef SERVO_STIK
     PORTC |= 0x40;
   #else
     PORTG |= 0x08;
   #endif
     bitClear(UCSR1B, RXEN1);    
     ax_tx_Pointer = 0;
 }
예제 #9
0
/** initializes serial transmit at baud, 8-N-1 */
void AX12::init (long baud) {
#if defined (__AVR_ATmega168__) || defined (__AVR_ATmega328P__)
    bitClear (UCSR0A, U2X0); 
    UBRR0H = ((F_CPU / 16 + baud / 2) / baud - 1) >> 8;
    UBRR0L = ((F_CPU / 16 + baud / 2) / baud - 1);        // setea la velocidad del USART
#elif defined (__AVR_ATmega1280__) || defined (__AVR_ATmega2560__)    
    bitClear (UCSR1A, U2X1); 
    UBRR1H = ((F_CPU / 16 + baud / 2) / baud - 1) >> 8;
    UBRR1L = ((F_CPU / 16 + baud / 2) / baud - 1);        // setea la velocidad del USART
#elif defined (__AVR_ATmega8__)
    bitClear (UCSRA, U2X); 
    UBRRH = ((F_CPU / 16 + baud / 2) / baud - 1) >> 8;
    UBRRL = ((F_CPU / 16 + baud / 2) / baud - 1);        // setea la velocidad del USART
#endif    
    ax_rx_Pointer = 0;
    // deshabilita tanto recepción como trasmisión
    setNone();
}
예제 #10
0
void DS1302_write(int address, uint8_t data)
{
  // clear lowest bit (read bit) in address
  bitClear(address, DS1302_READBIT);
  _DS1302_start();
  _DS1302_togglewrite(address, false);
  _DS1302_togglewrite(data, false);
  _DS1302_stop();
}
예제 #11
0
파일: Task.c 프로젝트: gondur/homeworld_src
/*-----------------------------------------------------------------------------
    Name        : taskResume
    Description : Resumes selected task.
    Inputs      : handle - handle of task
    Outputs     : Clears the paused bit of specified taskData structure
    Return      : void
----------------------------------------------------------------------------*/
void taskResume(taskhandle handle)
{
    taskInitCheck();
    dbgAssertOrIgnore(handle >= 0);
    dbgAssertOrIgnore(handle < taskMaxTask);
    dbgAssertOrIgnore(taskData[handle] != NULL);

    bitClear(taskData[handle]->flags, TF_Paused);
}
예제 #12
0
파일: DR_RF12.cpp 프로젝트: DMWR/modules
static void rf12_xfer (uint16_t cmd) {
    // writing can take place at full speed, even 8 MHz works
    bitClear(SS_PORT, cs_pin);
    uint8_t r1 = rf12_byte(cmd >> 8) << 8;
    //rf12_byte(cmd >> 8) << 8;
    uint8_t r2 = rf12_byte(cmd);
    //rf12_byte(cmd);
    bitSet(SS_PORT, cs_pin);
}
예제 #13
0
 /* Write to AX bus */
 void setAX_WR(){
   #ifdef SERVO_STIK
     PORTC |= 0x80;
   #else
     PORTG |= 0x10;
   #endif
     bitClear(UCSR2B, RXEN2);    
     ax_tx_Pointer = 0;
 }
예제 #14
0
void RegisterList::writeCVBit(char *s) volatile{
  byte bWrite[4];
  int bNum,bValue;
  int c,d,base;
  int cv, callBack, callBackSub;

  if(sscanf(s,"%d %d %d %d %d",&cv,&bNum,&bValue,&callBack,&callBackSub)!=5)          // cv = 1-1024
    return;    
  cv--;                              // actual CV addresses are cv-1 (0-1023)
  bValue=bValue%2;
  bNum=bNum%8;
  
  bWrite[0]=0x78+(highByte(cv)&0x03);   // any CV>1023 will become modulus(1024) due to bit-mask of 0x03
  bWrite[1]=lowByte(cv);  
  bWrite[2]=0xF0+bValue*8+bNum;

  loadPacket(0,resetPacket,2,1);
  loadPacket(0,bWrite,3,4);
  loadPacket(0,resetPacket,2,1);
  loadPacket(0,idlePacket,2,10);

  c=0;
  d=0;
  base=0;

  for(int j=0;j<ACK_BASE_COUNT;j++)
    base+=analogRead(CURRENT_MONITOR_PIN_PROG);
  base/=ACK_BASE_COUNT;
  
  bitClear(bWrite[2],4);              // change instruction code from Write Bit to Verify Bit

  loadPacket(0,resetPacket,2,3);          // NMRA recommends starting with 3 reset packets
  loadPacket(0,bWrite,3,5);               // NMRA recommends 5 verfy packets
  loadPacket(0,resetPacket,2,1);          // forces code to wait until all repeats of bRead are completed (and decoder begins to respond)
    
  for(int j=0;j<ACK_SAMPLE_COUNT;j++){
    c=(analogRead(CURRENT_MONITOR_PIN_PROG)-base)*ACK_SAMPLE_SMOOTHING+c*(1.0-ACK_SAMPLE_SMOOTHING);
    if(c>ACK_SAMPLE_THRESHOLD)
      d=1;
  }
    
  if(d==0)    // verify unsuccessful
    bValue=-1;
  
  INTERFACE.print("<r");
  INTERFACE.print(callBack);
  INTERFACE.print("|");
  INTERFACE.print(callBackSub);
  INTERFACE.print("|");
  INTERFACE.print(cv+1);
  INTERFACE.print(" ");
  INTERFACE.print(bNum);
  INTERFACE.print(" ");
  INTERFACE.print(bValue);
  INTERFACE.print(">");

} // RegisterList::writeCVBit()
예제 #15
0
void AX12::setNone () {
#if defined (__AVR_ATmega168__) || defined (__AVR_ATmega328P__)
    bitClear(UCSR0B, RXCIE0);    // deshabilita la interrupción de recepción
    bitClear(UCSR0B, RXEN0);     // deshabilila la recepción
    bitClear(UCSR0B, TXEN0);     // deshabilita la trasmisión
#elif defined (__AVR_ATmega1280__) || defined (__AVR_ATmega2560__)    
    bitClear(UCSR1B, RXCIE1);    // deshabilita la interrupción de recepción
    bitClear(UCSR1B, RXEN1);     // deshabilila la recepción
    bitClear(UCSR1B, TXEN1);     // deshabilita la trasmisión
#elif defined (__AVR_ATmega8__)
    bitClear(UCSRB, RXCIE);    // deshabilita la interrupción de recepción
    bitClear(UCSRB, RXEN);     // deshabilila la recepción
    bitClear(UCSRB, TXEN);     // deshabilita la trasmisión 
#endif    
}
예제 #16
0
파일: ax12.cpp 프로젝트: pabloxid/samsa-ii
void AX12::setRX () {
#if defined (__AVR_ATmega168__) || defined (__AVR_ATmega328P__)
    //bitClear(TIMSK0, TOIE0);   // deshabilita la interrupción del timer0 (nota: esto es sólo para entornos Arduino)
    bitClear(UCSR0B, TXEN0);   // deshabilita la trasmisión
    bitSet(UCSR0B, RXEN0);     // habilita la recepción
    bitSet(UCSR0B, RXCIE0);    // habilita la interrupción de recepción
#elif defined (__AVR_ATmega1280__) || defined (__AVR_ATmega128__) || defined (__AVR_ATmega2560__)
    //bitClear(TIMSK0, TOIE0);   // deshabilita la interrupción del timer0 (nota: esto es sólo para entornos Arduino)
    bitClear(UCSR1B, TXEN1);   // deshabilita la trasmisión
    bitSet(UCSR1B, RXEN1);     // habilita la recepción
    bitSet(UCSR1B, RXCIE1);    // habilita la interrupción de recepción
#elif defined (__AVR_ATmega8__)
    //bitClear(TIMSK0, TOIE0); // deshabilita la interrupción del timer0 (nota: esto es sólo para entornos Arduino)
    bitClear(UCSRB, TXEN);   // deshabilita la trasmisión
    bitSet(UCSRB, RXEN);     // habilita la recepción
    bitSet(UCSRB, RXCIE);    // habilita la interrupción de recepción 
#endif    
    ax_rx_Pointer = 0;         // resetea el puntero del buffer
}
예제 #17
0
void PCA9685::setNormalLogicMode()
{
  // get current mode2
  uint8_t mode2 = _read8bits(PCA9685_MODE2);

  // set inverted logic mode by setting bit 4 to 0
  bitClear(mode2, 4);

  _write8bits(PCA9685_MODE2, mode2);
}
예제 #18
0
파일: Sabre.cpp 프로젝트: djimoun/SabreCE
void Sabre::setSerialDataMode(uint8_t value)
{
	switch (value)
	{
		break;
		case LJ:						// Reg 10: Set to left justified data mode
		bitSet(sReg10, 4);
		bitClear(sReg10, 5);
		break;
		case RJ:						// Reg 10: Set to left justified data mode
		bitClear(sReg10, 4);
		bitSet(sReg10, 5);
		break;
		default:						// Reg 10: (Default) // Set to I2S data mode
		bitClear(sReg10, 4);
		bitClear(sReg10, 5);
	}
	writeSabreReg(REG10, sReg10);		// Reg 10: write setting to register
}
예제 #19
0
파일: AAaPC.cpp 프로젝트: AsserHic/aaapc
void vpSet(int pin, boolean value) {
  int reg = pin / 8;
  int pos = pin % 8;

  if (value) {
     bitSet(shiftRegister[reg], pos);
  } else {
     bitClear(shiftRegister[reg], pos);
  }
}
예제 #20
0
void ForestSerialPort::setLaser(int laserId, bool on) {
//	if(laserId>129 && laserId<140)
	//	printf("Set laser: %d %d\n", laserId, on);
	// we're 1-indexed
	laserId--;
	int whichChar = laserId / 8;
	int whichBit = laserId % 8;
	if(on) bitSet(laserBitmap[whichChar], whichBit);
	else bitClear(laserBitmap[whichChar], whichBit);
}
예제 #21
0
void Analog::debounceReset(uint16_t index)
{
    lastAnalogueValue[index] = 0;
    fsrLastAfterTouchValue[index] = 0;

    uint8_t arrayIndex = index/8;
    uint8_t fsrIndex = index - 8*arrayIndex;

    bitClear(fsrPressed[arrayIndex], fsrIndex);
}
예제 #22
0
uint8_t Stash::allocBlock () {
  for (uint8_t i = 0; i < sizeof map; ++i)
    if (map[i] != 0)
      for (uint8_t j = 0; j < 8; ++j)
        if (bitRead(map[i], j)) {
          bitClear(map[i], j);
          return (i << 3) + j;
        }
  return 0;
}
예제 #23
0
void KEYS::digitalWrite(uint32_t pin, uint8_t value) {

  
  if(value)
    bitSet(_PORT, pin);
  else
    bitClear(_PORT, pin);

  updateGPIO();
}
void process_output() {
  static uint32_t last_sbus_out = 0;
  static uint8_t flagbyte = 0;
  if ((milli_s() - last_sbus_out) >= (14 - (7 * SBUS_FAST_MODE))) {  // decide wether you have fast or slow SBUS
    last_sbus_out = milli_s();
    for (uint8_t i = 0; i < CHANNELS; i++) {
      cli();
      sbus_ch[i] = chan[i];         // read out all channel values
      sei();
    }
    /*
     * start the communication and write all channels (first convert them)
     */
    serial_write(SBUS_PORT, SBUS_STARTBYTE);
    serial_write(SBUS_PORT, sbus_ch[0]);                                                               //  chan0 8/11   
    serial_write(SBUS_PORT, ((sbus_ch[0]>>8) & 0x07) | (sbus_ch[1]<<3));                               //  chan0 3/3   chan1 5/11
    serial_write(SBUS_PORT, ((sbus_ch[1]>>5) & 0x3F) | (sbus_ch[2]<<6));                               //  chan1 6/6   chan2 2/11
    serial_write(SBUS_PORT, sbus_ch[2]>>2);                                                            //  chan2 8/9   
    serial_write(SBUS_PORT, ((sbus_ch[2]>>10) & 0x01) | (sbus_ch[3]<<1));                              //  chan2 1/1   chan3 7/11
    serial_write(SBUS_PORT, ((sbus_ch[3]>>7) & 0x0F) | (sbus_ch[4]<<4));                               //  chan3 4/4   chan4 4/11
    serial_write(SBUS_PORT, ((sbus_ch[4]>>4) & 0x7F) | (sbus_ch[5]<<7));                               //  chan4 7/7   chan5 1/11  
    serial_write(SBUS_PORT, sbus_ch[5]>>1);                                                            //  chan5 8/10   
    serial_write(SBUS_PORT, ((sbus_ch[5]>>9) & 0x03) | (sbus_ch[6]<<2));                               //  chan5 2/2   chan6 6/11
    serial_write(SBUS_PORT, ((sbus_ch[6]>>6) & 0x1F) | (sbus_ch[7]<<5));                               //  chan6 5/5   chan7 3/11
    serial_write(SBUS_PORT, sbus_ch[7]>>3);                                                            //  chan7 8/8
    serial_write(SBUS_PORT, sbus_ch[8]);                                                               //  chan8 8/11   
    serial_write(SBUS_PORT, ((sbus_ch[8]>>8) & 0x07) | (sbus_ch[9]<<3));                               //  chan8 3/3   chan9 5/11
    serial_write(SBUS_PORT, ((sbus_ch[9]>>5) & 0x3F) | (sbus_ch[10]<<6));                              //  chan9 6/6  chan10 2/11
    serial_write(SBUS_PORT, sbus_ch[10]>>2);                                                           // chan10 8/9   
    serial_write(SBUS_PORT, ((sbus_ch[10]>>10) & 0x01) | (sbus_ch[11]<<1));                            // chan10 1/1  chan11 7/11
    serial_write(SBUS_PORT, ((sbus_ch[11]>>7) & 0x0F) | (sbus_ch[12]<<4));                             // chan11 4/4  chan12 4/11
    serial_write(SBUS_PORT, ((sbus_ch[12]>>4) & 0x7F) | (sbus_ch[13]<<7));                             // chan12 7/7  chan13 1/11  
    serial_write(SBUS_PORT, sbus_ch[13]>>1);                                                           // chan13 8/10  
    serial_write(SBUS_PORT, ((sbus_ch[13]>>9) & 0x03) | (sbus_ch[14]<<2));                             // chan13 2/2  chan14 6/11
    serial_write(SBUS_PORT, ((sbus_ch[14]>>6) & 0x1F) | (sbus_ch[15]<<5));                             // chan14 5/5  chan15 3/11
    serial_write(SBUS_PORT, sbus_ch[15]>>3);                                                           // chan15 8/8
    if (sbus_ch[16] > MID_PULSE_OUT) bitSet(flagbyte,0); else bitClear(flagbyte,0);                        // chan16 digital
    if (sbus_ch[17] > MID_PULSE_OUT) bitSet(flagbyte,1); else bitClear(flagbyte,1);                        // chan17 digital
    serial_write(SBUS_PORT, flagbyte);
    serial_write(SBUS_PORT, SBUS_ENDBYTE);
    serial_activate(SBUS_PORT);             // activate serial port to finally send the data block
  }
예제 #25
0
void LedCircular::setSegment(unsigned char segment, bool led_on)
{
	if(led_on==true)
	{
		bitSet(led_c_,segment);
	}
	else
	{
		bitClear(led_c_,segment);
	}
}
예제 #26
0
/* ******************************************************************** *
 * public: jump to an item of this menu if exists
 * @param
 *		item name (uint8)
 * @return
 * ******************************************************************** */
void		LCDMenuLib::jumpToElement(uint8_t p_element)
/* ******************************************************************** */
{	
	// check if function is active
	if(function == p_element) {
		return;
	}
	Button_quit();
	function = _LCDML_NO_FUNC;	
	goRoot();		
	
	bitSet(control, _LCDML_control_disable_hidden);
	if(selectElementDirect(*rootMenu, p_element)) { //search element
		//open this element
		goEnter();
		//Button_enter();
	}
	bitClear(control, _LCDML_control_disable_hidden);
	bitClear(control, _LCDML_control_search_display);
}
예제 #27
0
파일: seq_if.c 프로젝트: ukaea/epics
/*
 * Initialize an event flag.
 */
epicsShareFunc void seq_efInit(PROG_ID sp, EF_ID ev_flag, unsigned val)
{
	assert(ev_flag > 0 && ev_flag <= sp->numEvFlags);

	epicsMutexMustLock(sp->lock);
	if (val)
		bitSet(sp->evFlags, ev_flag);
	else
		bitClear(sp->evFlags, ev_flag);
	epicsMutexUnlock(sp->lock);
}
예제 #28
0
파일: Alliance.c 프로젝트: Almamu/homeworld
/*-----------------------------------------------------------------------------
    Name        : allianceFormRequestRecievedCB
    Description : called when a request to from an alliance is recieved.
    Inputs      : alliance packet
    Outputs     : nont
    Return      : void
----------------------------------------------------------------------------*/
void allianceFormRequestRecievedCB(ChatPacket *packet)
{
    char temp[128];

    switch (packet->messageType)
    {
        case ALLIANCE_PACKET:
        {
            if (bitTest(universe.players[sigsPlayerIndex].AllianceProposals, PLAYER_MASK(packet->packetheader.frame)))
            {
                bitClear(universe.players[sigsPlayerIndex].AllianceProposals, PLAYER_MASK(packet->packetheader.frame));

                clWrapSetAlliance(ALLIANCE_FORMNEWALLIANCE, (uword)sigsPlayerIndex, (uword)packet->packetheader.frame);
            }
            else
            {
                sprintf(temp,"%s %s",playerNames[packet->packetheader.frame], strGetString(strAsksToFormAlliance));

                gcProcessGameTextMessage(temp, allianceMessageColor);
            }
        }
        break;
/*  OBSOLETE
        case ALLIANCE_NEWJOIN:
        {
            sprintf(temp, "%s %s %s %s",playerNames[packet->packetheader.frame], strGetString(strWants), playerNames[packet->message[0]], strGetString(strToJoin));
            gcProcessGameTextMessage(temp,allianceMessageColor);

            universe.players[sigsPlayerIndex].AllianceRequestToConfirm = (uword)packet->message[0];
            universe.players[sigsPlayerIndex].AllianceRequestInitiator = (uword)packet->packetheader.frame;
        }
        break;
        case ALLIANCE_GRANTED:
        {
            if (bitTest(universe.players[sigsPlayerIndex].AllianceConfirms,PLAYER_MASK(packet->packetheader.frame)))
            {
                bitClear(universe.players[sigsPlayerIndex].AllianceConfirms,PLAYER_MASK(packet->packetheader.frame));

                if (universe.players[sigsPlayerIndex].AllianceConfirms==0)
                {
                    sendAllianceRequest(PLAYER_MASK(universe.players[sigsPlayerIndex].AllianceRequestToConfirm),(uword)sigsPlayerIndex,ALLIANCE_PACKET, 0);
                    universe.players[sigsPlayerIndex].AllianceProposals=PLAYER_MASK(universe.players[sigsPlayerIndex].AllianceRequestToConfirm);
                    universe.players[sigsPlayerIndex].AllianceRequestToConfirm = -1;
                }
            }
        }
        break;
        /* //obsolete Now
        case ALLIANCE_RUTRANSFER:
            universe.players[sigsPlayerIndex].resourceUnits += packet->data;
        break;
        */
    }
}
예제 #29
0
// --------------------------------------------------------
// DS1302_write
//
// This function writes a byte to the DS1302 (clock or ram).
//
// The address could be like "0x80" or "0x81", 
// the lowest bit is cleared anyway.
//
// This function may be called as the first function, 
// also the pinMode is set.
//
void TimeDS1302::DS1302_write( int address, uint8_t data)
{
  // clear lowest bit (read bit) in address
  bitClear( address, DS1302_READBIT);   
	TimeDS1302::begin();
  // don't release the I/O-line
  TimeDS1302::_DS1302_togglewrite( address, false); 
  // don't release the I/O-line
  TimeDS1302::_DS1302_togglewrite( data, false); 
  TimeDS1302::_DS1302_stop();  
}
예제 #30
0
// write either command or data
void SpiLcd::send(uint8_t value, uint8_t mode) {
	if(mode){
		bitSet(_spiByte, LCD_SHIFT_RS);
	}
	else{
		bitClear(_spiByte, LCD_SHIFT_RS);
	}
	spiOut();
	write4bits(value>>4);
	write4bits(value);
}