Esempio n. 1
0
void epa_On()
{
	GPIO_SetBits(GPIOC, GPIO_Pin_2); //вкл епа

	{
		//инициализируем порты управления аналоговыми ключами выбора канала
		GPIO_InitTypeDef port;
		GPIO_StructInit(&port);
		port.GPIO_Pin = GPIO_Pin_12;
		port.GPIO_Mode = GPIO_Mode_OUT;
		port.GPIO_OType = GPIO_OType_PP;
		port.GPIO_PuPd = GPIO_PuPd_UP;
		port.GPIO_Speed = GPIO_Speed_2MHz;
		GPIO_Init(GPIOC, &port);

		port.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_7;
		GPIO_Init(GPIOB, &port);

		RCC_AHB1PeriphClockCmd(RCC_AHB1ENR_GPIODEN, ENABLE);
		port.GPIO_Pin = GPIO_Pin_7;
		GPIO_Init(GPIOD, &port);
	}


	switchOn(100); //выключаем все ключи

	initSpi1();
	vTaskDelay(2);

	initAdc();
}
Esempio n. 2
0
void 
ViewLightGL::paintGL()
{

  Vector3 pos(Vector3::Spherical(__distance,__azimuth*GEOM_RAD,(__elevation)*GEOM_RAD));
  if(fabs(pos.x()) < GEOM_EPSILON && fabs(pos.y()) < GEOM_EPSILON && fabs(pos.z()) < GEOM_EPSILON){
    pos = Vector3(0,0,1);
  }
   glGeomLightPosition(GL_LIGHT0,pos);
  Vector3 dir(pos);
  dir *= -1;
  dir.normalize();
  glGeomLightDirection(GL_LIGHT0,dir);

  switchOn();
  if(__show){
    glPushMatrix();
	glGeomTranslate(pos);
	glGeomMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, __ambient);
    glutSolidSphere(getStep()*0.1,8,8);
    glPopMatrix();  
  }

  GEOM_GL_ERROR;
}
Esempio n. 3
0
int GM862::executeCommand(String command){
    //  Serial.println("command: '" + command + "'\nlength: " + command.length());
	// parse command and execute
	int state = -1;
    if(command.equalsIgnoreCase("reboot")){
	  switchOff();
	  delay(8000);
	  switchOn();
	  delay(16000);
	  init();
	  state = 97;
	} else if(command.equalsIgnoreCase("delete messages")){
	  deleteMessage("0");
	  state = 96;
	} else if(command.equalsIgnoreCase("help")){
	  state = 95;
	}
	for(int i=0;i<=numOfCommands;i++){
//	   Serial.println("'" + command + "' ?? '" + commands[i] + "'");
	   if(command.equalsIgnoreCase(commands[i])){
	       state = i;
	       break;
	   }
	}
    return state;
}
Esempio n. 4
0
void GM862::init() {
  delay(1000);
  getStatus();                    // identify if modem is turned on or not
  Serial.println("GM862 MC Control");
  // test to see if modem is on
  if(!isOn()){
    Serial.println("Turning on Modem ...");
    switchOn();                   // switch the modem on
    delay(4000);                        // wait for the modem to boot
  }
  Serial.println("initializing modem ...");
  char buf[BUF_LENGTH];
  requestModem("AT", 1000, true, buf);
  requestModem("AT+IPR=19200", 1000, true, buf);
  requestModem("AT+CMEE=2", 1000, true, buf);
  requestModem("AT+CNMI=2,1,2,1,0", 1000, true, buf);
  requestModem("AT+CMGF=1", 1000, true, buf);             // send text sms
  state |= STATE_INITIALIZED;
  checkNetwork();             // check the network availability
//  modem.version();                    // request modem version info
/*  while (!modem.isRegistered()) {
    delay(1000);
    modem.checkNetwork();             // check the network availability
  }*/
  Serial.println("Modem is ready");
}
int LedDevicePhilipsHue::write(const std::vector<ColorRgb> & ledValues) {
	// Save light states if not done before.
	if (!areStatesSaved()) {
		saveStates((unsigned int) ledValues.size());
		switchOn((unsigned int) ledValues.size());
	}
	// If there are less states saved than colors given, then maybe something went wrong before.
	if (lights.size() != ledValues.size()) {
		restoreStates();
		return 0;
	}
	// Iterate through colors and set light states.
	unsigned int idx = 0;
	for (const ColorRgb& color : ledValues) {
		// Get lamp.
		PhilipsHueLight& lamp = lights.at(idx);
		// Scale colors from [0, 255] to [0, 1] and convert to xy space.
		CiColor xy = lamp.rgbToCiColor(color.red / 255.0f, color.green / 255.0f, color.blue / 255.0f);
		// Write color if color has been changed.
		if (xy != lamp.color) {
			// From a color to black.
			if (switchOffOnBlack && lamp.color != lamp.black && xy == lamp.black) {
				put(getStateRoute(lamp.id), QString("{\"on\": false}"));
			}
			// From black to a color
			else if (switchOffOnBlack && lamp.color == lamp.black && xy != lamp.black) {
				// Send adjust color and brightness command in JSON format.
				// We have to set the transition time each time.
				// Send also command to switch the lamp on.
				put(getStateRoute(lamp.id),
						QString("{\"on\": true, \"xy\": [%1, %2], \"bri\": %3, \"transitiontime\": %4}").arg(xy.x).arg(
								xy.y).arg(qRound(xy.bri * 255.0f)).arg(transitiontime));
			}
			// Normal color change.
			else {
				// Send adjust color and brightness command in JSON format.
				// We have to set the transition time each time.
				put(getStateRoute(lamp.id),
						QString("{\"xy\": [%1, %2], \"bri\": %3, \"transitiontime\": %4}").arg(xy.x).arg(xy.y).arg(
								qRound(xy.bri * 255.0f)).arg(transitiontime));
			}
		}
		// Remember last color.
		lamp.color = xy;
		// Next light id.
		idx++;
	}
	timer.start();
	return 0;
}
Esempio n. 6
0
void LampWidget::setColor(QRgb rgb)
{
   switchOn();
   this->color = QColor(rgb);
   lampLabel->setStyleSheet(QString("background: %1").arg(color.name()));
}
Esempio n. 7
0
void *do_parse(gearman_job_st *job, void *context, size_t *result_size,
		gearman_return_t *ret_ptr) {

	int yv;
	char *buf;
	JSONEncoder json = JSONEncoder();
	buf = strdup((char *) gearman_job_workload(job));

	yy_scan_string(buf);

	// on EOF yylex will return 0
	while ((yv = yylex()) != 0) {

		int token = yv;
		char *value = (char*) yysval.sval;

		switch (token) {
		case LIKES:
			switchOn(LIKES);
			break;
		case HATES:
			switchOn(HATES);
			break;
		case FROM:
			switchOn(FROM);
			break;
		case MOODS:
			switchOn(MOODS);
			break;
		case INFO:
			switchOn(INFO);
			break;

		case VALUE:
			Data *data = Data::getInstance();

			switch (getState()) {
			case LIKES:
				data->likes.push_back(value);
				break;
			case HATES:
				data->hates.push_back(value);
				break;
			case INFO:
				data->info.push_back(value);
				break;
			case MOODS:
				data->moods.push_back(value);
				break;
			case FROM:
				data->from.push_back(value);
				break;

			default:
				data->vals.push_back(value); //push all the vals to a list if no identifier is present
				break;

			}
		}

	}

	char* result = strdup(json.encodeParsed());
	*result_size = strlen(result);
	*ret_ptr = GEARMAN_SUCCESS;

	Data::getInstance()->free();
	state=0;

	return result;

}
Esempio n. 8
0
void Socket::on()
{
    std::cout << id << ": On" << std::endl;
    state = 1;
    switchOn( systemCode, unitCode );
}