Exemplo n.º 1
0
void boost_meter(){ 
 while (digitalRead(buttonApin) == LOW){}
   meter_splash("Boost", "     Meter");
   LCDSerial.print(0xFE, BYTE);   
   LCDSerial.print(0x01, BYTE);
   LCDSerial.print(0xFE, BYTE);   
   LCDSerial.print(128, BYTE); 
   LCDSerial.print("Boost Meter");
 delay(1000);
   LCDSerial.print(0xFE, BYTE);   
   LCDSerial.print(0x01, BYTE);
 long reading = 0;
 while (digitalRead(buttonApin) == HIGH){
  test_all_meters();
  if (digitalRead(buttonBpin) == LOW) {
    boost_peak = 0;
  }  
  //non sensor code
  //reading = reading + 1;
  //real reading code
  //0 psi = 12 Vcount;
  reading = lookup_boost( long(analogRead(boostPin)) );
  boost_peak = max (reading, boost_peak); 
  generic_bar_display ("psi", 170, reading, boost_peak, 145);
  delay(50);    
 }
 return;
}
Exemplo n.º 2
0
/* This function sets the name of an RN-42 module
   name should be an up to 20-character value. It MUST BE TERMINATED by a 
   \r character */
uint8_t makeyMateClass::setName(char * name)
{
  if (bluetooth.available())
    bluetooth.flush();	// Get rid of any characters in the buffer, we'll need to check it fresh

  bluetooth.print("SN,");
  for (int i=0; i<20; i++)
  {
    if (name[i] != '\r')
      bluetooth.write(name[i]);
    else
      break;
  }
  bluetooth.write('\r');
  
  delay(BLUETOOTH_RESPONSE_DELAY);
  bluetoothReceive(rxBuffer);

  /* Double check the setting, output results in Serial monitor */
  bluetooth.flush();
  bluetooth.print("GN");
  bluetooth.write('\r');
  delay(BLUETOOTH_RESPONSE_DELAY);
  Serial.print("Name set to: ");
  while (bluetooth.available())
    Serial.write(bluetooth.read());

  return bluetoothCheckReceive(rxBuffer, "AOK", 3);
}
Exemplo n.º 3
0
void onMessage() {
	char op = 0;
	op = msg.readChar();
	// s - set color, f - fade to color
	if (op == 's' || op == 'f') {
		int red = msg.readInt();
		int green = msg.readInt();
		int blue = msg.readInt();
		if (op == 'f') {
			fade_to_color(red, green, blue);
		} else if (op == 's') {
			set_color(red, green, blue);
		}
		String color = "colorChange " + String(red) + " " + String(green) + " "
				+ String(blue) + "\n";
		serial.print(color);
	}
	// q - query color
	else if (op == 'q') {
		String color = "currentColor " + String(get_red()) + " " + String(
				get_green()) + " " + String(get_blue()) + "\n";
		serial.print(color);
	} else {
		serial.print("Unknown command.");
		serial.print(op);
		serial.print("\n");
	}
}
void sensor_setup(){  
  temp_sensor.begin();//initialize one wire sensor
  temp_sensor.setResolution(insideThermometer, 9);  //configure sensor parameters 
  
   
#ifdef DEBUG_SENS
  // report on finding the devices on the bus or not
  if (!temp_sensor.getAddress(insideThermometer, 0)) softdebug.println("Unable to find address for Device 0");
  else{  
    
    // report parasite power requirements
    softdebug.print("Parasite power is: "); 
    if (temp_sensor.isParasitePowerMode()) softdebug.println("ON");
    else softdebug.println("OFF");
    
    sensors_temperature(); //print temperature for debugging
    
  }
  
  //print voltage sensor value for debugging
  softdebug.print("Vin=");
  softdebug.println(sensors_vin());
  
#endif //DEBUG_SENS
}
//---------------------------------------------------------------------
void loop() 
{
  // comming from wake-up?
  //pinMode(DALLAS_SENSOR_PIN, OUTPUT);
  LaCrosse.setTxPinMode(OUTPUT);
  
  power_adc_enable();
  delay(500); // ms, needed for settling DS18B20
  
  //--- [0] Betriebsspannung auslesen  
  lngVcc          = getVcc();   // as long
  controller_VCC  = (lngVcc/1000.0);  // as float in Volt, not millivolts (sent as HUM !
  
  //--- [2] read Dallas-Sensor
  float theta = ReadSingleOneWireSensor(dallas);

  #ifdef USE_SOFT_SERIAL_FOR_DEBUG
    //--- debug-output-block
    //softSerial.print("Vcc: ");
    //softSerial.print( (float) controller_VCC, 1);
    //softSerial.print("   Vcc_read: ");
    //softSerial.print((long) lngVcc);
    //softSerial.print("   ");  
    softSerial.print("Feuchte: ");
    softSerial.print( (float) bodenfeuchte, 1);
    softSerial.print("    ");
    softSerial.print("Temp: ");
    softSerial.println( (float) theta, 1);
  #endif 
  
  //--- transfer measured values to LaCrosse-instance
  LaCrosse.bSensorId = SENSOR_ID;
  LaCrosse.t = theta;    //--- alias temperature;  
  LaCrosse.sendTemperature();
  
  LaCrosse.sleep(1);        /* 1 second, no power-reduction! */

  #ifdef USE_SEPARATE_BATTERIE_ID 
    LaCrosse.bSensorId = SENSORID_BATTERIE;
  #endif 
  
  //LaCrosse.h = bodenfeuchte/1000; //   controller_VCC;    
  //LaCrosse.sendHumidity();
  //LaCrosse.sleep(1);        /* 1 second, no power-reduction! */


  //--- preserve more power during sleep phase 
  pinMode(DALLAS_SENSOR_PIN, INPUT);  
  LaCrosse.setTxPinMode(INPUT);

  //--- switch AD-converter off
  power_adc_disable(); 

  //--- fall to deep powersave-sleep, see notes in comments and 
  Narcoleptic.delay_minutes(DEEP_SLEEP_MINUTES);

  //--- deep sleep or test?
  //delay(10000); // 10 Sec 
}
Exemplo n.º 6
0
void printInTens(int Tvar){
    if (Tvar < 10){
      LCDSerial.print("0");
      LCDSerial.print(Tvar);
    }
    else LCDSerial.print(Tvar);
    return;
}
int calcAndDoDelay(int i) {
	int delayTime = HTTP_DELAY_BETWEEN_RETRY
	;
	debugSerial2.print(F("Sleeping between retry: "));
	debugSerial2.print(delayTime * (i + 1));
	printCurTime();
	delay(delayTime * (i + 1));
	return delayTime;
}
Exemplo n.º 8
0
void SLCD::brightness(int pct) { 
	int level = (pct > 100 ? pct % 100 : pct); 
	
	float brightness = (((float)level)/100) * 29 + 128;
 	mySerial.print((char)SPECIAL_CONTROL);
 	mySerial.print((char)brightness);
	// wait for the long string to be sent 
	delay(5); 
}
Exemplo n.º 9
0
void Log_UART_SendBuf(uint8_t *Buf, uint16_t PackLen)
{
	uint16_t i;

	#if(DEBUG==1)
		mySerial.println("MCU   :");
		for(i = 0; i < PackLen; i++)
		{
		  mySerial.print(" "); mySerial.print(Buf[i],HEX);
		}
		mySerial.println("");
	#endif
}
/*ESP8266 Methods*/
void connectToWifi() {
	setTeal();
	if (wifi.joinAP(SSID, PASSWORD)) {
		wifiConnected = true;
		debugSerial2.print(F("Join AP success\r\n"));
		blinkGreen(3);
		setGreen();
	} else {
		wifiConnected = false;
		debugSerial2.print(F("Join AP failure\r\n"));
		setRed();
	}
}
Exemplo n.º 11
0
uint8_t Pro_GetFrame()
{
    if(rb_can_read(&u_ring_buff) >= 1)
    {
        if(packageFlag ==0)
        {
            rb_read(&u_ring_buff, &curValue, 1);
           
            if((lastValue == 0xFF)&&(curValue == 0xFF))
            {
                tmp_buf[0] = 0xFF;
                tmp_buf[1] = 0xFF;
                count = 2;
                return 1;
            }
            if((lastValue == 0xFF)&&(curValue == 0x55))
            {
                lastValue = curValue;
                return 1;
            }
            tmp_buf[count] = curValue;
            count ++ ;
            lastValue = curValue;

            if(count ==4)
            {
                dataLen = tmp_buf[2]*256+  tmp_buf[3];
            }
            if(count ==  (dataLen + 4))
            {
                memcpy(UART_HandleStruct.Message_Buf, tmp_buf, dataLen + 4);
                UART_HandleStruct.Message_Len = dataLen + 4;
                
#ifdef PROTOCOL_DEBUG
                mySerial.print(F("[")); mySerial.print(SystemTimeCount, DEC); mySerial.print(F("]")); mySerial.print(F(" GAgentToMCU:")); 
                for(uint8_t i = 0; i < dataLen + 4; i++) 
                {
                    mySerial.print(" "); mySerial.print(tmp_buf[i], HEX); 
                }
                mySerial.println(""); 
#endif
				memset(tmp_buf, 0, (dataLen + 4));
                packageFlag = 1;
                lastValue = curValue =0;
                return 0;
            }
        }
    }
	return 1;

}
String checkAndReleaseConnection() {
	debugSerial2.print(F("Current Status: "));
	String status = wifi.getIPStatus();
	debugSerial2.println(status);
	if (status.indexOf("STATUS:3") != -1) {
		if (wifi.releaseTCP()) {
			debugSerial2.print(F("release tcp ok\r\n"));
		} else {
			debugSerial2.print(F("release tcp err\r\n"));
		}
	} else {
		debugSerial2.println(F("no connection to release"));
	}
	return status;
}
Exemplo n.º 13
0
void MqttsClientApplication::runLoop(){

    while(true){
        int rc = execMsgRequest();
        if ((rc != MQTTS_ERR_NO_ERROR || getMsgRequestCount() != 0) &&
                getMsgRequestStatus() != MQTTS_MSG_REQUEST){
                clearMsgRequest();
                #ifdef DEBUG_MQTTS
                debug.print(" ErrCode=");
                debug.println(rc,DEC);
                #endif
        }
        blinkIndicator(1);

        // interrupt Event
       if (MQ_intStat == INT0_LL){
           MQ_intStat = INT0_WAIT_HL;
           interruptHandler();
           setInterrupt();
       }

       // WDT event
       if (_sleepMode == MQ_MODE_NOSLEEP){
           if (MQ_wdtStat == INT_WDT){
               _wdTimer.wakeUp();
               _wdTimer.start();
           }
       }else{
           sleepXB();
           sleepApp();
           wakeupXB();
       }
    }
}
Exemplo n.º 14
0
void loop() // run over and over
{
  int i = 0;
  bool found = false;

  raw_packet com;

  while(usb.available()){
    found = true;
    if(i < 8){
      com.raw[i] = usb.read();
    } else{
      break;
    }
    i++;
  }

  if(!found){
    return;
  }

  packet curpacket = com.nice;

  if(curpacket.cmd = 1){
    usb.print("hi");
    usb.print("\n");
  }

}
Exemplo n.º 15
0
String sendData(String command, const int timeout, boolean debug)
{
    String response = "";
    
    esp8266.print(command); // send the read character to the esp8266
    
    long int time = millis();
    
    while( (time+timeout) > millis())
    {
      while(esp8266.available())
      {
        
        // The esp has data so display its output to the serial window 
        char c = esp8266.read(); // read the next character.
        response+=c;
      }  
    }
    
    if(debug)
    {
      Serial.print(response);
    }
    
    return response;
}
Exemplo n.º 16
0
void setup() {

  // Init display
  mySerial.begin(9600); // set up serial port for 9600 baud
  delay(500); // wait for display to boot up
  


  // Setup DS1820 temp sensor

  sensors.begin();
  sensors.setResolution(Sensor1, 11);
  sensors.setResolution(Sensor2, 11);
  sensors.setWaitForConversion(false);
  sensors.requestTemperatures();
  delayInMillis = 750 / (1 << (12 - 11)); //750 for 12bit, 400 for 11bit, 220 for 10bit, 100 for 9bit
                        // calc by   delayInMillis = 750 / (1 << (12 - resolution)); 
  lastTempRequest = millis(); 


  // Set next state i FSM
  menu_FSM = M_PAGE1;
  menu_last_state = M_PAGE1;
  system_FSM = S_IDLE;
 
 
   // **************** Set up display *******************
  DisplayClear();
  MenuShowTime = millis();
 
  
  // **************** Set up RTC ***********************
  Wire.begin();
  rtc.begin();
  //TimeDate(rtc.now(),dateTimeString,1);

  //DateTime now = rtc.now();

 // write on display
  DisplayGoto(2,0);
  mySerial.print("Version 0.9B");

  
  // **************** Set up SD card *******************
  pinMode(10, OUTPUT);
  DisplayGoto(1,0);
  mySerial.write("Init SD -> "); // clear display + legends
 
  DisplayGoto(1,11);
  // see if the card is present and can be initialized:
  if (!SD.begin())
    mySerial.write("Fail");
  else
    mySerial.write("OK");
  delay(2000);
  
  // ***************** Clear display ********************
  DisplayClear();
   
  }
Exemplo n.º 17
0
uint8_t GizWits_W2D_AckCmdHandle(void)
{
    uint16_t i;  
    Pro_HeadPartTypeDef * Wait_Ack_HeadPart = (Pro_HeadPartTypeDef *)Wait_AckStruct.Cmd_Buff; 
    Pro_HeadPartTypeDef * Recv_HeadPart = (Pro_HeadPartTypeDef *)UART_HandleStruct.Message_Buf; 
    
    //Wait_AckStruct.Flag = 1为检测ACK模式,否则不做处理
    if(Wait_AckStruct.Flag == 1) 
    {
		// #if(DEBUG==1)
			// mySerial.print(F("Wait_Ack_HeadPart->Cmd / SN: "));mySerial.print(Wait_Ack_HeadPart->Cmd,HEX);mySerial.print(F(" / "));mySerial.print(Wait_Ack_HeadPart->SN,HEX);
			// mySerial.println("");
			// mySerial.print(F("Recv_HeadPart->Cmd /SN : "));mySerial.print(Recv_HeadPart->Cmd,HEX);mySerial.print(F(" / "));mySerial.print(Recv_HeadPart->SN,HEX);
			// mySerial.println("");
		// #endif

        //符合对应ACK条件行判断操作 否则是其他cmd,直接跳过
        if((Wait_Ack_HeadPart->Cmd == (Recv_HeadPart->Cmd - 1)) && (Wait_Ack_HeadPart->SN == Recv_HeadPart->SN))
        {
            if(Wait_AckStruct.SendNum < Send_MaxNum)
            {
				// #if(DEBUG==1)
					// mySerial.print(F("Time: "));mySerial.print(SystemTimeCount - Wait_AckStruct.SendTime,DEC);mySerial.print(" ");mySerial.print(SystemTimeCount,DEC);mySerial.print(" ");mySerial.print(Wait_AckStruct.SendTime,DEC);
					// mySerial.println("");
				// #endif
				#if(DEBUG==1)
					mySerial.print(F("[Time: "));mySerial.print(SystemTimeCount - Wait_AckStruct.SendTime,DEC);mySerial.print("]");
				#endif
                if((SystemTimeCount - Wait_AckStruct.SendTime) < Send_MaxTime)
                {
                    memset(&Wait_AckStruct, 0, sizeof(Wait_AckStruct)); //Wait_AckStruct.Flag = 0;
                    return 1; //是收到了对应的ACK包
                }
                else
                {
                    memset(&Wait_AckStruct, 0, sizeof(Wait_AckStruct)); //Wait_AckStruct.Flag = 0;
                    return 3; //是收到了对应的ACK包 但超时
                }
            }
            memset(&Wait_AckStruct, 0, sizeof(Wait_AckStruct)); //Wait_AckStruct.Flag = 0;
            return 0; //放弃接收ACK 允许重新reprot
        }

    }

    return 4;//放不做接收ACK处理 
}
Exemplo n.º 18
0
void LoRaModem::prnt(char * fmt, ... ) {
        char buf[8]; // resulting string limited to 7 chars
        va_list args;
        va_start (args, fmt );
        vsnprintf(buf, 8, fmt, args);
        va_end (args);
        _LoRaSerial.print(buf);
}
Exemplo n.º 19
0
void DinoSerial::process(int cmd, char *message) {
  switch(cmd) {
    case 0:  setPins(message);            break;
    case 1:  begin(message);              break;
    case 2:  softSerial.print(message);   break;
    case 3:  softSerial.println(message); break;
    default:                              break;
  }
}
Exemplo n.º 20
0
/* This function returns a 1 if the RN-42 is already in HID mode
   The module MUST BE IN COMMAND MODE for this function to work! */
uint8_t makeyMateClass::getHIDMode(void)
{
  bluetooth.flush();
  bluetooth.print("G~");  // '~' is the RN-42's HID/SPP set command
  bluetooth.write('\r');
  delay(BLUETOOTH_RESPONSE_DELAY);
  bluetoothReceive(rxBuffer);  // receive all response chars into rxBuffer

  return bluetoothCheckReceive(rxBuffer, "6", 1);	
}
void setup(void) {


	pinMode(REDPin, OUTPUT);
	pinMode(GREENPin, OUTPUT);
	pinMode(BLUEPin, OUTPUT);

//    pinMode(figaroCOcircuit, OUTPUT);


	doRGBPOST();
	debugSerial2.begin(57600);
	debugSerial2.print(F("setup begin\r\n"));
//	setPurple();
//	wifi.begin();
//	if (wifi.kick()) {
//		blinkGreen(1);
//	} else {
//		setOrange();
//	}
//
//	debugSerial2.print(F("FW Version:"));
//	debugSerial2.println(wifi.getVersion().c_str());
//
//	if (wifi.setOprToStationSoftAP()) {
//		debugSerial2.print(F("to station + softap ok\r\n"));
//		blinkGreen(2);
//	} else {
//		debugSerial2.print(F("to station + softap err\r\n"));
//	}
//
//	connectToWifi();
//
//	if (wifi.disableMUX()) {
//		debugSerial2.print(F("single ok\r\n"));
//	} else {
//		debugSerial2.print(F("single err\r\n"));
//	}

	debugSerial2.print(F("setup end\r\n"));
	printCurTime();
}
Exemplo n.º 22
0
/* This function will attempt a connection to the stored remote address
   The first time you connect the the RN-42 HID, the master device will
   need to initiate the connection. The first time a connection is made
   the bluetooth address of the master device will be stored on the RN-42.
   If no remote address is stored, a connection will not be made. */
uint8_t makeyMateClass::connect()
{
  freshStart();  // Get the module disconnected, and out of command mode
  
  while (!enterCommandMode())
  {  // Enter command mode
    delay(BLUETOOTH_RESPONSE_DELAY);
  }
  delay(BLUETOOTH_RESPONSE_DELAY);
  bluetooth.flush();
  
  /* get the remote address and print it in the serial monitor */
  bluetooth.print("GR");  // Get the remote address
  bluetooth.write('\r');
  delay(BLUETOOTH_RESPONSE_DELAY);
  if (bluetooth.peek() == 'N')  // Might say "No remote address stored */
  {  // (bluetooth address is hex values only, so won'te start with 'N'.
    Serial.println("Can't connect. No paired device!");
    bluetooth.flush();
    bluetooth.print("---");  // exit command mode
    bluetooth.write('\r');
    return 0;  // No connect is attempted
  }
  else if (bluetooth.available() == 0)  
  { // If we can't communicate with the module at all, print error
    Serial.println("ERROR!");
    return 0;  // return error
  }
  /* otherwise print the address we're trying to connect to */
  Serial.print("Attempting to connect to: ");
  while (bluetooth.available())
    Serial.write(bluetooth.read());
    
  /* Attempt to connect */
  bluetooth.print("C");  // The connect command
  bluetooth.write('\r');
  delay(BLUETOOTH_RESPONSE_DELAY);
  while (bluetooth.available())
    Serial.write(bluetooth.read());  // Should print "TRYING"
  
  return 1;
}
Exemplo n.º 23
0
void meter_splash(char line1[], char line2[]){
   LCDSerial.print(0xFE, BYTE);   
   LCDSerial.print(0x01, BYTE); //clear
   LCDSerial.print(0xFE, BYTE);  
   LCDSerial.print(128, BYTE); //select line 1
   LCDSerial.print(line1);
   LCDSerial.print(0xFE, BYTE);   
   LCDSerial.print(192, BYTE);  //select line 2
   LCDSerial.print(line2); 
   delay(1000);                  //wait
   LCDSerial.print(0xFE, BYTE);   //clear
   LCDSerial.print(0x01, BYTE);
}
Exemplo n.º 24
0
void Register::set(int value)
{
    if (value != _value)
    {
        SoftwareSerial speakjet = SoftwareSerial(_rxPin, _txPin); 
        speakjet.begin(9600);
            
        value = (value <= max_value) ? value : max_value;
        value = (value >= min_value) ? value : min_value;
    
        speakjet.print("\\0");  
        speakjet.print(_address);    
        speakjet.print("J");  
        speakjet.print(value);  
        speakjet.print("N");    
        speakjet.print("X");
    
        _value = value;    
    }
}
Exemplo n.º 25
0
 bool S4::writeData()
 {
     bool wait = true;
     int command;
     if(S4GPS.getGPS(gps))
     {   
         sensorData += "</sensor>";
        
        
         Serial.print("<gps>");
         Serial.print(deviceName);
         Serial.print(",");  
         Serial.print(gps);
         Serial.println("</gps>");
         Serial.println(sensorData);
         
         
         microSerial.print("<gps>");
         microSerial.print(deviceName);
         microSerial.print(",");
         microSerial.print(gps);
         microSerial.println("</gps>");
         microSerial.println(sensorData);
         
         if(WiFiIsOn)
         {
             SpiSerial.print("<gps>");
             SpiSerial.print(deviceName);
             SpiSerial.print(",");  
             SpiSerial.print(gps);
             SpiSerial.println("</gps>");
             SpiSerial.println(sensorData);
             
             command = getIncommingMessage(); 
         }
         sensorData = "<sensor>";
         sensorData += deviceName;
         wait = false;
     }
     return wait;
   } 
int getTgs4161(byte tgsPin) {

	//digitalWrite(figaroCircuit, LOW); // disconect R12 of the circuit (only for tgs2442)

	currentMillis = millis();
	previousMillis = currentMillis;

	while (currentMillis - previousMillis < heatTime) { //read during heater Time

		currentMillis = millis();
		//Serial.println(currentMillis - previousMillis);

//		figaroCO2Val = getAverage(tgsPin, 32, 1000); // take average measurement here every 1ms

//		incEmc = computeVolts((computeAdc(TGS4161_350) - figaroCO2Val)) * 1000;
//		incEmc = computeVolts((figaroCO2Val)) * 1000;
		if (incEmc < 0)
			incEmc = 0;

		ppm = pow(10, ((incEmc + 158.631) / 62.877));
		debugSerial2.print("PPM RAW: ");
		debugSerial2.print(ppm);
		if (ppm > 10000)
			ppm = 10000;

		ppm = (alphaTgs * ppm_last + (1 - alphaTgs) * ppm); //smoothing
		ppm_last = ppm;

		debugSerial2.print(" RAW CO2: ");
//		debugSerial2.print(computeVolts(figaroCO2Val), 4);
		debugSerial2.print("  AEMC: ");
		debugSerial2.print(incEmc);
		debugSerial2.print("  ADC: ");
		debugSerial2.print(computeAdc(TGS4161_350));
		debugSerial2.print("  PPM: ");
		debugSerial2.println(ppm);
	}

	//digitalWrite(figaroCO2Heater, HIGH); // turn OFF heater VCC

	debugSerial2.print("Final PPM: ");
	debugSerial2.println(ppm);

	return ((int) ppm);

}
Exemplo n.º 27
0
/* This function will set the RN-42 into HID mode, from SPP mode.
   Requires a reboot to take effect! */
uint8_t makeyMateClass::setHIDMode(void)
{
  if (bluetooth.available())
    bluetooth.flush();	// Get rid of any characters in the buffer, we'll need to check it fresh

    bluetooth.print("S~,6");  // Bluetooth HID Mode
  bluetooth.write('\r');
  delay(BLUETOOTH_RESPONSE_DELAY);
  bluetoothReceive(rxBuffer);

  /* Double check the setting, output results in Serial monitor */
  bluetooth.flush();
  bluetooth.print("G~");
  bluetooth.write('\r');
  delay(BLUETOOTH_RESPONSE_DELAY);
  Serial.print("Profile set to: ");
  while (bluetooth.available())
    Serial.write(bluetooth.read());

  return bluetoothCheckReceive(rxBuffer, "AOK", 3);
}
Exemplo n.º 28
0
// **************************************************************************
// *                            Main Loop 
// **************************************************************************
void loop() 
{
  long currentTime = millis();
  if (finder.find("SCANEND")){
    scanning = false;
  }
  if(scanning){
    mySerial.print("SCAN");
  }
  if (currentTime - lastTimeSent > sendInterval && xpos < XSIZE){
    if (scanning==false){
      line_following.go_forward(50);
      delay(2000);
      line_following.all_stop();
      xpos++;
      lastTimeSent = currentTime;
      scanning = true;
      mySerial.print("SCAN");
    } 
  }
}
Exemplo n.º 29
0
void TinyServo::write(uint8_t servoNumber, float angle)
{
  uint16_t count = 900 + (1200.0f * angle / 180.0f);
  mySerial.print("count "); mySerial.println(count);
  if (count < 900) {
    count = 900;
  }
  if (count > 2100) {
    count = 2100;
  }
  servopwm[servoNumber] = count;
}
Exemplo n.º 30
0
void GizWits_DevStatusUpgrade(uint8_t * P0_Buff, uint32_t Time, uint8_t flag, uint8_t ConfigFlag)
{
	uint8_t i = 0;
	uint8_t Report_Flag = 0;
	Pro_HeadPartP0CmdTypeDef *Pro_D2W_ReportStatusStruct = (Pro_HeadPartP0CmdTypeDef *)g_DevStatus;
	
    //等待上一次主动上报后判断ACK的状态,flg = 1:放弃主动上报 flg = 0:可以主动上报
  	if( ConfigFlag == 1 || Wait_AckStruct.Flag == 1)
	{
        return; 
	}
    if(flag == 1) 
    {
        Report_Flag = 1;
        goto Report; 
    }
	
    //设备的状态的变化是由于用户触发或环境变化所产生的, 其发送的频率不能快于2秒每次
    if((2 * 1000) < (SystemTimeCount - Last_ReportTime)) 
    {
        if(memcmp(g_DevStatus + sizeof(Pro_HeadPartP0CmdTypeDef), P0_Buff, g_P0DataLen) != 0)
        {
            Report_Flag = 1;
        }
    }

    //每隔十分钟定时主动上报
    if((Time * 6 * 10) < (SystemTimeCount - Last_Report_10_Time)) 
	{
        mySerial.println("%%%%%%%%%%%%%%%10 minutes regular reporting%%%%%%%%%%%%%%%"); 
		Report_Flag = 1;
        Last_Report_10_Time = SystemTimeCount; 
	}
	
Report:
	if(Report_Flag == 1)
	{
        memcpy(g_DevStatus + sizeof(Pro_HeadPartP0CmdTypeDef), P0_Buff, g_P0DataLen);

        Pro_D2W_ReportStatusStruct->Pro_HeadPart.Len = exchangeBytes(sizeof(Pro_HeadPartP0CmdTypeDef) + 1 + g_P0DataLen - 4);
        Pro_D2W_ReportStatusStruct->Pro_HeadPart.Cmd = Pro_D2W_P0_Cmd;
        Pro_D2W_ReportStatusStruct->Pro_HeadPart.SN = SN++;
        Pro_D2W_ReportStatusStruct->Action = P0_D2W_ReportDevStatus_Action;
        g_DevStatus[sizeof(Pro_HeadPartP0CmdTypeDef) + g_P0DataLen] = CheckSum(g_DevStatus, sizeof(Pro_HeadPartP0CmdTypeDef) + g_P0DataLen + 1);
        Pro_UART_SendBuf((uint8_t *)Pro_D2W_ReportStatusStruct, sizeof(Pro_HeadPartP0CmdTypeDef) + g_P0DataLen + 1, 1);//最后一位为 4.3/4.4/4.9 的重发机制开关

        Last_ReportTime = SystemTimeCount;

#if(DEBUG==1)
		mySerial.print("[");mySerial.print(SystemTimeCount,DEC);mySerial.print("]");mySerial.print(" MCU   :");
		for(i = 0; i < (sizeof(Pro_HeadPartP0CmdTypeDef) + g_P0DataLen + 1); i++)
		{
		  mySerial.print(" "); mySerial.print(g_DevStatus[i],HEX);
		}
		mySerial.println("");
#endif

	}
	return;
}