int cBoblight::send() { if (!boblight_sendrgb(m_boblight, 0, NULL)) { tell(1, "Error sendrgb boblight %s", boblight_geterror(m_boblight)); return fail; } return success; }
int cBoblight::ping() { if(m_boblight == 0) { tell(1, "boblight not initalized"); return fail; } if (!boblight_ping(m_boblight, NULL)) { tell(0, "Connecting to boblight lost: %s", boblight_geterror(m_boblight)); return fail; } return success; }
int cBoblight::open() { //init boblight m_boblight = boblight_init(); tell(1, "Successfully loaded and initalized libboblight"); if (!boblight_connect(m_boblight, cfg.host, cfg.port, 1000000) || !boblight_setpriority(m_boblight, cfg.priority)) { tell(0, "Error connecting to boblight %s", boblight_geterror(m_boblight)); close(); return fail; } tell(0, "Connected to boblight"); sendOptions(); return success; }
bool BobClient::connect(const QString &hostname, int port) { qCDebug(dcBoblight) << "Connecting to boblightd\n"; m_boblight = boblight_init(); //try to connect, if we can't then bitch to stderr and destroy boblight if (!boblight_connect(m_boblight, hostname.toLatin1().data(), port, 5000000) || !boblight_setpriority(m_boblight, 1)) { qCWarning(dcBoblight) << "Failed to connect:" << boblight_geterror(m_boblight); boblight_destroy(m_boblight); m_connected = false; return false; } qCDebug(dcBoblight) << "Connection to boblightd opened\n"; m_hostname = hostname; m_port = port; m_connected = true; return true; }
void BobClient::sync() { if(!m_connected) { qCWarning(dcBoblight) << "Not connected to boblight. Cannot sync"; return; } if(m_lastSyncTime.addMSecs(50) > QTime::currentTime()) { if(!m_resyncTimer.isActive()) { m_resyncTimer.start(); } return; } qCDebug(dcBoblight) << "syncing"; m_lastSyncTime = QTime::currentTime(); for(int i = 0; i < lightsCount(); ++i) { //load the color into int array int rgb[3]; rgb[0] = m_colors[i].red() * m_colors[i].alphaF(); rgb[1] = m_colors[i].green() * m_colors[i].alphaF(); rgb[2] = m_colors[i].blue() * m_colors[i].alphaF(); qCDebug(dcBoblight) << "set color" << rgb[0] << rgb[1] << rgb[2]; //set all lights to the color we want and send it boblight_addpixel(m_boblight, i, rgb); } if (!boblight_sendrgb(m_boblight, 1, NULL)) //some error happened, probably connection broken, so bitch and try again { qCWarning(dcBoblight) << "Boblight connection error:" << boblight_geterror(m_boblight); boblight_destroy(m_boblight); m_connected = false; connect(m_hostname, m_port); } }