Esempio n. 1
0
void writeCommand() {

    //write command in hex is 3AA, binary is 11 1010 1010
    writeOne();
    writeOne();
    
    writeOne();
    writeZero();
    writeOne();
    writeZero();

    writeOne();
    writeZero();
    writeOne();
    writeZero();    
}
Esempio n. 2
0
void Mesh::writeBinaryVertices(FILE* file)
{
    if (vertices.size() > 0)
    {
        // Assumes that all vertices are the same size.
        // Write the number of bytes for the vertex data
        const Vertex& vertex = vertices.front();
        write((unsigned int)(vertices.size() * vertex.byteSize()), file); // (vertex count) * (vertex size)

        // for each vertex
        for (std::vector<Vertex>::const_iterator i = vertices.begin(); i != vertices.end(); ++i)
        {
            // Write this vertex
            i->writeBinary(file);
        }
    }
    else
    {
        // No vertex data
        writeZero(file);
    }

    // Write bounds
    write(&bounds.min.x, 3, file);
    write(&bounds.max.x, 3, file);
    write(&bounds.center.x, 3, file);
    write(bounds.radius, file);
}
Esempio n. 3
0
void writeWord(uint8 word){
    uint8 i;
    for(i = 0; i < 8; i++){
        if(word & 0x80)
            writeOne();
        else
            writeZero();
        word <<= 1;
    }
}
Esempio n. 4
0
void writeLED(uint8 R, uint8 G, uint8 B){    
    uint16 i;
    uint8 word = 0x3A;
    uint8 words[4];
    
    words[0] = 0x3A;
    words[1] = R;
    words[2] = G;
    words[3] = B;    
    
    for(i = 0; i < 8; i++){
        if(word & 0x80)
            writeOne();
        else
            writeZero();
        word <<= 1;
    }       
    for(i = 0; i < 8; i++){
        if(R & 0x80)
            writeOne();
        else
            writeZero();
        R <<= 1;
    }        
    for(i = 0; i < 8; i++){
        if(G & 0x80)
            writeOne();
        else
            writeZero();
        G <<= 1;
    }       
    for(i = 0; i < 8; i++){
        if(B & 0x80)
            writeOne();
        else
            writeZero();
        B <<= 1;
    }    
    waitEOS();
    waitGSLAT();
}
Esempio n. 5
0
void writeData(uint8 data) {
    uint8 i;
    
    for (i = 0; i < 8; i++) {
        if (data & 0b10000000) {
            writeOne();
        } else {
            writeZero();
        }
        data <<= 1;
    }
}
Esempio n. 6
0
void Scene::writeBinary(FILE* file)
{
    Object::writeBinary(file);
    writeBinaryObjects(_nodes, file);
    if (_cameraNode)
    {
        _cameraNode->writeBinaryXref(file);
    }
    else
    {
        writeZero(file);
    }
    write(_ambientColor, Light::COLOR_SIZE, file);
}
Esempio n. 7
0
void writeByte(bool playera, bool playerb, bool shoot, mraa::Pwm* pwm) {
	for (int i = 0; i < 15; i++) {
		writeZero(pwm);
	}
}	
Esempio n. 8
0
void writeCommTimer() {
    //first two zeroes determine the timing (tcycle) after device is powered up or after a GSLAT
    writeZero();
    writeZero();
}
// 62.5ns per instruction.
//
// 1.25us ideal per "bit" = 20 instructions per "bit"
// 1.25us (+/- 300ns => 950ns - 1.55ns)
// 800us high, 450us low = ZERO  => 13 cycles high, 7 cycles low
// 450us high, 800us low = ONE  =>  7 cycles high, 13 cycles low
//
// NOTES: BIT0 runs slightly slower than the Bits: BIT7 - BIT1 because of the
//  pointer increment and the while loop test.
//
// TIMING MEASUREMENTS:
//      tH ONE: 725ns   (nominal 800ns  +/- 150ns) OK!!! (-75ns off)
//      tL ONE: 715ns   (nominal 450ns  +/- 150ns) OK... (+265ns off)
//  period ONE: 1440ns  (nominal 1250ns +/- 600ns) OK!!! (+190ns off)
//
//     tH ZERO: 390ns   (nominal 400ns  +/- 150ns) OK!!! (-10ns off)
//     tL ZERO: 790ns   (nominal 850ns  +/- 150ns) OK!!! (-60ns off)
// period ZERO: 1180ns  (nominal 1250ns +/- 600ns) OK!!! (-70ns off)
//
//     tH LAST ONE: 725ns   (nominal 800ns  +/- 150ns) OK!!! (-75ns off)
//     tL LAST ONE: 985ns   (nominal 450ns  +/- 150ns) Uhh   (+535ns off)
// period LAST ONE: 1550ns  (nominal 1250ns +/- 600ns) ok!!! (+460ns off)
//
//     tH LAST ZERO: 460ns   (nominal 400ns  +/- 150ns) OK!!! (+60ns off)
//     tL LAST ZERO: 1100ns  (nominal 850ns  +/- 150ns) OK    (+250ns off)
// period LAST ZERO: 1560ns  (nominal 1250ns +/- 600ns) OK!!! (+310ns off)
//
//
// PSUEDO:
//  1. Turn off Interrupts!  Time critical.
//  2. 100us pause to reset the data cycle.
//  3. get end address of pixels[] (pixels + numberOfBytes)
//  4. Get pointer for each byte to be written (bit by bit).
//  5. Write each byte (bit by bit) for "numberOfBytes".
//  6. increment pointer.
//  7. All Data written. Turn on interrups back on.
//----------------------------------------------------------------------------
void show(struct WS2812B_Strip *strip)
{
  if (strip->inShow == true)
	return;

  //  1. Turn off Interrupts!  Time critical.
  // DISABLE global interrupts.  "Bit Clear Status Register"
  __bic_SR_register(GIE);
  strip->inShow = true;

  //  2. Turn output low for 50us. (800 cycles @16MHz ~= 50us).
  SERIAL_OUTPUT_PORT &= ~SERIAL_OUTPUT_PIN;
  __delay_cycles(800);

  //  3. get end address of pixels[] (pixels + numberOfBytes)
  //  4. Get pointer for each byte to be written (bit by bit).
  uint16_t  bytesLeft = strip->numberOfBytes;
  uint8_t *ptr = strip->pixels;                      // Pointer to the current byte we are writing.

  //  5. Write each byte (bit by bit) for "numberOfBytes".
  while(bytesLeft != 0)  // 2 cycles.
  {
    if (*ptr & BIT7)
      writeOne();
    else
      writeZero();

    if (*ptr & BIT6)
      writeOne();
    else
      writeZero();

    if (*ptr & BIT5)
      writeOne();
    else
      writeZero();

    if (*ptr & BIT4)
      writeOne();
    else
      writeZero();

    if (*ptr & BIT3)
      writeOne();
    else
      writeZero();

    if (*ptr & BIT2)
      writeOne();
    else
      writeZero();

    if (*ptr & BIT1)
      writeOne();
    else
      writeZero();

    if (*ptr & BIT0)
    {
      // Write last One
      SERIAL_OUTPUT_PORT |= SERIAL_OUTPUT_PIN;
      bytesLeft--;
      ptr++;
      _no_operation();
      _no_operation();
      _no_operation();
      _no_operation();

      SERIAL_OUTPUT_PORT &= ~SERIAL_OUTPUT_PIN;
    }
    else
    {
      // Write last Zero
      SERIAL_OUTPUT_PORT |= SERIAL_OUTPUT_PIN;
      bytesLeft--;
      ptr++;

      SERIAL_OUTPUT_PORT &= ~SERIAL_OUTPUT_PIN;
    }

  }


  //  7. All Data written. Turn on interrups back on.
  __bis_SR_register(GIE);    // Enable global interrupts.  "Bit Set Status Register"
  strip->inShow = false;
}