Commit a60bcd96 authored by MagoKimbra's avatar MagoKimbra

Add MFRC522

parent 3f127b2a
......@@ -111,7 +111,7 @@
* M401 - Lower z-probe if present
* M402 - Raise z-probe if present
* M404 - D[dia in mm] Enter the nominal filament width (3mm, 1.75mm) or will display nominal filament width without parameters
* M405 - Turn on Filament Sensor extrusion control. Optional D[delay in cm] to set delay in centimeters between sensor and extruder
* M405 - Turn on Filament Sensor extrusion control. Optional D[delay in cm] to set delay in centimeters between sensor and extruder
* M406 - Turn off Filament Sensor extrusion control
* M407 - Displays measured filament diameter
* M408 - Report JSON-style response
......@@ -119,8 +119,9 @@
* M428 - Set the home_offset logically based on the current_position
* M500 - stores paramters in EEPROM
* M501 - reads parameters from EEPROM (if you need reset them after you changed them temporarily).
* M502 - reverts to the default "factory settings". You still need to store them in EEPROM afterwards if you want to.
* M502 - reverts to the default "factory settings". You still need to store them in EEPROM afterwards if you want to.
* M503 - print the current settings (from memory not from EEPROM)
* M522 - Use for reader o writer tag width MFRC522. M522 T<extruder> R(read) W(write) L(print list data on tag)
* M540 - Use S[0|1] to enable or disable the stop SD card print on endstop hit (requires ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
* M595 - Set hotend AD595 offset and gain
* M600 - Pause for filament change X[pos] Y[pos] Z[relative lift] E[initial retract] L[later retract distance for removal]
......
### Version 4.2.82
* Add DONDOLO_DUAL_MOTOR for DONDOLO bowden and dual extruder
* Add reader TAG width MFRC522
### Version 4.2.81
* Fix serial protocol for Repetier Host
......
......@@ -50,6 +50,7 @@
* - Filament diameter sensor
* - Filament Runout sensor
* - Power consumption sensor
* - RFID card sensor
* ADDON FEATURES:
* - EEPROM
* - SDCARD
......@@ -1068,6 +1069,28 @@
/**************************************************************************
*********************** RIFD module card reader **************************
**************************************************************************
* *
* Support RFID module card reader width UART interface. *
* This module mount chip MFRC522 designed to communicate with *
* ISO/IEC 14443 A/MIFARE cards and transponders without additional *
* active circuitry *
* *
* New command for this system is: *
* M522 T<extruder> R<read> or W<write> *
* *
* Define if you used and Serial used. *
* *
**************************************************************************/
//#define RFID_MODULE
#define RFID_SERIAL 1
/**************************************************************************/
//===========================================================================
//============================= ADDON FEATURES ==============================
//===========================================================================
......
......@@ -3095,12 +3095,21 @@ void gcode_get_destination() {
if(code_seen(axis_codes[E_AXIS])) IDLE_OOZING_retract(false);
#endif
for (int i = 0; i < 3; i++) {
if (code_seen(axis_codes[i]))
destination[i] = code_value() + (axis_relative_modes[i] || relative_mode ? current_position[i] : -hotend_offset[i][active_extruder]);
else
destination[i] = current_position[i];
}
#if HOTENDS == 1
for (int i = 0; i < 3; i++) {
if (code_seen(axis_codes[i]))
destination[i] = code_value() + (axis_relative_modes[i] || relative_mode ? current_position[i] : 0);
else
destination[i] = current_position[i];
}
#else
for (int i = 0; i < 3; i++) {
if (code_seen(axis_codes[i]))
destination[i] = code_value() + (axis_relative_modes[i] || relative_mode ? current_position[i] : -hotend_offset[i][active_extruder]);
else
destination[i] = current_position[i];
}
#endif
if(code_seen(axis_codes[E_AXIS]))
destination[E_AXIS] = code_value() + (axis_relative_modes[E_AXIS] || relative_mode ? current_position[E_AXIS] : 0);
......@@ -6867,15 +6876,25 @@ inline void gcode_M503() {
if (code_seen('R')) {
ECHO_LM(DB, "Put RFID on tag!");
#if ENABLED(NEXTION)
rfid_setText("Put RFID on tag!");
#endif
Spool_must_read[target_extruder] = true;
}
if (code_seen('W')) {
if (Spool_ID[target_extruder] != 0) {
ECHO_LM(DB, "Put RFID on tag!");
#if ENABLED(NEXTION)
rfid_setText("Put RFID on tag!");
#endif
Spool_must_write[target_extruder] = true;
}
else
else {
ECHO_LM(ER, "You have not read this Spool!");
#if ENABLED(NEXTION)
rfid_setText("You have not read this Spool!", 64488);
#endif
}
}
if (code_seen('L')) RFID522.printInfo(target_extruder);
......
/**
* MK & MK4due 3D Printer Firmware
*
* Based on Marlin, Sprinter and grbl
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
* Copyright (C) 2013 - 2016 Alberto Cotronei @MagoKimbra
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/**
* MFRC522 Serial
* Designed for module MFRC522 width UART
*
* Copyright (C) 2016 Alberto Cotronei MagoKimbra
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "../../base.h"
#include <Arduino.h>
#ifdef RFID_MODULE
#include "MFRC522_serial.h"
uint8_t MFRC522Data[20];
/**
* Constructor.
*/
MFRC522::MFRC522() {
#if RFID_SERIAL > 0
#if RFID_SERIAL == 1
#define RFID Serial1
#elif RFID_SERIAL == 2
#define RFID Serial2
#elif RFID_SERIAL == 3
#define RFID Serial3
#endif
#else
#define RFID Serial1
#endif
}
/**
* Start Serial
*/
bool MFRC522::init() {
RFID.begin(9600);
HAL::delayMilliseconds(1000);
write(MFRC522_HEADER); // Header
write(0x02);
write(COMMAND_READ_ID);
HAL::delayMilliseconds(500);
if (available()) {
clear(); // Clear Buffer
return true;
}
else {
return false;
}
}
bool MFRC522::getID(int8_t e) {
if (communicate(0x02, COMMAND_READ_ID)) {
for (int i = 0; i < 4; i++)
RfidDataID[e].RfidPacketID[i] = MFRC522Data[i];
return true;
}
return false;
}
bool MFRC522::readBlock(int8_t e) {
int8_t Packetdata = 0;
byte sendData[8] = {
0x01, // block
MIFARE_KEYA, // key type
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF // key
};
for (uint8_t sector = BLOCK_START; sector < BLOCK_TOTAL; sector += 4) {
sendData[0] = sector;
if (communicate(
0x0A, // length
COMMAND_READ_BLOCK, // command
sendData // sendData
)) {
for (int8_t i = 0; i < 16; i++)
RfidData[e].RfidPacket[i + Packetdata] = MFRC522Data[i];
}
else {
return false;
}
Packetdata += 16;
HAL::delayMilliseconds(20);
}
return true;
}
bool MFRC522::writeBlock(int8_t e) {
int8_t Packetdata = 0;
byte sendData[24] = {
0x01, // block
MIFARE_KEYA, // key type
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
};
for (uint8_t sector = BLOCK_START; sector < BLOCK_TOTAL; sector += 4) {
sendData[0] = sector;
for (int8_t i = 0; i < 16; i++) {
sendData[i + 8] = RfidData[e].RfidPacket[i + Packetdata];
}
if (!(communicate(
0x1A, // length
COMMAND_WRITE_BLOCK, // command
sendData // sendData
))) {
return false;
}
HAL::delayMilliseconds(20);
Packetdata += 16;
}
return true;
}
/**
* Description: Comunication between MFRC522 and ISO14443.
* Command Format: Header + Lenght + Command + (Data)
* Return: Return STATUS_OK if success.
*/
bool MFRC522::communicate(uint8_t sendDataLength, uint8_t command, uint8_t* sendData) {
// Send instruction to MFRC522
write(MFRC522_HEADER); // Header
write(sendDataLength); // Length (Length + Command + Data)
write(command); // Command
if (sendData != NULL) {
for (uint8_t i = 0; i < sendDataLength - 2; i++) {
write(sendData[i]); // Data
}
}
// Read response to MFRC522
while (!available());
uint8_t header = read(); // Header
while (!available());
uint8_t returnDataLength = read(); // Length (Length + Command + Data)
while (!available());
uint8_t commandResult = read(); // Command result
for (int i = 0; i < returnDataLength - 2; i++) {
while (!available());
if (available()) {
MFRC522Data[i] = read(); // Data
}
}
// Return
if (command != commandResult) {
return STATUS_ERROR;
}
return STATUS_OK;
}
void MFRC522::printInfo(int8_t e) {
char lung[30];
ECHO_LMV(INFO, MSG_RFID_SPOOL, e);
ECHO_LMT(INFO, MSG_RFID_BRAND, RfidData[e].data.brand);
ECHO_LMT(INFO, MSG_RFID_TYPE, RfidData[e].data.type);
ECHO_LMT(INFO, MSG_RFID_COLOR, RfidData[e].data.color);
ECHO_LMV(INFO, MSG_RFID_SIZE, RfidData[e].data.size);
ECHO_SMV(INFO, MSG_RFID_TEMP_HOTEND, RfidData[e].data.temphotendmin);
ECHO_EMV(" - ", RfidData[e].data.temphotendmax);
ECHO_SMV(INFO, MSG_RFID_TEMP_BED, RfidData[e].data.tempbedmin);
ECHO_EMV(" - ", RfidData[e].data.tempbedmax);
ECHO_LMV(INFO, MSG_RFID_TEMP_USER_HOTEND, RfidData[e].data.temphotend);
ECHO_LMV(INFO, MSG_RFID_TEMP_USER_BED, RfidData[e].data.tempbed);
ECHO_SMV(INFO, MSG_RFID_DENSITY, RfidData[e].data.density); ECHO_EM("%");
unsigned int kmeter = (long)RfidData[e].data.lenght / 1000 / 1000,
meter = ((long)RfidData[e].data.lenght / 1000) % 1000,
centimeter = ((long)RfidData[e].data.lenght / 10) % 100,
millimeter = ((long)RfidData[e].data.lenght) % 10;
sprintf_P(lung, PSTR("%i Km %i m %i cm %i mm"), kmeter, meter, centimeter, millimeter);
ECHO_LMT(INFO, MSG_RFID_SPOOL_LENGHT, lung);
}
// Private
/*
* Description:Write a byte data into MFRC522.
*/
void MFRC522::write(uint8_t value) {
RFID.write(value);
}
/*
* Description:Read a byte data of MFRC522
* Return:Return the read value.
*/
byte MFRC522::read() {
return RFID.read();
}
void MFRC522::clear() {
while (available()) RFID.read();
}
/*
* Description:Returns true if detect card in MFRC522.
*/
bool MFRC522::available() {
return (RFID.available() > 0);
}
#endif // ENABLED(RFID_MODULE)
/**
* MK & MK4due 3D Printer Firmware
*
* Based on Marlin, Sprinter and grbl
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
* Copyright (C) 2013 - 2016 Alberto Cotronei @MagoKimbra
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/**
* MFRC522 Serial
* Designed for module MFRC522 width UART
*
* Copyright (C) 2016 Alberto Cotronei MagoKimbra
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MFRC522_H
#define MFRC522_H
//------------------MFRC522 register ---------------
#define MFRC522_HEADER 0xAB
#define COMMAND_READ_ID 0x02
#define COMMAND_READ_BLOCK 0x03
#define COMMAND_WRITE_BLOCK 0x04
#define STATUS_ERROR 0
#define STATUS_OK 1
#define MIFARE_KEYA 0x00
#define MIFARE_KEYB 0x01
#define BLOCK_START 5
#define BLOCK_TOTAL 26 // block total = block used + 1
class MFRC522 {
public:
MFRC522();
bool init();
bool getID(int8_t e);
bool readBlock(int8_t e);
bool writeBlock(int8_t e);
void printInfo(int8_t e);
typedef struct {
char brand[16]; // 16 byte Block 5
char serialnumber[16]; // 16 byte Block 9
char type[8]; // 8 byte Block 13
char color[8]; // 8 byte Block 13
char free1[12]; // 12 byte Block 17
float size; // 4 byte Block 17
int temphotendmin; // 4 byte Block 21
int temphotendmax; // 4 byte Block 21
int tempbedmin; // 4 byte Block 21
int tempbedmax; // 4 byte Block 21
int temphotend; // 4 byte Block 25
int tempbed; // 4 byte Block 25
int density; // 4 byte Block 25
unsigned long lenght; // 4 byte Block 25
} data_t;
typedef union {
data_t data;
byte RfidPacket[sizeof(data_t)];
} RfidPacket_t;
typedef union {
unsigned long Spool_ID;
byte RfidPacketID[4];
} RfidPacketID_t;
RfidPacket_t RfidData[EXTRUDERS];
RfidPacketID_t RfidDataID[EXTRUDERS];
private:
void write(uint8_t value);
byte read();
bool communicate(uint8_t sendDataLength, uint8_t command, uint8_t *sendData = NULL);
void clear();
bool available();
};
#endif // MFRC522_H
......@@ -35,5 +35,6 @@
//#include "NexWaveform.h"
#include "NexTimer.h"
#include "NexVar.h"
#include "NexDualStateButton.h"
#endif /* #ifndef __NEXTION_H__ */
......@@ -12,11 +12,11 @@
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
......@@ -104,6 +104,7 @@
NexVar RFID = NexVar(1, 27, "rfid");
NexPicture Speedpic = NexPicture(1, 28, "p9");
NexVar VSpeed = NexVar(1, 29, "vspeed");
NexVar Extruder = NexVar(1, 30, "extruder");
// Page 2 Temp
NexText set0 = NexText(2, 2, "set0");
......@@ -160,6 +161,17 @@
NexText Tgcode = NexText(8, 1, "tgcode");
NexButton Benter = NexButton(8, 41, "benter");
// Page 9 Gcode
NexPicture MSD9 = NexPicture(9, 2, "p1");
NexButton Rfid0 = NexButton(9, 5, "b0");
NexButton Rfid1 = NexButton(9, 6, "b1");
NexButton Rfid2 = NexButton(9, 7, "b2");
NexButton Rfid3 = NexButton(9, 8, "b3");
NexButton Rfid4 = NexButton(9, 9, "b4");
NexButton Rfid5 = NexButton(9, 10, "b5");
NexDSButton RfidR = NexDSButton(9,11, "bt0");
NexText RfidText = NexText(9, 13, "t0");
NexTouch *nex_listen_list[] =
{
&Pstart,
......@@ -167,6 +179,7 @@
&MSD3,
&MSD5,
&MSD6,
&MSD9,
&Fanpic,
&Speedpic,
&NPlay,
......@@ -200,6 +213,12 @@
&ZDown,
&SpeedOk,
&Benter,
&Rfid0,
&Rfid1,
&Rfid2,
&Rfid3,
&Rfid4,
&Rfid5,
NULL
};
......@@ -250,12 +269,18 @@
Hotend21.setText("BED");
#endif
Extruder.setValue(EXTRUDERS);
VSpeed.setValue(100);
#if HAS(FAN)
Fan.setValue(1);
#endif
#if ENABLED(RFID_MODULE)
RFID.setValue(1);
#endif
lcd_setstatus(lcd_status_message);
}
......@@ -406,6 +431,44 @@
}
#endif
#if ENABLED(RFID_MODULE)
void rfidPopCallback(void *ptr) {
memset(buffer, 0, sizeof(buffer));
String temp = "M522 ";
uint32_t Rfid_read = 0;
RfidR.getValue(&Rfid_read);
if (ptr == &Rfid0)
temp += "T0 ";
else if (ptr == &Rfid1)
temp += "T1 ";
else if (ptr == &Rfid2)
temp += "T2 ";
else if (ptr == &Rfid3)
temp += "T3 ";
else if (ptr == &Rfid4)
temp += "T4 ";
else if (ptr == &Rfid5)
temp += "T5 ";
if(Rfid_read)
temp += "R";
else
temp += "W";
temp.toCharArray(buffer, sizeof(buffer));
enqueue_and_echo_commands_P(buffer);
}
void rfid_setText(const char* message, uint32_t color /* = 65535 */) {
char Rfid_status_message[25];
strncpy(Rfid_status_message, message, 30);
RfidText.setColor(color);
RfidText.setText(Rfid_status_message);
}
#endif
void ExitPopCallback(void *ptr) {
setpageInfo();
}
......@@ -523,7 +586,7 @@
for (uint8_t i = 0; i < 10; i++) {
NextionON = nexInit();
if (NextionON) break;
delay(1000);
HAL::delayMilliseconds(1000);
}
if (!NextionON) {
......@@ -549,6 +612,7 @@
MSD3.attachPop(setpageSDPopCallback);
MSD5.attachPop(setpageSDPopCallback);
MSD6.attachPop(setpageSDPopCallback);
MSD9.attachPop(setpageSDPopCallback);
sdlist.attachPop(sdlistPopCallback);
ScrollUp.attachPop(sdlistPopCallback);
ScrollDown.attachPop(sdlistPopCallback);
......@@ -557,6 +621,15 @@
NStop.attachPop(StopPopCallback);
#endif
#if ENABLED(RFID_MODULE)
Rfid0.attachPop(rfidPopCallback, &Rfid0);
Rfid1.attachPop(rfidPopCallback, &Rfid1);
Rfid2.attachPop(rfidPopCallback, &Rfid2);
Rfid3.attachPop(rfidPopCallback, &Rfid3);
Rfid4.attachPop(rfidPopCallback, &Rfid4);
Rfid5.attachPop(rfidPopCallback, &Rfid5);
#endif
#if HAS_TEMP_0
hot0.attachPop(hotPopCallback, &hot0);
#endif
......
......@@ -12,11 +12,11 @@
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
......@@ -77,6 +77,11 @@
void UploadNewFirmware();
#endif
#if ENABLED(RFID_MODULE)
void rfidPopCallback(void *ptr);
void rfid_setText(const char* message, uint32_t color = 65535);
#endif
FORCE_INLINE bool lcd_hasstatus() { return false; }
FORCE_INLINE void lcd_buttons_update() {}
FORCE_INLINE bool lcd_detected(void) { return true; }
......
......@@ -45,6 +45,7 @@ Added total Power consumption writed in SD CARD.
Added total filament printed writed in SD CARD.
Added anti extruder idle oozing system.
Added Hysteresis and Z-Wobble correction (only cartesian printers).
Added support reader TAG width MFRC522
## Credits
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment