Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <EEPROM.h>
- #include <avr/interrupt.h>
- #include <avr/io.h>
- #include <avr/sleep.h>
- #include <Arduino.h>
- #include <U8g2lib.h>
- //#include <SPI.h>
- #include <Wire.h>
- //#include "U8glib.h"
- //U8GLIB_SSD1306_ADAFRUIT_128X64 u8g(12, 11, 8, 9, 10); // SW SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
- U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
- // Пин к которому подключена катушка - пин D2 D6
- #define COIL 6
- byte facility[2] = { 0x02, 0x0C };
- byte cardID[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- int colsum[4] = { 0, 0, 0, 0}; // storage for the column checksums
- // delay between symbols when we are transmitting
- int bittime = 254; //256
- byte RFIDdata[128];
- int clock = 0; // storage for the current state of our clock signal.
- byte datapointer = 0;
- byte state;
- //******************************************************
- #define METAKOM_CYFRAL 0xFFFFFFFFFF
- #define METAKOM_1 0x365A1140BE
- #define CYFRAL_1 0x01FFFFFFFF
- #define VIZIT_1 0x565A1140BE
- #define VIZIT_2 0x365A398149
- #define ELTIS 0x0
- #define K0St25 0x2802AB1340D2 //0x0B57814601
- #define TOILET 0x2802AB1340 //BH352802AB1340D2
- //uint64_t universalID[8] = {1099511627775, 233439314110, 8589934591, 370878267582, 233441952073, 0, 48712730113, 5675447};
- uint64_t universalID[] =
- {
- METAKOM_CYFRAL,
- METAKOM_1,
- CYFRAL_1,
- VIZIT_1,
- VIZIT_2,
- 0,
- K0St25,
- TOILET
- };
- uint32_t nibleMask = 15;
- #define BTN_UP 3
- #define BTN_DWN 5
- #define BTN_SEL 4
- int8_t keyNumber = 0;
- void draw0(void) {
- u8g.setFont(u8g_font_unifont); //display.setCursor(0, 0);
- u8g.drawStr(0,10, ">>1 Met_CY");
- u8g.drawStr(0,26," 2 Met_1");
- u8g.drawStr(0,40," 3 CY_1");
- u8g.drawStr(0,54," 4 VIZ_1");
- }
- void draw1(void) {
- u8g.setFont(u8g_font_unifont); //display.setCursor(0, 0);
- u8g.drawStr(0,10, "1 Met_CY");
- u8g.drawStr(0,26,">> 2 Met_1");
- u8g.drawStr(0,40," 3 CY_1");
- u8g.drawStr(0,54," 4 VIZ_1");
- }
- void draw2(void) {
- u8g.setFont(u8g_font_unifont); //display.setCursor(0, 0);
- u8g.drawStr(0,10, "1 Met_CY");
- u8g.drawStr(0,26," 2 Met_1");
- u8g.drawStr(0,40,">> 3 CY_1");
- u8g.drawStr(0,54," 4 VIZ_1");
- }
- void draw3(void) {
- u8g.setFont(u8g_font_unifont);
- u8g.drawStr(0,10, "1 Met_CY");
- u8g.drawStr(0,26," 2 Met_1");
- u8g.drawStr(0,40," 3 CY_1");
- u8g.drawStr(0,54,">> 4 VIZ_1");
- }
- void draw4(void) {
- u8g.setFont(u8g_font_unifont);
- u8g.drawStr(0,10,">5 VIZ_2");
- u8g.drawStr(0,26," 6 ELT");
- u8g.drawStr(0,40," 7 K0St25");
- u8g.drawStr(0,54," 8 BH35");
- }
- void draw5(void) {
- u8g.setFont(u8g_font_unifont);
- u8g.drawStr(0,10," 5 VIZ_2");
- u8g.drawStr(0,26,"> 6 ELT");
- u8g.drawStr(0,40," 7 K0St25");
- u8g.drawStr(0,54," 8 BH35");
- }
- void draw6(void) {
- u8g.setFont(u8g_font_unifont);
- u8g.drawStr(0,10," 5 VIZ_2");
- u8g.drawStr(0,26," 6 ELT");
- u8g.drawStr(0,40,"> 7 K0St25");
- u8g.drawStr(0,54," 8 BH35");
- }
- void draw7(void) {
- u8g.setFont(u8g_font_unifont);
- u8g.drawStr(0,10," 5 VIZ_2");
- u8g.drawStr(0,26," 6 ELT");
- u8g.drawStr(0,40," 7 K0St25");
- u8g.drawStr(0,54,">> 8 BH35");
- }
- void tr0(void) {
- u8g.setFont(u8g_font_unifont);
- u8g.drawStr(0,10,"> MCOM_CY <");
- }
- void tr1(void) {
- u8g.setFont(u8g_font_unifont);
- u8g.drawStr(0,10,"> MCOM_1 <");
- }
- void tr2(void) {
- u8g.setFont(u8g_font_unifont);
- u8g.drawStr(0,10,"> CYF_1 <");
- }
- void tr3(void) {
- u8g.setFont(u8g_font_unifont);
- u8g.drawStr(0,10,"> VIZ_1 <");
- }
- void tr4(void) {
- u8g.setFont(u8g_font_unifont);
- u8g.drawStr(0,10,"> VIZ_2 <");
- }
- void tr5(void) {
- u8g.setFont(u8g_font_unifont);
- u8g.drawStr(0,10,"> ELTIS <");
- }
- void tr6(void) {
- u8g.setFont(u8g_font_unifont);
- u8g.drawStr(0,10,"> K0St25 <");
- }
- void tr7(void) {
- u8g.setFont(u8g_font_unifont);
- u8g.drawStr(0,10,"> BH35 <");
- }
- void setup()
- {
- // Serial.begin(115200);
- pinMode(BTN_UP, INPUT_PULLUP);
- pinMode(BTN_DWN, INPUT_PULLUP);
- pinMode(BTN_SEL, INPUT_PULLUP);
- pinMode(COIL, OUTPUT);
- digitalWrite(COIL, LOW);
- // flip screen, if required
- // u8g.setRot180();
- u8g.begin();
- // display.init();
- // display.backlight();
- //u8g.setFont(u8g_font_unifont);
- }
- void loop(void)
- {
- //Serial.println(keyNumber);
- if (digitalRead(BTN_UP) == LOW)
- {
- keyNumber++;
- if (keyNumber == 8) keyNumber = 0;
- while (digitalRead(BTN_UP) == LOW);
- //display.clear();
- }
- if (digitalRead(BTN_DWN) == LOW)
- {
- keyNumber--;
- if (keyNumber == -1) keyNumber = 7;
- while (digitalRead(BTN_DWN) == LOW);
- //display.clear();
- }
- switch (keyNumber)
- {
- case 0:
- u8g.firstPage();
- do {
- draw0();
- } while( u8g.nextPage() );
- //display.display();
- break;
- case 1:
- u8g.firstPage();
- do {
- draw1();
- } while( u8g.nextPage() );
- //display.display();
- break;
- case 2:
- u8g.firstPage();
- do {
- draw2();
- } while( u8g.nextPage() );
- //display.display();
- break;
- case 3:
- u8g.firstPage();
- do {
- draw3();
- } while( u8g.nextPage() );
- //display.display();
- break;
- case 4:
- u8g.firstPage();
- do {
- draw4();
- } while( u8g.nextPage() );
- break;
- case 5:
- u8g.firstPage();
- do {
- draw5();
- } while( u8g.nextPage() );
- break;
- case 6:
- u8g.firstPage();
- do {
- draw6();
- } while( u8g.nextPage() );
- break;
- case 7:
- u8g.firstPage();
- do {
- draw7();
- } while( u8g.nextPage() );
- break;
- }
- if (digitalRead(BTN_SEL) == LOW)
- {
- //display.clear();
- switch (keyNumber)
- {
- case 0:
- u8g.firstPage();
- do {
- tr0();
- } while( u8g.nextPage() );
- break;
- case 1:
- u8g.firstPage();
- do {
- tr1();
- } while( u8g.nextPage() );
- break;
- case 2:
- u8g.firstPage();
- do {
- tr2();
- } while( u8g.nextPage() );
- break;
- case 3:
- u8g.firstPage();
- do {
- tr3();
- } while( u8g.nextPage() );
- break;
- case 4:
- u8g.firstPage();
- do {
- tr4();
- } while( u8g.nextPage() );
- break;
- case 5:
- u8g.firstPage();
- do {
- tr5();
- } while( u8g.nextPage() );
- break;
- case 6:
- u8g.firstPage();
- do {
- tr6();
- } while( u8g.nextPage() );
- break;
- case 7:
- u8g.firstPage();
- do {
- tr7();
- } while( u8g.nextPage() );
- break;
- }
- /*display.print("Press reset");
- display.print("to continue...");
- display.display();
- */
- facility[0] = universalID[keyNumber] >> 36 & nibleMask;
- facility[1] = universalID[keyNumber] >> 32 & nibleMask;
- for (uint8_t i = 0; i < 8; ++i ) //забиваем десятичный ID карты в массив
- {
- cardID[i] = (universalID[keyNumber] >> ((7 - i) * 4)) & nibleMask; //в нулевой элемент массива надо записывать старший разряд, поэтому 7-i
- }
- EmulateCard(); // start card emulation
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement