Exemplo n.º 1
0
Arquivo: main.c Projeto: bpg/RFBee
static void loop() {
	if (serial_available() > 0) {
#ifdef DEBUG
		printf("Sdat\r\n");
#endif
		sleepCounter = 1000; // reset the sleep counter
		if (serialMode == SERIALCMDMODE) {
			readSerialCmd();
		} else {
			readSerialData();
		}
	}

	if (GDO_PIN & GDO0) {
#ifdef DEBUG
		printf("Rdat\r\n");
#endif
		writeSerialData();
		sleepCounter++; // delay sleep
	}

	sleepCounter--;

	// check if we can go to sleep again, going into low power too early will result in lost data in the CCx fifo.
	if ((sleepCounter == 0)
			&& (config_get(CONFIG_RFBEE_MODE) == LOWPOWER_MODE)) {
#ifdef DEBUG
		printf("low power on\r\n");
#endif
		lowPowerOn();
#ifdef DEBUG
		printf("woke up\r\n");
#endif
	}
}
Exemplo n.º 2
0
/*
 * Stop the PWM signal of the specified PWM.
 */
void ControlBoard::stopPWM(quint8 pwm)
{
  if (!enabled) {
	qWarning("%s: Not enabled", __FUNCTION__);
	return;
  }

  QString cmd = "pwm_stop " + QString::number(pwm);
  writeSerialData(cmd);
}
Exemplo n.º 3
0
/*
 * Set the frequency of all PWMs
 */
void ControlBoard::setPWMFreq(quint32 freq)
{
  if (!enabled) {
	qWarning("%s: Not enabled", __FUNCTION__);
	return;
  }

  QString cmd = "pwm_frequency " + QString::number(freq);
  writeSerialData(cmd);
}
Exemplo n.º 4
0
/*
 * Set the duty cycle (0-10000) of the selected PWM.
 */
void ControlBoard::setPWMDuty(quint8 pwm, quint16 duty)
{
  if (!enabled) {
	qWarning("%s: Not enabled", __FUNCTION__);
	return;
  }

  if (duty > 10000) {
	qWarning("%s: Duty out of range: %d", __FUNCTION__, duty);
	return;
  }

  QString cmd = "pwm_duty " + QString::number(pwm) + " "+ QString::number(duty);
  writeSerialData(cmd);
}
Exemplo n.º 5
0
void ControlBoard::setGPIO(quint16 gpio, quint16 enable)
{
  QString cmd = "";

  // HACK: Pretending that GPIO 0 means the led
  if (gpio == 0) {
	cmd += "led ";
  }
  else {
	cmd += "gpio ";
	cmd += ('0' + gpio) + " ";
  }
  if (enable) {
	cmd += "1";
  } else {
	cmd += "0";
  }
  writeSerialData(cmd);
}
Exemplo n.º 6
0
void ControlBoard::sendPing(void)
{
  QString cmd = "ping";
  writeSerialData(cmd);
}