void writeBit(uint8_t bit){ //Pull line low for 1uS pullLineLow(); delayUs(1); //If we want to write 1, release the line (if not will keep low) if(bit) { releaseLine(); } //Wait for 60uS and release the line delayUs(60); releaseLine(); }
uint32_t reset(){ uint32_t i; //Pull line low and wait for 480uS pullLineLow(); delayUs(480); //Release line and wait for 60uS releaseLine(); delayUs(60); //Store line value and wait until the completion of 480uS period i = readLineState(); delayUs(420); //Return the value read from the presence pulse (0=OK, 1=WRONG) return i; }
uint8_t readBit(void){ uint8_t bit = 0; //Pull line low for 1uS pullLineLow(); delayUs(1); //Release line and wait for 14uS releaseLine(); delayUs(14); //Read line value if(readLineState()){ bit=1; } //Wait for 45uS to end and return read value delayUs(45); return bit; }
void EmacsLinePtr::newLine() { releaseLine(); m_line = EMACS_NEW EmacsLine; }
void wyBitmapFontLabel::updateContentSize() { // remove all quads in all atlas wyArrayEach(m_atlasList, clearAtlas, NULL); // if null, do nothing if(!m_text) return; // break line into a vector vector<const char*>* lines = wyUtils::breakLines(m_text, m_font, m_lineWidth, m_spaceWidth, m_tabSize); // get width first because we need support text alignment vector<float>* widthList = measureWidth(lines); // get max width float maxWidth = 0; for(vector<float>::iterator iter = widthList->begin(); iter != widthList->end(); iter++) { maxWidth = MAX(maxWidth, *iter); } // line number int line = 0; // real width of final render float width = 0; // final render y position float y = 0; // prev line height float prevLineHeight = 0; // render line one by one for(vector<const char*>::iterator iter = lines->begin(); iter != lines->end(); iter++, line++) { char* p = (char*)(*iter); float x = 0; float lineOffset = 0; float charWidth, charHeight; bool firstLineChar = true; float currentLineHeight = 0; // line offset switch(m_alignment) { case LEFT: lineOffset = 0; break; case CENTER: lineOffset = (maxWidth - widthList->at(line)) / 2; break; case RIGHT: lineOffset = maxWidth - widthList->at(line); break; } // if first char of this line, add line spacing if(line > 0) { y += m_lineSpacing; if(prevLineHeight == 0) y += m_font->getEmptyLineHeight(); else y += prevLineHeight; } while(*p != 0) { // get char integer int c = 0; int b = wyUtils::getUTF8Bytes(*p); while(b-- > 0) { c <<= 8; c |= *p & 0xff; p++; } wyCharInfo* pCi = m_font->getCharInfo(c); if(pCi) { // get char size charWidth = pCi->texRect.width; charHeight = pCi->texRect.height; // if not first char of line, add left padding if(!firstLineChar) { x += pCi->left; } // choose max height as line height currentLineHeight = m_lineHeight > 0 ? m_lineHeight : MAX(currentLineHeight, charHeight + pCi->top); // get atlas wyTextureAtlas* atlas = (wyTextureAtlas*)wyArrayGet(m_atlasList, pCi->page); // get vertex corner float left = x + lineOffset; float right = left + charWidth; float top = -y - pCi->top; float bottom = top - charHeight; // build vertex wyQuad3D v; v.bl_x = left; v.bl_y = bottom; v.bl_z = 0.0f; v.br_x = right; v.br_y = bottom; v.br_z = 0.0f; v.tl_x = left; v.tl_y = top; v.tl_z = 0.0f; v.tr_x = right; v.tr_y = top; v.tr_z = 0.0f; // build texture coordinates wyQuad2D t; wyTexture2D* tex = m_font->getTexture(pCi->page); left = pCi->texRect.x / tex->getPixelWidth(); right = (pCi->texRect.x + charWidth) / tex->getPixelWidth(); top = pCi->texRect.y / tex->getPixelHeight(); bottom = (pCi->texRect.y + charHeight) / tex->getPixelHeight(); t.bl_x = left; t.bl_y = bottom; t.br_x = right; t.br_y = bottom; t.tl_x = left; t.tl_y = top; t.tr_x = right; t.tr_y = top; // add quad atlas->appendQuad(t, v); // adjust x and y x += charWidth + pCi->right; } else { // special check for space or tab if(c == ' ') { x += m_spaceWidth; } else if(c == '\t') { x += m_spaceWidth * m_tabSize; } } // we can clear line first char flag here firstLineChar = false; } // save line height prevLineHeight = currentLineHeight; // save max width width = MAX(width, x); } // add last line if(prevLineHeight != 0) { y += prevLineHeight; } // set label content size setContentSize(width, y); // adjust quad for(int i = 0; i < m_atlasList->num; i++) { wyTextureAtlas* atlas = (wyTextureAtlas*)wyArrayGet(m_atlasList, i); atlas->iterateQuad3D(adjustAtlasPosition, this); } // release for(vector<const char*>::iterator iter = lines->begin(); iter != lines->end(); iter++) { releaseLine(*iter); } WYDELETE(lines); WYDELETE(widthList); }