Example #1
0
void wsMessageReceived(WebSocket& socket, const String& message) {
	Serial.printf("WebSocket message received: %s\r\n", message.c_str());

	char buf[150];
	sprintf(buf, "WebSocket message received: %s\r\n", message.c_str());
	String msgBack = String(buf);
	sendToClients(msgBack);

	parseGcode(message.c_str());
}
Example #2
0
void parseCmd(char * cmd)
{
  COMMPORT.print(">> ");
  COMMPORT.println(cmd);
  if(cmd[0]=='N'){
	cmd = strstr(cmd,"G"); // remove code index
  }
	
  if(cmd[0]=='G'){ // gcode
    parseGcode(cmd+1);
  }else if(cmd[0]=='M'){ // mcode
    parseMcode(cmd+1);    
  }
  COMMPORT.print("ok\r\n");
}
Example #3
0
void connectOk(IPAddress ip, IPAddress mask, IPAddress gateway) {
//void connectOk() {
	String ipString = WifiStation.getIP().toString();
	Serial.println("I'm CONNECTED to AP_SSID=" + wifi_sid.get(currWifiIndex) + " IP: " + ipString);
	//String ipString = ip.toString();
	Serial.println("IP: " + ipString);

	startWebServer();

	if (ipString.equals("192.168.1.115") || ipString.equals("192.168.1.110")) {
// distance sensor
		Serial.println("MODE: LEUZE Distance sensor");
		udp.listen(udpServerPort);

		Serial.begin(57600);
		deltat = 100000;
		system_uart_swap();
		delegateDemoClass.begin();
		reportTimer.initializeMs(100, reportAnalogue).start();

	} else if (ipString.equals("192.168.1.113") || ipString.equals("192.168.1.112") || ipString.equals("192.168.1.21")
			|| ipString.equals("192.168.43.154")) {    //
// 4 axis stepper driver
		Serial.setCallback(serialCallBack);
		Serial.println("MODE: 4 Axis Stepper driver");

		Serial.println("Init ended.");
		Serial.println("Type 'help' and press enter for instructions.");
		Serial.println();

		deltat = 2000;

		if (ipString.equals("192.168.1.112"))
			parseGcode("reassign x=0 y=3 e=1 z=2");
		else if (ipString.equals("192.168.1.113"))
			parseGcode("reassign x=0 y=1 e=3 z=2");

		reportTimer.initializeMs(300, reportStatus).start();
		hardwareTimer.initializeUs(deltat, StepperTimerInt);
		hardwareTimer.startOnce();
	} else if (ipString.equals("192.168.1.116")) {
		Serial.println("MODE: Encoder driver");
		pinMode(encoder0PinA, INPUT);
		digitalWrite(encoder0PinA, HIGH);       // turn on pullup resistor
		pinMode(encoder0PinB, INPUT);
		digitalWrite(encoder0PinB, HIGH);       // turn on pullup resistor

		attachInterrupt(encoder0PinA, doEncoderA, GPIO_PIN_INTR_ANYEDGE);
		attachInterrupt(encoder0PinB, doEncoderB, GPIO_PIN_INTR_ANYEDGE);

		reportTimer.initializeMs(100, reportEncoderPosition).start();
	} else if (ipString.equals("192.168.1.117")) {
		Ltc2400Spi = new SPISoft(PIN_DO, PIN_DI, PIN_CK, PIN_SS);
		Ltc2400Spi->begin();
		reportTimer.initializeMs(300, readFromLTC2400).startOnce();
	}
	else
	{
		Serial.setCallback(serialCallBack);
	}

}
Example #4
0
void serialCallBack(Stream& stream, char arrivedChar, unsigned short availableCharsCount) {

	/*
	 Serial.print("Class Delegate Demo Time = ");
	 Serial.print(micros());
	 Serial.print(" char = 0x");
	 Serial.print(String(arrivedChar, HEX)); // char hex code
	 Serial.print(" available = ");
	 Serial.println(availableCharsCount);
	 */
	int ia = (int) arrivedChar;
	if (arrivedChar == '\n') // Lets show data!
			{
		char str[availableCharsCount];
		Serial.println("<New line received>");
		int i = 0;
		while (stream.available()) {
			char cur = stream.read();
			if (((int) cur != 13) && ((int) cur != 10)) {
				str[i] = cur;
				Serial.print(cur);
			} else {
				str[i] = '\0';
			}
			i++;
		}
		Serial.println();
		//}

		/*
		 int ia = (int) arrivedChar;
		 if (ia == 13) {
		 char str[availableCharsCount];
		 for (int i = 0; i < availableCharsCount-1; i++) {
		 str[i] = stream.read();
		 Serial.printf("%c",str[i]);
		 if (str[i] == '\r' || str[i] == '\n') {
		 str[i] = '\0';
		 //break;
		 }
		 }
		 */
		Serial.printf("\nCommand: %s, length=%d %d %d\n", str, availableCharsCount, str[availableCharsCount - 2],
				str[availableCharsCount - 1]);
		if (!strcmp(str, "connect")) {
			// connect to wifi
			WifiStation.config(wifi_sid.get(currWifiIndex), wifi_pass.get(currWifiIndex));
			WifiStation.enable(true);
		} else if (!strcmp(str, "ip")) {
			Serial.printf("ip: %s mac: %s\r\n", WifiStation.getIP().toString().c_str(), WifiStation.getMAC().c_str());
		} else if (!strcmp(str, "ota")) {
			OtaUpdate();
		} else if (!strcmp(str, "restart")) {
			System.restart();
		} else if (!strcmp(str, "ls")) {
			Vector<String> files = fileList();
			Serial.printf("filecount %d\r\n", files.count());
			for (unsigned int i = 0; i < files.count(); i++) {
				Serial.println(files[i]);
			}
		} else if (!strcmp(str, "info")) {
			ShowInfo();
		} else if (!strcmp(str, "switch")) {
			Switch();
		} else if (!strcmp(str, "cat")) {
			Vector<String> files = fileList();
			if (files.count() > 0) {
				Serial.printf("dumping file %s:\r\n", files[2].c_str());
				Serial.println(fileGetContent(files[2]));
			} else {
				Serial.println("Empty spiffs!");
			}
		} else if (!strcmp(str, "pos")) {
			reportStatus();
		} else if (!strcmp(str, "move")) {
			Serial.println();
			nextPos[0] += 10000;
			nextPos[1] += 10000;
			nextPos[2] += 10000;
			nextPos[3] += 10000;
//procTimer.initializeUs(deltat, blink1).start(true);
		} else if (!strcmp(str, "help")) {
			Serial.println();
			Serial.println("available commands:");
			Serial.println("  help - display this message");
			Serial.println("  ip - show current ip address");
			Serial.println("  connect - connect to wifi");
			Serial.println("  restart - restart the esp8266");
			Serial.println("  switch - switch to the other rom and reboot");
			Serial.println("  ota - perform ota update, switch rom and reboot");
			Serial.println("  info - show esp8266 info");
#ifndef DISABLE_SPIFFS
			Serial.println("  ls - list files in spiffs");
			Serial.println("  cat - show first file in spiffs");
#endif
			Serial.println();
		} else {
			Serial.printf("Trying to parse as gCode: %s\n", str);
			parseGcode(str);
		}
	} else if (ia == 48) {
		Serial.println();
		stream.read();
		nextPos[0] += 100;
		nextPos[1] += 100;
		nextPos[2] += 100;
		nextPos[3] += 100;
//procTimer.initializeUs(deltat, blink1).start(true);
	} else if (ia == 49) {
		Serial.println();
		stream.read();
		nextPos[0] -= 100;
		nextPos[1] -= 100;
		nextPos[2] -= 100;
		nextPos[3] -= 100;
//procTimer.initializeUs(deltat, blink1).start(true);
	}
}