예제 #1
0
static void updateReport()
{	
	latch(CD4021BE_LATCH_PIN);
	
	currentState.buttons0 = shiftIn(CD4021BE_DATA_PIN, CD4021BE_CLOCK_PIN);
	currentState.buttons1 = shiftIn(CD4021BE_DATA_PIN, CD4021BE_CLOCK_PIN);
	currentState.buttons2 = ~PINB & 0x1f /*00011111 = PB0-PB4*/ | (currentState.buttons2 & 0xe0); /*11100000 = REL0 RER0 REL1*/
	// currentState.buttons3 = RER1 REL2 RER2 REL3 RER3 REL4 RER4
	
	uint8_t change0 = currentState.buttons0 ^ previousState.buttons0;
	uint8_t change1 = currentState.buttons1 ^ previousState.buttons1;
	uint8_t change2 = (currentState.buttons2 & 0x1f) | ( (currentState.buttons2 ^ previousState.buttons2) & 0xe0 );
	uint8_t change3 = currentState.buttons3 ^ previousState.buttons3;
	
	memcpy(&previousState, &currentState, sizeof(gamepad_report_t));
	
	for (uint8_t i = 0; i < CHANGE_BUFFER_LENGTH; i++)
	{
		changeBuffer[i].buttons0 |= change0;
		changeBuffer[i].buttons1 |= change1;
		changeBuffer[i].buttons2 |= change2;
		changeBuffer[i].buttons3 |= change3;
	}
	
	memcpy(&gamepad_report, &changeBuffer[changeBufferIndex], sizeof(gamepad_report_t));
	
	changeBuffer[changeBufferIndex].buttons0 = 0;
	changeBuffer[changeBufferIndex].buttons1 = 0;
	changeBuffer[changeBufferIndex].buttons2 = 0;
	changeBuffer[changeBufferIndex].buttons3 = 0;
	
	changeBufferIndex++;
	changeBufferIndex %= CHANGE_BUFFER_LENGTH;
}
예제 #2
0
uint16_t sensirion::getData16SHT(int _dataPin, int _clockPin)
{
  uint16_t val;
  // start with idle colock
  digitalWrite(_clockPin, LOW);
  // Get the most significant bits
  pinMode(_dataPin, INPUT);
  pinMode(_clockPin, OUTPUT);
  //val = shiftIn(_dataPin, _clockPin, 8);
  val = shiftIn(_dataPin, _clockPin, MSBFIRST );
  val *= 256;

  // Send the required ack
  digitalWrite(_dataPin, LOW);
  pinMode(_dataPin, OUTPUT);
  shtDelay(1);
  digitalWrite(_clockPin, HIGH);
  shtDelay(1);
  digitalWrite(_clockPin, LOW);
  shtDelay(1);
  pinMode(_dataPin, INPUT);

  // Get the least significant bits
  //val |= shiftIn(_dataPin, _clockPin, 8);
  val |= shiftIn(_dataPin, _clockPin, MSBFIRST);

  return val;
}
예제 #3
0
// Returns the heading [-PI;PI] with East being 0 and North -PI/2
float HM55B::getHeading(){
  startMeasurementCommand(); // necessary!!
  delay(40); // the data is 40ms later ready
  readCommand();
  x_data = shiftIn(11); // Field strength in X
  y_data = shiftIn(11); // and Y direction
  digitalWrite(EN_PIN, HIGH); // ok deselect chip
  heading = atan2(x_data, -1 * y_data);
	return heading;
}
void Ecolino_Hijacker::refresh_states()
{
   // TODO: verify no bus contention

   byte sr_buffer;

    // select U2 on ecolino_ctl_board.schem (buttons 1-3)
   digitalWrite(ARD_MUX_A0, LOW);
   digitalWrite(ARD_MUX_A1, LOW);
   
   digitalWrite(ARD_MUX_EN_NOT, LOW); // enable multiplexer on panel
   sr_buffer = shiftIn(ARD_PANEL_DIN, ARD_DIN_CLK, LSBFIRST); // correct bit order?
   user_button_states[0] = (sr_buffer & 0x08) ? BUTTON_STATE_PRESSED : BUTTON_STATE_RELEASED;
   user_button_states[1] = (sr_buffer & 0x04) ? BUTTON_STATE_PRESSED : BUTTON_STATE_RELEASED;
   user_button_states[2] = (sr_buffer & 0x02) ? BUTTON_STATE_PRESSED : BUTTON_STATE_RELEASED;
   digitalWrite(ARD_MUX_EN_NOT, HIGH); // disable multiplexer on panel
   
   
    // select U2 on ecolino_ctl_board.schem (buttons 8-11)
   digitalWrite(ARD_MUX_A0, HIGH);
   digitalWrite(ARD_MUX_A1, LOW);
   digitalWrite(ARD_MUX_EN_NOT, LOW); // enable multiplexer on panel
   sr_buffer = shiftIn(ARD_PANEL_DIN, ARD_DIN_CLK, LSBFIRST); // correct bit order?
   for (int i = 0; i < 8; i++)
      user_button_states[10 - i] = (sr_buffer & (1 << i)) ? BUTTON_STATE_PRESSED : BUTTON_STATE_RELEASED;
   digitalWrite(ARD_MUX_EN_NOT, HIGH); // disable multiplexer on panel
   
   
   // read led state from board
   // arduino is 16 Mhz ,
   // 0.2 us from selecting multiplexer to flipping multiplexer enable
   // we have ~.5 us window to catch led state enable and flip sr load pin.  This gives us 8 cycles to flip pin
   // read is 63 ns, write is 63 ns, loop overhead is? [calc says cycle is 62 ns]
   
   // best method is : wait for demux_en_not to go low.  Wait one millisecond.  The next time the a1 pin goes low, led data is valid
   //                  and we have 0.6 us to catch a single pin flip with another 0.1 to latch into the SR
   
   // for sr:  want clock low and parallel enable low to begin with.  Then clock in data.  
   bitWrite(PORTB, 3, 0); // active low ARD_DIN_LD_NOT enabled.  (Parallel load)
   while(bitRead(PORTC, 4)); // wait for demux enable.  Should put this at top of function so it's done ahead of time and delay isn't needed
   delay(1);                  // delay would be replaced by time spent reading the buttons from panel.  Able to do this because 10 ms between updates
   while (bitRead(PORTC, 2)); // wait for a1 to go low (6 cycles)
   bitWrite(PORTB, 2, 1); // latch in the data waste .1 us (2 cycles).  This is clock pin
   bitWrite(PORTB, 2, 0); // probably should put some delay before this.  This is clock pin
   sr_buffer = shiftIn(ARD_BRD_DIN, ARD_DIN_CLK, LSBFIRST); // bit order correct ?
   
   // save the state of the leds
   for (int i = 0; i < 8; i++)
      board_led_states[i] = (sr_buffer & 1 << i) ?  LED_STATE_ON : LED_STATE_OFF;
	  
   // last four are flipped state
   for (int i = 4; i < 8; i++)
      board_led_states[i] != board_led_states[i];
}
예제 #5
0
int Encoder::getEncoder()
{
  digitalWrite(_chipSelect,LOW);
  byte _incoming = shiftIn(_dataPin, _clockPin, MSBFIRST);
  _sensorValue = _incoming<<2;
  _incoming = shiftIn(_dataPin, _clockPin, MSBFIRST);
  digitalWrite(_chipSelect,HIGH);
  _incoming = _incoming >> 6;
  _sensorValue |= _incoming;
  return _sensorValue;
}
예제 #6
0
double LM95172::getTempC()
{
    double result = 0.0;
    
    pinMode(PIN_SIO, INPUT);
    byte h = shiftIn(PIN_SIO, PIN_CLK, MSBFIRST);
    byte l = shiftIn(PIN_SIO, PIN_CLK, MSBFIRST);
        
    unsigned int v = (h << 8) | l;
    
    if (currentResolution == 13) {
        if (v >= 4096) {
            result = (4096.0 - (v >> 3)) * 0.0625;
        } else {
예제 #7
0
uint8_t Adafruit_STMPE610::spiIn() {
  if (_CLK == -1) {
#if defined (SPI_HAS_TRANSACTION)
    uint8_t d = SPI.transfer(0);
    return d;
#elif defined (__AVR__)
    SPCRbackup = SPCR;
    SPCR = mySPCR;
    uint8_t d = SPI.transfer(0);
    SPCR = SPCRbackup;
    return d;
#elif defined (__arm__)
    SPI.setClockDivider(84);
    SPI.setDataMode(m_spiMode);
    uint8_t d = SPI.transfer(0);
    return d;
#elif defined(__ARDUINO_X86__)
    SPI.setClockDivider(SPI_CLOCK_DIV16);
    SPI.setDataMode(m_spiMode);
    uint8_t d = SPI.transfer(0);
    return d;
#endif
  }
  else
    return shiftIn(_MISO, _CLK, MSBFIRST);
}
예제 #8
0
uint8_t sensirion::readCRC(int _dataPin, int _clockPin )
{
	uint8_t crc;

	// Send the required ack
	digitalWrite(_dataPin, LOW);
	pinMode(_dataPin, OUTPUT);
	shtDelay(1);
	digitalWrite(_clockPin, HIGH);
	shtDelay(1);
	digitalWrite(_clockPin, LOW);
	shtDelay(1);
	pinMode(_dataPin, INPUT);

	// Get the crc value

	crc = shiftIn(_dataPin, _clockPin, MSBFIRST);

	// end comm, turn off gpio's
	pinMode(_dataPin, INPUT);
	pinMode(_clockPin, INPUT);

	return crc;
	/*
	uint8_t local_crc = crc8( (uint8_t*)&data, 2);

	if (crc != local_crc){
		Serial.println("SHT: crc error");
		Serial.print(" Got:      0x"); Serial.println(crc, HEX);
		Serial.print(" Expected: 0x"); Serial.println(local_crc, HEX);
	}
	*/
}
예제 #9
0
파일: pfatfs.cpp 프로젝트: fmilburn3/PFatFs
uint8_t PFFS::SPI_RECEIVE (void)
{
#if _SoftSPI
//	data = 0;
	digitalWrite(_MOSI, HIGH);
//	
//	if(digitalRead(_MISO)) data+=0x80;	/* bit7 */
//	digitalWrite(_SCLK, HIGH);digitalWrite(_SCLK, LOW);
//	if(digitalRead(_MISO)) data+=0x40;	/* bit6 */
//	digitalWrite(_SCLK, HIGH);digitalWrite(_SCLK, LOW);
//	if(digitalRead(_MISO)) data+=0x20;	/* bit5 */
//	digitalWrite(_SCLK, HIGH);digitalWrite(_SCLK, LOW);
//	if(digitalRead(_MISO)) data+=0x10;	/* bit4 */
//	digitalWrite(_SCLK, HIGH);digitalWrite(_SCLK, LOW);
//	if(digitalRead(_MISO)) data+=0x08;	/* bit3 */
//	digitalWrite(_SCLK, HIGH);digitalWrite(_SCLK, LOW);
//	if(digitalRead(_MISO)) data+=0x04;	/* bit2 */
//	digitalWrite(_SCLK, HIGH);digitalWrite(_SCLK, LOW);
//	if(digitalRead(_MISO)) data+=0x02;	/* bit1 */
//	digitalWrite(_SCLK, HIGH);digitalWrite(_SCLK, LOW);
//	if(digitalRead(_MISO)) data+=0x01;	/* bit0 */
//	digitalWrite(_SCLK, HIGH);digitalWrite(_SCLK, LOW);
//
//	return data;
	return shiftIn(_MISO, _SCLK, MSBFIRST);
#else
	return SPI.transfer( 0xFF );
#endif

}
예제 #10
0
String shiftin()
{
  int dataPin=str2int(rdata("dataPin ?"));
  int clockPin=str2int(rdata("clockPin ?"));
  int bitOrder=str2int(rdata("bitOrder ?"));
  return shiftIn(dataPin, clockPin, bitOrder);
}
예제 #11
0
long HX711::read() {
	// wait for the chip to become ready
	while (!is_ready()) {
		// Will do nothing on Arduino but prevent resets of ESP8266 (Watchdog Issue)
		yield();
	}

    unsigned long value = 0;
    byte data[3] = { 0 };
    byte filler = 0x00;

	// pulse the clock pin 24 times to read the data
    data[2] = shiftIn(DOUT, PD_SCK, MSBFIRST);
    data[1] = shiftIn(DOUT, PD_SCK, MSBFIRST);
    data[0] = shiftIn(DOUT, PD_SCK, MSBFIRST);

	// set the channel and the gain factor for the next reading using the clock pin
	for (unsigned int i = 0; i < GAIN; i++) {
		digitalWrite(PD_SCK, HIGH);
		digitalWrite(PD_SCK, LOW);
	}

    // Datasheet indicates the value is returned as a two's complement value
    // Flip all the bits
    data[2] = ~data[2];
    data[1] = ~data[1];
    data[0] = ~data[0];

    // Replicate the most significant bit to pad out a 32-bit signed integer
    if ( data[2] & 0x80 ) {
        filler = 0xFF;
    } else if ((0x7F == data[2]) && (0xFF == data[1]) && (0xFF == data[0])) {
        filler = 0xFF;
    } else {
        filler = 0x00;
    }

    // Construct a 32-bit signed integer
    value = ( static_cast<unsigned long>(filler) << 24
            | static_cast<unsigned long>(data[2]) << 16
            | static_cast<unsigned long>(data[1]) << 8
            | static_cast<unsigned long>(data[0]) );

    // ... and add 1
    return static_cast<long>(++value);
}
예제 #12
0
uint8_t NESpad_Buttons(NESpad *pad)
{
  strobe(pad);
  digitalWrite(pad->m_clock,LOW);
  byte ret = digitalRead(pad->m_data) 
    | (shiftIn(pad->m_data, pad->m_clock, LSBFIRST) << 1);
  return ~ret;
}
예제 #13
0
int HM55B::readCommand() {
  int result = 0;
  pinMode(DIO_PIN, OUTPUT);
  digitalWrite(EN_PIN, LOW);
  shiftOut(B1100, 3);
  result = shiftIn(3);
  return result;
}
예제 #14
0
파일: HX711.cpp 프로젝트: zfields/HX711
long HX711::read() {
    // Byte:     0        1        2        3
    // Bits:  76543210 76543210 76543210 76543210
    // Data: |--------|--------|--------|--------|
    // Bit#:  33222222 22221111 11111100 00000000
    //        10987654 32109876 54321098 76543210
    union DataBuffer {
        byte data[4];
        long value;
    } data_buffer;

    // Wait for the chip to become ready
    for (; !is_ready() ;) {
        // Will do nothing on Arduino but prevent resets of ESP8266 (Watchdog Issue)
        yield();
    }

    // Pulse the clock pin 24 times to read the data
    data_buffer.data[1] = shiftIn(DOUT, PD_SCK, MSBFIRST);
    data_buffer.data[2] = shiftIn(DOUT, PD_SCK, MSBFIRST);
    data_buffer.data[3] = shiftIn(DOUT, PD_SCK, MSBFIRST);

	// Set the channel and the gain factor for the next reading using the clock pin
	for (unsigned int i = GAIN ; 0 < i ; --i) {
		digitalWrite(PD_SCK, HIGH);
		digitalWrite(PD_SCK, LOW);
	}

    // Replicate the most significant bit to pad out a 32-bit signed integer
    if ( data_buffer.data[1] & 0x80 ) {
        data_buffer.data[0] = 0xFF;
    } else {
        data_buffer.data[0] = 0x00;
    }

    // Datasheet indicates the value is a 24-bit two's complement (signed) value
    // https://cdn.sparkfun.com/datasheets/Sensors/ForceFlex/hx711_english.pdf

    // Flip all the bits
    data_buffer.value = ~data_buffer.value;

    // ... and add 1
    return ++data_buffer.value;
}
unsigned long ShiftInController::getShiftIn()
{
	unsigned long tmp_shiftin=0;
	unsigned long val_shiftin=0;

	for (int i=0; i < 4; i++){
		tmp_shiftin = shiftIn(_data_pin, _clock_pin, LSBFIRST);
		tmp_shiftin=tmp_shiftin<<(8*i);
		val_shiftin+=tmp_shiftin;
	}
	return val_shiftin;
}
예제 #16
0
파일: wpi.c 프로젝트: alepharchives/wpi
static ERL_NIF_TERM
shift_in_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    int data_pin, clock_pin, order, value;
    if (!enif_get_int(env, argv[0], &data_pin)  ||
        !enif_get_int(env, argv[1], &clock_pin) ||
        !enif_get_int(env, argv[2], &order))
    {
        return enif_make_badarg(env);
    }
    value = shiftIn((uint8_t)data_pin, (uint8_t)clock_pin, (uint8_t)order);
    return enif_make_int(env, value);
}
예제 #17
0
파일: SHT1x.cpp 프로젝트: krhoyt/Adobe
int SHT1x::getData16SHT(int _dataPin, int _clockPin)
{
  int val;

  // Get the most significant bits
  pinMode(_dataPin, INPUT);
  pinMode(_clockPin, OUTPUT);
  val = shiftIn(_dataPin, _clockPin, 8);
  val *= 256;

  // Send the required ack
  pinMode(_dataPin, OUTPUT);
  digitalWrite(_dataPin, HIGH);
  digitalWrite(_dataPin, LOW);
  digitalWrite(_clockPin, HIGH);
  digitalWrite(_clockPin, LOW);

  // Get the least significant bits
  pinMode(_dataPin, INPUT);
  val |= shiftIn(_dataPin, _clockPin, 8);

  return val;
}
예제 #18
0
int pincodeProcessor() {
    
    static char command[50]; // 
    static short cmd_index = 0; // the index in the string to put the next received character
    static boolean dtmfProcessed = false;

    // If a DTMF tone is being detected:
    char detected = digitalRead(PIN_DTMF_DETECTED);//check if DTMF is being detected.  digitalRead: read the value for the specified digital PIN
    dtmfProcessed = (detected && dtmfProcessed);//dtmfProcess should be true if it is already true, and a DTMF tone still being detected

    if (!dtmfProcessed & detected) {//If DTMF is being detected and it hasn't been processed yet
        Serial.println("pincode inside !dtmfProcessed & detected");
	dtmfProcessed = true;
        char tone = 0;
        
	//Read which tone was detected by shifting in bits from the DTMF chip
        tone = shiftIn(PIN_DTMF_DATA, PIN_DTMF_ACK, LSBFIRST) & 0xF; //Keep only 4 lowest bits
        if(processDTMF(tone + '0') == 0){
		 Serial.println("pincode inside processDTMF");
		return 0;
		//playHappyTone();
	}else{
		return 1;
        	//playSadTone();
    }
    
    //If there is data on the serial port connected to the GSM moduel
/*    if(Serial2.available() >0){

        incoming_char = Serial2.read();
        Serial.print(incoming_char); //when one byte comes on the serial port from the GSM module, send to the PC

        if (incoming_char == '\r'){ //When we get carriage return, we know the line is finished and we can see what we got

            command[cmd_index] = '\0'; //terminate Command String
            processCommand(command);
            cmd_index = 0;//Start from the beginning
            
        }else if(cmd_index < 49){

            if(incoming_char != 10)//10 is the ascii code for line feed 
                command[cmd_index++] = incoming_char;

        }*/
    }
    return 0;
}
예제 #19
0
/*!
  @brief Read from the decoder if a tone is pressed
  @authors Yavor Paunov, Anita Blazheva.
  @return pressed key tone
 */
int readDTMF(){
  boolean dtmfProcessed = false;
  char detected = digitalRead(PIN_DTMF_DETECTED);
  dtmfProcessed = (detected && dtmfProcessed);
  if (!dtmfProcessed & detected) {
    dtmfProcessed = true;

    char tone = 0;
    tone = shiftIn(PIN_DTMF_DATA, PIN_DTMF_ACK, LSBFIRST) & 0xF;

    Serial.print("DTMF :");
    Serial.println((int)tone);
    
//    delay(1000);
    return tone;
  }
  return -1;
}
예제 #20
0
uint8_t
ShiftConnection::receive() const {
  pinMode(_mosi, INPUT);
  // TODO: ?retrieve CPHA from SPI mode and preinit _sclk?
  return shiftIn(_mosi, _sclk, _config.getBitOrder());
}
예제 #21
0
파일: PCF8574.cpp 프로젝트: bonzehan/test
void PCF8574::shiftIn(uint8_t* val) {
	shiftIn(val,1);
}
예제 #22
0
mrb_value mrb_arduino_shiftIn(mrb_state *mrb, mrb_value self){
  mrb_int dataPin, clockPin, bitOrder;
  int n = mrb_get_args(mrb, "iii", &dataPin, &clockPin, &bitOrder);
  return mrb_fixnum_value(shiftIn(dataPin, clockPin, bitOrder));
}
예제 #23
0
파일: main.cpp 프로젝트: raphendyr/yaal
void loop() {

    uint8_t value = shiftIn(clock, data);
    shiftOut(clock, data, value);

}