void CTellstick::Init() { tdInit(); tdRegisterDeviceEvent( reinterpret_cast<TDDeviceEvent>(&CTellstick::deviceEventCallback), this ); int intNumberOfDevices = tdGetNumberOfDevices(); for (int i = 0; i < intNumberOfDevices; i++) { int id = tdGetDeviceId(i); char *name = tdGetName(id); _log.Log(LOG_NORM, "Tellstick: %s method %d", name, tdMethods(id, TELLSTICK_TURNON | TELLSTICK_TURNOFF | TELLSTICK_DIM) & TELLSTICK_DIM); bool isDimmer = tdMethods(id, TELLSTICK_TURNON | TELLSTICK_TURNOFF | TELLSTICK_DIM) & TELLSTICK_DIM; AddSwitchIfNotExits(id, name, isDimmer); tdReleaseString(name); } }
bool CLimitLess::StartHardware() { Init(); if (m_RemoteSocket!=INVALID_SOCKET) { closesocket(m_RemoteSocket); m_RemoteSocket=INVALID_SOCKET; } struct hostent *he; if ((he=gethostbyname(m_szIPAddress.c_str())) == NULL) { // get the host info _log.Log(LOG_ERROR,"AppLamp: Error with IP address!..."); return false; } m_RemoteSocket = socket( AF_INET, SOCK_DGRAM, 0 ); // this call is what allows broadcast packets to be sent: int broadcast = 1; if (setsockopt(m_RemoteSocket, SOL_SOCKET, SO_BROADCAST, (const char*)&broadcast, sizeof(broadcast)) == -1) { _log.Log(LOG_ERROR,"AppLamp: Error with IP address (SO_BROADCAST)!..."); return false; } memset(&m_stRemoteDestAddr,0,sizeof(m_stRemoteDestAddr)); //m_stRemoteDestAddr.sin_family = AF_UNSPEC; //m_stRemoteDestAddr.sin_family = PF_INET; m_stRemoteDestAddr.sin_family = AF_INET; // host byte order m_stRemoteDestAddr.sin_port = htons(m_usIPPort); // short, network byte order m_stRemoteDestAddr.sin_addr = *((struct in_addr *)he->h_addr); memset(m_stRemoteDestAddr.sin_zero, '\0', sizeof m_stRemoteDestAddr.sin_zero); //Add the Default switches if (m_LEDType != sTypeLimitlessRGB) { if (!AddSwitchIfNotExits(0, "AppLamp All")) { if (!AddSwitchIfNotExits(1, "AppLamp Group1")) { if (!AddSwitchIfNotExits(2, "AppLamp Group2")) { if (!AddSwitchIfNotExits(3, "AppLamp Group3")) { AddSwitchIfNotExits(4, "AppLamp Group4"); } } } } } else { //RGB controller is a single controlled device AddSwitchIfNotExits(0, "AppLamp RGB"); } m_bIsStarted=true; sOnConnected(this); //Start worker thread m_thread = boost::shared_ptr<boost::thread>(new boost::thread(boost::bind(&CLimitLess::Do_Work, this))); _log.Log(LOG_STATUS,"AppLamp: Worker Started..."); //WriteToHardware((const char*)&RGBWOn,sizeof(RGBWOn)); //Sleep(100); //WriteToHardware((const char*)&RGBWSetColorToWhiteAll,sizeof(RGBWSetColorToWhiteAll)); //RGBWSetColor[1]=90; //WriteToHardware((const char*)&RGBWGroup1AllOn,sizeof(RGBWGroup1AllOn)); //Sleep(100); //WriteToHardware((const char*)&RGBWSetColor,sizeof(RGBWSetColor)); return (m_thread!=NULL); }