Lynx500SL/Laser_Test/Laser_Test.ino
2022-01-07 15:38:23 +01:00

191 lines
4.5 KiB
C++

#include <HardwareSerial.h>
HardwareSerial MySerial1(1);
HardwareSerial MySerial2(2);
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define pin1_LASERTYPE 12
#define pin2_LASERTYPE 14
#define pin_MODE 13
#define pin_RXD1 5
#define pin_TXD1 18
#define pin_RXD2 16
#define pin_TXD2 17
long now = 0;
long prev = 0;
int incomingByte = 0; // for incoming serial data
bool b_mode;
bool b_type;
int lasertype = 0; //Lasertype selected
//void Linx500SL_Watchdog();
//void Linx500SL_SendCode();
char line1_14[] = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', 0};
char line2_14[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 0};
void setup()
{
pinMode(pin1_LASERTYPE, INPUT_PULLUP);
pinMode(pin2_LASERTYPE, INPUT_PULLUP);
pinMode(pin_MODE, INPUT_PULLUP);
//init debug port
Serial.begin(9600);
if((!digitalRead(pin1_LASERTYPE)) && (!digitalRead(pin2_LASERTYPE))) {
lasertype = 1;
}
if((!digitalRead(pin1_LASERTYPE)) && (digitalRead(pin2_LASERTYPE))) {
lasertype = 2;
}
if((digitalRead(pin1_LASERTYPE)) && (!digitalRead(pin2_LASERTYPE))) {
lasertype = 3;
}
if((digitalRead(pin1_LASERTYPE)) && (digitalRead(pin2_LASERTYPE))) {
lasertype = 4;
}
//
//lasertype = 4;
//
if (lasertype == 1) {
Serial.println("Lasertype set to : Linx 500SL - baudrate 19k2");
//init serial ports
MySerial1.begin(19200, SERIAL_8N1, pin_RXD1, pin_TXD1);
MySerial2.begin(19200, SERIAL_8N1, pin_RXD1, pin_TXD2);
}
else {
Serial.println("Lasertype set to : Linx ??? - baudrate 9600");
//init serial ports
MySerial1.begin(9600, SERIAL_8N1, pin_RXD1, pin_TXD1);
MySerial2.begin(9600, SERIAL_8N1, pin_RXD1, pin_TXD2);
}
//init I2C Display
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;); // Don't proceed, loop forever
}
// Clear the buffer
display.clearDisplay();
display.setTextSize(1);
//display.setTextColor(SSD1306_WHITE);
display.setTextColor(WHITE, BLACK);
display.setCursor(10, 0);
display.println(F("RS232 Sniffer v0.3"));
delay(1000);
display.display();
display.clearDisplay();
display.setCursor(10, 0);
if (lasertype == 1) {
dsp_info("Linx 500SL", 1);
}
if (lasertype == 2) {
dsp_info("MundiScan 2000", 1);
}
if (lasertype == 3) {
dsp_info("Linx CL30 / CL60", 1);
}
if (lasertype == 4) {
dsp_info("Linx Inktjet", 1);
}
b_mode = digitalRead(pin_MODE);
if(b_mode) {
dsp_info("Sniffer Mode ", 2);
}
else{
dsp_info("Generate Code ", 2);
}
delay(2000);
}
void loop()
{
// put your main code here, to run repeatedly:
if (digitalRead(pin_MODE) != b_mode) {
b_mode = digitalRead(pin_MODE);
if (b_mode) {
Serial.println("Mode : Sniffer");
dsp_info("Sniffer Mode ", 2);
delay(1000);
}
else {
Serial.println("Mode : Generate code");
dsp_info("Generate Code ", 2);
delay(1000);
}
}
if (b_mode) {
if (MySerial1.available() > 0) {
// read the incoming byte:
incomingByte = MySerial1.read();
// say what you got:
Serial.print("P1 received: ");
Serial.println(incomingByte, DEC);
}
if (MySerial2.available() > 0) {
// read the incoming byte:
incomingByte = MySerial2.read();
// say what you got:
Serial.print("P2 received: ");
Serial.println(incomingByte, DEC);
}
}
//generating mode
else {
now = millis();
if (now - prev >= 5000) {
//Laser 500SL
if (lasertype == 1) {
dsp_info("==> Linx 500SL", 1);
SL500_generate_code();
}
//MundiScan 2000
if (lasertype == 2) {
dsp_info("==> MundiScan2000", 1);
MundiScan_generate_code();
}
//Laser Linx CL30 / CL 60
if (lasertype == 3) {
dsp_info("==> Linx CL30/CL60", 1);
CL60_generate_code();
}
//Linx Inktjet
if (lasertype == 4) {
dsp_info("==> Linx Inktjet", 1);
Inktjet_generate_code();
}
prev = now;
}
}
}