bool CToonThermostat::WriteToHardware(const char *pdata, const unsigned char length) { if (m_UserName.size() == 0) return false; if (m_Password.size() == 0) return false; tRBUF *pCmd = (tRBUF *)pdata; if (pCmd->LIGHTING2.packettype != pTypeLighting2) return false; //later add RGB support, if someone can provide access int node_id = pCmd->LIGHTING2.id4; if ((node_id == 113) || (node_id == 114) || (node_id == 115)) return false; //we can not turn on/off the internal status int state = 0; int light_command = pCmd->LIGHTING2.cmnd; if (pCmd->LIGHTING2.cmnd == light2_sOn) state = 1; if (node_id == 254) return SwitchAll(state); std::string uuid; if (!GetUUIDFromIdx(node_id, uuid)) return false; return SwitchLight(uuid, state); }
bool OTGWBase::WriteToHardware(const char *pdata, const unsigned char length) { tRBUF *pSen = (tRBUF*)pdata; unsigned char packettype = pSen->ICMND.packettype; unsigned char subtype = pSen->ICMND.subtype; int svalue = 0; std::string LCmd = ""; int nodeID = 0; if (packettype == pTypeLighting2) { //light command nodeID = pSen->LIGHTING2.id4; if ((pSen->LIGHTING2.cmnd == light2_sOff) || (pSen->LIGHTING2.cmnd == light2_sGroupOff)) { LCmd = "Off"; svalue = 0; } else if ((pSen->LIGHTING2.cmnd == light2_sOn) || (pSen->LIGHTING2.cmnd == light2_sGroupOn)) { LCmd = "On"; svalue = 255; } SwitchLight(nodeID, LCmd, svalue); } return true; }
Light *CreateVoidLight() { Light *newLight; RenderState *rs; newLight = malloc( sizeof(*newLight) * 1 ); // directional light newLight->type = MG_POSITIONAL; newLight->switched = TRUE; newLight->twoside = FALSE; newLight->ambient[0] = 0.2f; newLight->ambient[1] = 0.2f; newLight->ambient[2] = 0.2f; newLight->diffuse[0] = 0.8f; newLight->diffuse[1] = 0.8f; newLight->diffuse[2] = 0.8f; newLight->specular[0] = 0.0f; newLight->specular[1] = 0.0f; newLight->specular[2] = 0.0f; newLight->position[0] = 0.0f; newLight->position[1] = 5.0f; // at "y" axis newLight->position[2] = 0.0f; newLight->position[3] = 1.0f; // positional newLight->positionEye[0] = 0.0f; newLight->positionEye[1] = 5.0f; newLight->positionEye[2] = 0.0f; newLight->positionEye[3] = 1.0f; newLight->spotDirection[0] = 0.577; // sqtr(3)/3 newLight->spotDirection[1] = 0.577; newLight->spotDirection[2] = 0.577; newLight->spotDirectionEye[0] = 0.577; // sqtr(3)/3 newLight->spotDirectionEye[1] = 0.577; newLight->spotDirectionEye[2] = 0.577; newLight->spotExponent = 10.0f; newLight->spotCutOff = 30.0f; // must be degrees newLight->att[2] = 0.0f; // GL_QUADRATIC_ATTENUATION newLight->att[1] = 0.0f; // GL_LINEAR_ATTENUATION newLight->att[0] = 1.0f; // GL_CONSTANT_ATTENUATION newLight->needsUpdate = TRUE; // Put the light into render state rs = RenderStateScene(); AddLightRS(rs, newLight); SwitchLight(newLight, 1); return newLight; }
void draw_stuff(){ SwitchLight(); glEnable(GL_DEPTH_TEST); glClearColor(0.4, 0.4, 0.4, 0); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); do_lights(); glUseProgram(selected_shader_id); if (selected_shader_id) { // if not using fixed shading GLint light_switch_loc = glGetUniformLocation( selected_shader_id, "LtSwitch"); glUniform1i(light_switch_loc, LightSwitch); } model->DrawModel((int) DrawNormal, selected_shader_id); ground->DrawModel((int) DrawNormal, selected_shader_id); skydome->DrawModel((int) DrawNormal, selected_shader_id); // printf("Using shader %d\n", selected_shader_id); }
bool OTGWBase::WriteToHardware(const char *pdata, const unsigned char length) { const tRBUF *pSen = reinterpret_cast<const tRBUF*>(pdata); unsigned char packettype = pSen->ICMND.packettype; unsigned char subtype = pSen->ICMND.subtype; if (packettype == pTypeLighting2) { std::string LCmd = ""; int nodeID = 0; int svalue = 0; //light command nodeID = pSen->LIGHTING2.id4; if ((pSen->LIGHTING2.cmnd == light2_sOff) || (pSen->LIGHTING2.cmnd == light2_sGroupOff)) { LCmd = "Off"; svalue = 0; } else if ((pSen->LIGHTING2.cmnd == light2_sOn) || (pSen->LIGHTING2.cmnd == light2_sGroupOn)) { LCmd = "On"; svalue = 255; } SwitchLight(nodeID, LCmd, svalue); } else if ((packettype == pTypeThermostat) && (subtype == sTypeThermSetpoint)) { const _tThermostat *pMeter=reinterpret_cast<const _tThermostat*>(pdata); float temp = pMeter->temp; unsigned char idx = pMeter->id4; SetSetpoint(idx, temp); } else { _log.Log(LOG_STATUS, "OTGW: Skipping writing to Hardware for type: %02X, subType: %02X", packettype, subtype); } return true; }
bool CPhilipsHue::WriteToHardware(const char *pdata, const unsigned char length) { tRBUF *pSen = (tRBUF*)pdata; unsigned char packettype = pSen->ICMND.packettype; unsigned char subtype = pSen->ICMND.subtype; int svalue = 0; std::string LCmd = ""; int nodeID = 0; if (packettype == pTypeLighting2) { //light command nodeID = pSen->LIGHTING2.id4; if ((pSen->LIGHTING2.cmnd == light2_sOff) || (pSen->LIGHTING2.cmnd == light2_sGroupOff)) { LCmd = "Off"; svalue = 0; } else if ((pSen->LIGHTING2.cmnd == light2_sOn) || (pSen->LIGHTING2.cmnd == light2_sGroupOn)) { LCmd = "On"; svalue = 255; } else { LCmd = "Set Level"; float fvalue = (255.0f / 15.0f)*float(pSen->LIGHTING2.level); if (fvalue > 255.0f) fvalue = 255.0f; svalue = round(fvalue); } SwitchLight(nodeID, LCmd, svalue); } else if (packettype == pTypeLimitlessLights) { _tLimitlessLights *pLed = (_tLimitlessLights*)pSen; nodeID = static_cast<int>(pLed->id); if (pLed->command == Limitless_LedOff) { LCmd = "Off"; svalue = 0; SwitchLight(nodeID, LCmd, svalue); return true; } else if (pLed->command == Limitless_LedOn) { LCmd = "On"; svalue = 255; SwitchLight(nodeID, LCmd, svalue); return true; } else if (pLed->command == Limitless_SetBrightnessLevel) { if (pLed->value == 0) { //Off LCmd = "Off"; svalue = 0; SwitchLight(nodeID, LCmd, svalue); } else { LCmd = "Set Level"; float fvalue = (255.0f / 100.0f)*float(pLed->value); if (fvalue > 255.0f) fvalue = 255.0f; svalue = round(fvalue); SwitchLight(nodeID, LCmd, svalue); } return true; } else if (pLed->command == Limitless_SetColorToWhite) { LCmd = "Set White"; SwitchLight(nodeID, LCmd, 0); return true; } else if (pLed->command == Limitless_SetRGBColour) { float cHue = (65535.0f / 255.0f)*float(pLed->value);//hue given was in range of 0-255 LCmd = "Set Hue"; svalue = round(cHue); SwitchLight(nodeID, LCmd, svalue); return true; } } return true; }
void ZWaveBase::WriteToHardware(const char *pdata, const unsigned char length) { unsigned char ID1=0; unsigned char ID2=0; unsigned char ID3=0; unsigned char ID4=0; const _tZWaveDevice* pDevice=NULL; tRBUF *pSen=(tRBUF*)pdata; unsigned char packettype=pSen->ICMND.packettype; unsigned char subtype=pSen->ICMND.subtype; if (packettype==pTypeLighting2) { //light command //find device int nodeID=(pSen->LIGHTING2.id2<<8)|pSen->LIGHTING2.id3; int instanceID=pSen->LIGHTING2.id4; int svalue=0; //First find dimmer pDevice=pDevice=FindDevice(nodeID,instanceID,ZDTYPE_SWITCHDIMMER); if (pDevice) { if ((pSen->LIGHTING2.cmnd==light2_sOff)||(pSen->LIGHTING2.cmnd==light2_sGroupOff)) svalue=0; else if ((pSen->LIGHTING2.cmnd==light2_sOn)||(pSen->LIGHTING2.cmnd==light2_sGroupOn)) svalue=255; else { float fvalue=(100.0f/15.0f)*float(pSen->LIGHTING2.level); if (fvalue>99.0f) fvalue=99.0f; //99 is fully on svalue=round(fvalue); } SwitchLight(nodeID,instanceID,pDevice->commandClassID,svalue); } else { //find normal pDevice=FindDevice(nodeID,instanceID,ZDTYPE_SWITCHNORMAL); if (pDevice) { if ((pSen->LIGHTING2.cmnd==light2_sOff)||(pSen->LIGHTING2.cmnd==light2_sGroupOff)) svalue=0; else svalue=255; SwitchLight(nodeID,instanceID,pDevice->commandClassID,svalue); } } } else if ((packettype==pTypeThermostat)&&(subtype==sTypeThermSetpoint)) { //Set Point _tThermostat *pMeter=(_tThermostat *)pSen; int nodeID=(pMeter->id2<<8)|pMeter->id3; int instanceID=pMeter->id4; //find normal pDevice=FindDevice(nodeID,instanceID,ZDTYPE_SENSOR_SETPOINT); if (pDevice) { SetThermostatSetPoint(nodeID,instanceID,pDevice->commandClassID,pMeter->temp); } } }
static int populate_lights(Vector *lights) { size_t i; size_t n; int s; hash *light_h; char *name, *type, *aux; Vector *v; set *S; float r, g, b, w; float rgb[3], pos4[4]; float cutoff = 30.0; float exp = 10.0; Light *l; if (!lights) return -1; n = sizeVector(lights); for(i = 0; i < n; i++) { S = CreateSet(); light_h = (hash *) atVector(lights, i); name = (char *) FindHashElement(light_h, "name"); type = (char *) FindHashElement(light_h, "type"); if (!check_light_type(type)) { fprintf(stderr, "[E] populate_lights: bad light type %s (possible values \"positional\", \"directional\", \"spotlight\")\n", type); exit(1); } if (!name) return i; if (!type) return i; InsertSetElement(S, "name"); InsertSetElement(S, "type"); l = SceneRegisterLight(name); v = (Vector *) FindHashElement(light_h, "pos"); if (v) { InsertSetElement(S, "pos"); read_xyz(v, &pos4[0], &pos4[1], &pos4[2]); pos4[3] = 1.0; if (!strcmp(type, "directional")) pos4[3] = 0.0; SetPositionLight(l, &pos4[0]); } v = (Vector *) FindHashElement(light_h, "amb"); if (v) { InsertSetElement(S, "amb"); read_xyz(v, &rgb[0], &rgb[1], &rgb[2]); SetAmbientLight(l, &rgb[0]); } v = (Vector *) FindHashElement(light_h, "dif"); if (v) { InsertSetElement(S, "dif"); read_xyz(v, &rgb[0], &rgb[1], &rgb[2]); SetDiffuseLight(l, &rgb[0]); } v = (Vector *) FindHashElement(light_h, "spec"); if (v) { InsertSetElement(S, "spec"); read_xyz(v, &rgb[0], &rgb[1], &rgb[2]); SetSpecularLight(l, &rgb[0]); } if (!strcmp(type, "spotlight")) { aux = (char *) FindHashElement(light_h, "exp"); if (aux) { InsertSetElement(S, "exp"); sscanf(aux, "%f", &exp); if (exp < 0) { fprintf(stderr, "[E] populate_lights: negative exponent\n"); exit(1); } free(aux); } aux = (char *) FindHashElement(light_h, "cutoff"); if (aux) { InsertSetElement(S, "cutoff"); sscanf(aux, "%f", &cutoff); if (exp < 0) { fprintf(stderr, "[E] populate_lights: negative cutoff\n"); exit(1); } free(aux); } rgb[0] = 0.577; rgb[1] = 0.577; rgb[2] = 0.577; v = (Vector *) FindHashElement(light_h, "spdir"); if (v) { InsertSetElement(S, "spdir"); read_xyz(v, &rgb[0], &rgb[1], &rgb[2]); } SetSpotLight(l, &rgb[0], cutoff, exp); } aux = (char *) FindHashElement(light_h, "switched"); if (aux) { InsertSetElement(S, "switched"); sscanf(aux, "%d", &s); if (!s) SwitchLight(l, 0); free(aux); } free(type); free(name); check_and_destroy("populate_lights", light_h, S); //DestroyHash(&light_h); } DestroyVector(&lights); return -1; }