//-------------------------------------------------------------- void testApp::printColor(){ if(License(YEAR,MON,DAY,HOUR,MINUTE)) { try { //for TEXT if(colorInfomationArray.size()>0) { ofstream file; file.open ("result.txt", ios::out); for (int i=0; i< colorInfomationArray.size() ; i++) { file << colorInfomationArray[i] << colorNumber[i]+1 << "/" << endl; } file.close(); bFileDone = true; } //for HTML if(colorInfomationHTML.size()>0) { ofstream file; file.open ("result.html", ios::out); file << "<html><head><title>Result</title></head><body><table border =\"1\"><tr align =\"center\"><td>Pixel</td><td>Image</td><td>X</td><td>Y</td><td>Color</td><td>Match</td></tr>" << endl; for (int i=0; i< colorInfomationHTML.size() ; i++) { file << colorInfomationHTML[i] << "<td align =\"right\">" << colorNumber[i]+1 << "</td></tr>" << endl; } file << "</td></tr></table></body></html>" << endl; file.close(); bFileDone = true; } //for HTML if(colorTable.size()>0) { ofstream file; file.open ("colorTable.html", ios::out); file << "<html><head><title>Color Table</title></head><body><table border =\"1\"><tr align =\"center\"><td>Number</td><td>Color</td><td>RGB</td></tr>" << endl; for (int i=0; i< colorTable.size() ; i++) { file << "<tr>" << endl; file << "<td align =\"right\">" << i+1 << "</td>" << endl; file << "<td bgcolor=\"#" << ofToHex(colorTable[i].r)+ofToHex(colorTable[i].g)+ofToHex(colorTable[i].b) << "\"/>" << endl; file << "<td align =\"center\">" << ofToString((int)colorTable[i].r) << "," << ofToString((int)colorTable[i].g) << "," << ofToString((int)colorTable[i].b) << "</td></tr>" << endl; } file << "</table></body></html>" << endl; file.close(); bFileDone = true; } bPushCreate = false; }catch(exception e){ } } }
// friend functions //-------------------------------------------------------------- std::ostream& operator<<(std::ostream &os, const ofxOscMessage &message) { os << message.getAddress(); for(std::size_t i = 0; i < message.getNumArgs(); ++i) { os << " "; switch(message.getArgType(i)) { case OFXOSC_TYPE_INT32: os << message.getArgAsInt32(i); break; case OFXOSC_TYPE_INT64: os << message.getArgAsInt64(i); break; case OFXOSC_TYPE_FLOAT: os << message.getArgAsFloat(i); break; case OFXOSC_TYPE_DOUBLE: os << message.getArgAsDouble(i); break; case OFXOSC_TYPE_STRING: os << message.getArgAsString(i); break; case OFXOSC_TYPE_SYMBOL: os << message.getArgAsSymbol(i); break; case OFXOSC_TYPE_CHAR: os << message.getArgAsChar(i); break; case OFXOSC_TYPE_MIDI_MESSAGE: os << ofToHex(message.getArgAsMidiMessage(i)); break; case OFXOSC_TYPE_TRUE: os << "T"; break; case OFXOSC_TYPE_FALSE: os << "F"; break; case OFXOSC_TYPE_NONE: os << "NONE"; break; case OFXOSC_TYPE_TRIGGER: os << "TRIGGER"; break; case OFXOSC_TYPE_TIMETAG: os << "TIMETAG"; break; case OFXOSC_TYPE_BLOB: os << "BLOB"; break; case OFXOSC_TYPE_RGBA_COLOR: os << ofToHex(message.getArgAsRgbaColor(i)); break; default: break; } } return os; }
void DeckLinkController::getAncillaryDataFromFrame(IDeckLinkVideoInputFrame* videoFrame, BMDTimecodeFormat timecodeFormat, string& timecodeString, string& userBitsString) { IDeckLinkTimecode* timecode = NULL; CFStringRef timecodeCFString; BMDTimecodeUserBits userBits = 0; if ((videoFrame != NULL) && (videoFrame->GetTimecode(timecodeFormat, &timecode) == S_OK)) { if (timecode->GetString(&timecodeCFString) == S_OK) { timecodeString = string(CFStringGetCStringPtr(timecodeCFString, kCFStringEncodingMacRoman)); CFRelease(timecodeCFString); } else { timecodeString = ""; } timecode->GetTimecodeUserBits(&userBits); userBitsString = "0x" + ofToHex(userBits); timecode->Release(); } else { timecodeString = ""; userBitsString = ""; } }
void MissingControl::draw() { ofPushStyle(); ofEnableAlphaBlending(); ofBackground(0); ofSetColor(255, 128); drawPerspective(); drawPlan(ofGetWidth() - 256, 0, 256); drawSection(ofGetWidth() - 256, 256, 256); vector<unsigned char>& packet = driver.getPacket(); string msg; for(int i = 0; i < packet.size(); i++) { msg += ofToString(i, 2, '0') + " 0x" + ofToHex(packet[i]) + "\n"; } MiniFont::draw(msg, 10, 10); ofPushMatrix(); ofPushStyle(); ofTranslate(10, ofGetHeight() - 10); ofScale(100, 1); ofSetColor(ofColor::fromHex(0xffee00)); ofLine(0, 0, (rawPresence ? 1 : 0), 0); ofSetColor(ofColor::fromHex(0x00abec)); ofLine(0, 2, presence.get(), 2); ofSetColor(ofColor::fromHex(0xec008c)); ofLine(0, 4, volume.get(), 4); ofPopStyle(); ofPopMatrix(); ofPopStyle(); }
//-------------------------------------------------------------- string testApp::createCsvString() { copyInterfaceDateToElement(); string tempString; tempString+="1,IP,"+ib->IP+",\n"; for(int i = 1; i< d->functionList.size();i++) //1 because of the #OFF# { tempString+=ofToString(i)+",C,"+d->functionAssignList[i-1]+","+d->functionList[i]+",\n"; } for(int i = 0; i < d->resList.size(); i++) { tempString+=ofToString(i+1)+",R,"+d->resList[i]+","+d->resData[i]+",\n"; } for(int i = 0; i < numberOfElements; i++) { tempString+=ofToString(i+1); tempString+=",B,"; tempString+=ofToString(e[i]->type); tempString+=","; for (int j = 0; j < numberOfSkins; j++) { tempString+=e[i]->oscAddress[j]; tempString+=","; } for (int j = 0; j < numberOfSkins; j++) { tempString+=ofToString(e[i]->masterFunction[j]); tempString+=","; } for (int j = 0; j < numberOfSkins; j++) { tempString+=ofToString(e[i]->toggle[j]); tempString+=","; } tempString+="\n"; } //write resolution tempString+="1,T,00,41,083,"; tempString+=ofToString(ofToHex(ib->resolution+1),6,' '); tempString+=",\n"; //write emulator tempString+="2,T,10,41,243,"+ofToString(ib->emulatorOne+5)+",\n"; tempString+="3,T,11,41,243,"+ofToString(ib->emulatorTwo+5)+",\n"; //write HDCP tempString+="4,T,00,41,233,"+ofToString(ib->hdcpOutput)+",\n"; tempString+="5,T,10,41,238,"+ofToString(ib->hdcpInputOne)+",\n"; tempString+="6,T,11,41,238,"+ofToString(ib->hdcpInputTwo)+",\n"; //write source loss tempString+="7,T,10,41,0A3,"+ofToString(ib->sourceLoss+1)+",\n"; tempString+="8,T,11,41,0A3,"+ofToString(ib->sourceLoss+1)+",\n"; return tempString; }
// get type from internal format; bool ftUtil::isFloat(GLint _internalFormat) { bool isFloat = false; switch(_internalFormat){ case GL_R32F: case GL_RG32F: case GL_RGB32F: case GL_RGBA32F: return true; break; case GL_R8: case GL_RG: case GL_RG8: case GL_RGB: case GL_RGB8: case GL_RGBA: case GL_RGBA8: return false; break; default: ofLogWarning("ftUtil") << "isFloat: " << "Internal format " << ofToHex(_internalFormat) << " not supported"; break; } }
//Main Update void ofxModbusTcpClient::update(ofEventArgs & args) { connected = weConnected; int transactionID = 0; int lengthPacket = 0; if (enabled) { if (weConnected) { if (!waitingForReply){ sendNextCommand(); } uint8_t headerReply[2000]; int totalBytes = 0; if (tcpClient.receiveRawBytes((char *)headerReply, 2000) > 0) { //Grab Header int transID = convertToWord(headerReply[0], headerReply[1]); int protocolID = convertToWord(headerReply[3], headerReply[4]); //Ignore if not last transaction ID if (transID != lastTransactionID) { ofLogError("ofxModbusTCP IP:"+ip)<<"Transaction ID Mismatch, discarding Reply. Got: "<<ofToHex(transID)<<" expected:"<<ofToHex(lastTransactionID); return; } //Ignore if not correct protocol if (headerReply[3] != 0x00 || headerReply[4] != 0x00) { ofLogError("ofxModbusTCP IP:"+ip)<<"Invalid Protocol ID, discarding reply. Got: "<<ofToHex(headerReply[3])<<" "<<ofToHex(headerReply[4]); return; } int functionCode = headerReply[7]; //Ignore if not correct last function code if (functionCode != lastFunctionCode) { ofLogError("ofxModbusTCP IP:"+ip)<<"Function Code Mismatch, discarding reply."; } int originatingID = headerReply[6]; int lengthData = convertToWord(headerReply[4], headerReply[5]); switch (functionCode) { case 1: { sendDebug("Reply Received, Setting Multiple Coils - not supported yet"); } break; case 3: { sendDebug("Reply Received, Setting Multiple Registers"); int byteCount = headerReply[8]; int currentByte = 9; for (int i=0; i<(byteCount/2); i++) { int newVal = convertToWord(headerReply[currentByte], headerReply[currentByte+1]); slaves.at(originatingID-1)->setRegister(i+1, newVal); currentByte = currentByte + 2; } } break; case 5: { sendDebug("Reply Received, Setting A Single Coul"); int address = convertToWord(headerReply[8], headerReply[9])+1; bool t; if (headerReply[10] == 0xff) {t=true;} else {t=false;} slaves.at(originatingID-1)->setCoil(address+1, t); } break; case 6: { sendDebug("Reply Received, Setting A Single Register"); int address = convertToWord(headerReply[8], headerReply[9]); slaves.at(originatingID-1)->setRegister(address+1, convertToWord(headerReply[10], headerReply[11])); } break; case 15: { sendDebug("Reply Received, Setting Multiple Coils - not supported yet"); } break; case 16: { sendDebug("Reply Received, Setting Multiple Registers - not supported yet"); } break; } waitingForReply = false; } if(!active) { active = true; PreviousActivityTime = ofGetElapsedTimeMillis(); } if(ofGetElapsedTimeMillis() > (PreviousActivityTime + 60000)) { if(active) { active = false; } } } else if (!tcpClient.isConnected()){ //if we are not connected lets try and reconnect every 5 seconds deltaTime = ofGetElapsedTimeMillis() - connectTime; if( deltaTime > 5000 ){ weConnected = tcpClient.setup(ip, port); connectTime = ofGetElapsedTimeMillis(); } } } else { if (tcpClient.isConnected()) { tcpClient.close(); } } }
void Trace2552::logError2(HRESULT hResult, const string& message, char*file, int line) { logError2(message + ": " + ofToHex(hResult), file, line); }
void testApp::setup() { string splitInput = " a,,b,c,"; splitTest(" a,,b, c , ", ","); splitTest(" a<><>b<> c <> ", "<>"); cout << "empty" << endl; cout << ofToInt("") << endl; cout << ofToFloat("") << endl; cout << ofToBool("") << endl; cout << ofToChar("") << endl; cout << endl; cout << "strings" << endl; cout << ofToString(123) << endl; cout << ofToString(123.4) << endl; cout << ofToString(123.4f) << endl; cout << ofToString(123, 5) << endl; cout << ofToString(123.4, 5) << endl; cout << ofToString(123.4f, 5) << endl; cout << endl; cout << "ints" << endl; cout << ofToInt("123.") << endl; cout << ofToInt("123.4") << endl; cout << ofToInt("123.4f") << endl; cout << ofToInt("+123.4") << endl; cout << endl; cout << "float" << endl; cout << ofToFloat("123.") << endl; cout << ofToFloat("123.4") << endl; cout << ofToFloat("123.4f") << endl; cout << ofToFloat("+123.4") << endl; cout << endl; cout << "bool" << endl; cout << ofToBool("1") << endl; cout << ofToBool("0") << endl; cout << ofToBool("true") << endl; cout << ofToBool("false") << endl; cout << ofToBool("True") << endl; cout << ofToBool("False") << endl; cout << endl; cout << "char" << endl; cout << ofToChar("a") << endl; cout << ofToChar("b") << endl; cout << ofToChar("1") << endl; cout << ofToChar("0") << endl; cout << endl; cout << "to binary" << endl; cout << ofToBinary(8) << endl; cout << ofToBinary(64) << endl; cout << ofToBinary(1024) << endl; cout << ofToBinary('a') << endl; cout << ofToBinary(8.5) << endl; cout << ofToBinary(8.f) << endl; cout << ofToBinary(8.5f) << endl; cout << ofToBinary(9.f) << endl; string strVal = "abc"; cout << ofToBinary(strVal) << endl; cout << ofToBinary("abc") << endl; cout << endl; cout << "to binary" << endl; cout << ofBinaryToInt(ofToBinary(8)) << endl; cout << ofBinaryToInt(ofToBinary(64)) << endl; cout << ofBinaryToInt(ofToBinary(1024)) << endl; cout << ofBinaryToChar(ofToBinary('a')) << endl; cout << ofBinaryToFloat(ofToBinary(8.5f)) << endl; cout << ofBinaryToFloat(ofToBinary(64.5f)) << endl; cout << ofBinaryToString(ofToBinary("abc")) << endl; cout << endl; cout << "to hex" << endl; cout << ofToHex('a') << endl; cout << ofToHex(128) << endl; cout << ofToHex(128.f) << endl; cout << ofToHex(128.) << endl; cout << ofToHex("abc") << endl; cout << ofToHex("abcd") << endl; string val = "abcdefg"; cout << ofToHex(val) << endl; cout << endl; cout << "hex to int" << endl; cout << ofHexToInt("0xff") << endl; cout << ofHexToInt("ff") << endl; cout << ofHexToInt(ofToHex(128)) << endl; cout << ofHexToFloat(ofToHex(128.5f)) << endl; cout << ofHexToChar(ofToHex('a')) << endl; cout << ofHexToString(ofToHex("abc")) << endl; cout << endl; }
void ofxPTZControl::pcPanTilt(int panPos, int tiltPos) { // pan and tilt can be set to a value between 1 and 65535 sendCommand("APC" + ofToHex(panPos) + ofToHex(tiltPos)); }
// get number of channels in texture format int ftUtil::getNumChannelsFromFormat(GLint _format) { switch(_format){ case GL_RED: return 1; case GL_RG: return 2; ; case GL_RGB: return 3; case GL_RGBA: return 4; default: ofLogWarning("ftUtil") << "getNumChannelsFromFormat: " << "flowtools does not use format " << ofToHex(_format); break; return 0; } }
// get number of channels in texture internalFormat int ftUtil::getNumChannelsFromInternalFormat(GLint _internalFormat) { switch(_internalFormat){ case GL_R8: case GL_R32F: return 1; case GL_RG: case GL_RG8: case GL_RG32F: return 2; ; case GL_RGB: case GL_RGB8: case GL_RGB32F: return 3; case GL_RGBA: case GL_RGBA8: case GL_RGBA32F: return 4; default: ofLogWarning("ftUtil") << "getNumChannelsFromInternalFormat: " << "flowtools does not use internalFormat " << ofToHex(_internalFormat); break; return 0; } }
//-------------------------------------------------------------- void testApp::ImageLoad(){ try{ ofColor color; dir.listDir(openFileResult.getPath()); imageCnt = 0; colorCnt = 0; colorArray.clear(); colorInfomationArray.clear(); colorInfomationHTML.clear(); int imgCnt = dir.size(); for (int i = 0; i < imgCnt; i++) { string tmpstr = dir[i].path(); if(dir[i].getExtension() == "jpg" || dir[i].getExtension() == "JPG" || dir[i].getExtension() == "jpeg" || dir[i].getExtension() == "JPEG" || dir[i].getExtension() == "png" || dir[i].getExtension() == "PNG" || dir[i].getExtension() == "bmp" || dir[i].getExtension() == "BMP" || dir[i].getExtension() == "gif" || dir[i].getExtension() == "GIF" || dir[i].getExtension() == "tga" || dir[i].getExtension() == "TGA") { img.loadImage(tmpstr); if(img.width == imgWidth && img.height == imgHeight) { imageCnt++; for(int i=0; i < img.width; i++) { for(int j=0; j<img.height; j++) { color = img.getColor(i,j); colorArray.push_back(color); colorCnt++; string tmp = ofToString(colorCnt) + "," + ofToString(imageCnt) + "," + ofToString(i+1) + "," + ofToString(j+1) + "," + ofToString(int(color.r)) + "," + ofToString(int(color.g)) + "," + ofToString(int(color.b)) + ","; string tmpHtml = "<tr><td align =\"right\">" + ofToString(colorCnt) + "</td>" + "<td align =\"right\">" + ofToString(imageCnt) + "</td>" + "<td align =\"right\">" + ofToString(i+1) + "</td>" + "<td align =\"right\">" + ofToString(j+1) + "</td>" + "<td bgcolor =\"#" + ofToHex(color.r) + ofToHex(color.g) + ofToHex(color.b) + "\">" + ofToString(int(color.r)) + "," + ofToString(int(color.g)) + "," + ofToString(int(color.b)) + "</td>"; colorInfomationArray.push_back(tmp); colorInfomationHTML.push_back(tmpHtml); } } } else { continue; } } } bPushLoad = false; } catch(exception e) { } bLoad = false; }