From e263b258e1c0f114f49e446a6c53a68b1a26ee4f Mon Sep 17 00:00:00 2001 From: hark Date: Sun, 28 Aug 2016 23:03:54 +0200 Subject: [PATCH] not crashing (and not working) arduino --- arduino-rx/Makefile | 5 +- arduino-rx/arduino-rx.ino | 255 ++++++++++++-- base-tx/test.c | 14 +- libs/LiquidCrystal/LiquidCrystal.cpp | 310 ++++++++++++++++++ libs/LiquidCrystal/LiquidCrystal.h | 106 ++++++ .../examples/Autoscroll/Autoscroll.ino | 74 +++++ libs/LiquidCrystal/examples/Blink/Blink.ino | 61 ++++ libs/LiquidCrystal/examples/Cursor/Cursor.ino | 61 ++++ .../CustomCharacter/CustomCharacter.ino | 138 ++++++++ .../examples/Display/Display.ino | 61 ++++ .../examples/HelloWorld/HelloWorld.ino | 58 ++++ libs/LiquidCrystal/examples/Scroll/Scroll.ino | 86 +++++ .../examples/SerialDisplay/SerialDisplay.ino | 65 ++++ .../examples/TextDirection/TextDirection.ino | 86 +++++ .../examples/setCursor/setCursor.ino | 72 ++++ libs/LiquidCrystal/keywords.txt | 37 +++ libs/pagerlib/pagerlib.c | 52 ++- libs/pagerlib/pagerlib.h | 9 +- 18 files changed, 1498 insertions(+), 52 deletions(-) create mode 100644 libs/LiquidCrystal/LiquidCrystal.cpp create mode 100644 libs/LiquidCrystal/LiquidCrystal.h create mode 100644 libs/LiquidCrystal/examples/Autoscroll/Autoscroll.ino create mode 100644 libs/LiquidCrystal/examples/Blink/Blink.ino create mode 100644 libs/LiquidCrystal/examples/Cursor/Cursor.ino create mode 100644 libs/LiquidCrystal/examples/CustomCharacter/CustomCharacter.ino create mode 100644 libs/LiquidCrystal/examples/Display/Display.ino create mode 100644 libs/LiquidCrystal/examples/HelloWorld/HelloWorld.ino create mode 100644 libs/LiquidCrystal/examples/Scroll/Scroll.ino create mode 100644 libs/LiquidCrystal/examples/SerialDisplay/SerialDisplay.ino create mode 100644 libs/LiquidCrystal/examples/TextDirection/TextDirection.ino create mode 100644 libs/LiquidCrystal/examples/setCursor/setCursor.ino create mode 100644 libs/LiquidCrystal/keywords.txt diff --git a/arduino-rx/Makefile b/arduino-rx/Makefile index 196f086..e6bd10c 100644 --- a/arduino-rx/Makefile +++ b/arduino-rx/Makefile @@ -1,8 +1,9 @@ ARDUINO_DIR= USER_LIB_PATH=../libs/ BOARD_TAG=atmega328 -ARDUINO_LIBS=RadioHead SPI AESLib Wire LCDI2C_LK162 MemoryFree micro-ecc pagerlib +ARDUINO_LIBS=RadioHead SPI AESLib Wire LCDI2C_LK162 MemoryFree micro-ecc pagerlib LiquidCrystal include /usr/share/arduino/Arduino.mk -DEVICE_PATH = /dev/ttyUSB2 +#DEVICE_PATH = /dev/ttyUSB0 +DEVICE_PATH = /tmp/simavr-uart0 TARGET = arduino-rx diff --git a/arduino-rx/arduino-rx.ino b/arduino-rx/arduino-rx.ino index 627bc5d..4115f82 100644 --- a/arduino-rx/arduino-rx.ino +++ b/arduino-rx/arduino-rx.ino @@ -1,3 +1,4 @@ + #include #include #include @@ -7,72 +8,262 @@ #include // Not actualy used but needed to compile #include #include -#include +//#include #include #include +#include +#include +/* #define NUM_ECC_DIGITS 24 //size of privkey, curvesize in bytes #define CURVE uECC_secp192r1() -LCDI2C lcd = LCDI2C(2,16,0x50,0); + */ +//LCDI2C lcd = LCDI2C(2,16,0x50,0); +/* + * pagerlib things + */ aes_context ctx; // context for the cbc crypto stuff -#define ADDRESS 2 -#define MESSAGE_SIZE 32 -#define PAGER_MESSAGE_SIZE 57 +//const uint8_t tx_priv_key[ECC_COMPRESSED_SIZE-1] PROGMEM = {0xB4, 0x15, 0x70, 0x3E, 0xA7, 0x5D, 0x06, 0xF2, 0x33, 0x75, 0x8E, 0xE0, 0x86, 0x1B, 0x73, 0xBE, 0xEC, 0x87, 0x36, 0x0F, 0xF5, 0xE1, 0x79, 0x76, 0x2C, 0x3C, 0x74, 0x69, 0x83, 0x71, 0x07, 0xB5}; +//const uint8_t tx_comp_p[ECC_COMPRESSED_SIZE] PROGMEM = {0x02, 0xA3, 0x91, 0x16, 0x71, 0x1E, 0x7B, 0xB2, 0x51, 0x7F, 0xD4, 0xF4, 0xC7, 0x81, 0x49, 0x75, 0x8B, 0x48, 0x75, 0x59, 0x27, 0xC9, 0x94, 0x3F, 0x59, 0xDD, 0xFF, 0x2E, 0x89, 0xE9, 0xD8, 0x1D, 0x2B }; + +struct pl_keypair *sender, *receiver, *kp; +char clear_message[] = "dit is een test berichtje :) "; +//const char clear_message[] PROGMEM = "Blaat coblaat, dit is een test berichtje :), en nog meer en meer en meer 123456744555 blablablablablablabal jajajajaj hee blaat "; +//const char b64_key[] PROGMEM = "Zs8rZ5EfIpMs2i5Mskq2Nnx0pHhKShirwswQbIAjXxUDkPCKKSD1o+oIF84qwlUk85B1W0lN4AyEtJZNk24HKL8="; +//const char b64_key2[] PROGMEM = "6+owJHKEhmoz1RI3dx+x7JODIjueBOZUmzjxSrmrpZ8COt4Tld6bsa2UlFnt4qDMf/Rz5M60d/wjgXzafEkCg54="; +const char b64_key[] = "Zs8rZ5EfIpMs2i5Mskq2Nnx0pHhKShirwswQbIAjXxUDkPCKKSD1o+oIF84qwlUk85B1W0lN4AyEtJZNk24HKL8="; +const char b64_key2[]= "6+owJHKEhmoz1RI3dx+x7JODIjueBOZUmzjxSrmrpZ8COt4Tld6bsa2UlFnt4qDMf/Rz5M60d/wjgXzafEkCg54="; + -RH_ASK driver(2000); -RHDatagram manager(driver, ADDRESS); -uint8_t tx_priv_key[ECC_COMPRESSED_SIZE-1] = {0xB4, 0x15, 0x70, 0x3E, 0xA7, 0x5D, 0x06, 0xF2, 0x33, 0x75, 0x8E, 0xE0, 0x86, 0x1B, 0x73, 0xBE, 0xEC, 0x87, 0x36, 0x0F, 0xF5, 0xE1, 0x79, 0x76, 0x2C, 0x3C, 0x74, 0x69, 0x83, 0x71, 0x07, 0xB5}; -uint8_t tx_comp_p[ECC_COMPRESSED_SIZE] = {0x02, 0xA3, 0x91, 0x16, 0x71, 0x1E, 0x7B, 0xB2, 0x51, 0x7F, 0xD4, 0xF4, 0xC7, 0x81, 0x49, 0x75, 0x8B, 0x48, 0x75, 0x59, 0x27, 0xC9, 0x94, 0x3F, 0x59, 0xDD, 0xFF, 0x2E, 0x89, 0xE9, 0xD8, 0x1D, 0x2B }; -struct pl_keypair *sender, *receiver; -char clear_message[] = "dit is een test berichtje :) "; struct pl_ctx * context; +char output[MSG_SIZE] = "outputcharbla" ; +#define LCD +#define RADIO + +/* + * hardware things + */ + +#define ADDRESS 2 +/* +#define MESSAGE_SIZE 32 +#define PAGER_MESSAGE_SIZE 57 + */ + +#ifdef RADIO +RH_ASK driver(2000, 2, 12, 13); +RHDatagram manager(driver, ADDRESS); +#endif +#ifdef LCD +LiquidCrystal lcd(8, 9, 4, 5, 6, 7); + +// define some values used by the panel and buttons +int lcd_key = 0; +int adc_key_in = 0; +#define btnRIGHT 0 +#define btnUP 1 +#define btnDOWN 2 +#define btnLEFT 3 +#define btnSELECT 4 +#define btnNONE 5 +#endif void setup() { - lcd.init(); - lcd.println("dit is een pager"); +#ifdef LCD + // select the pins used on the LCD panel + lcd.begin(16, 2); // start the library + lcd.setCursor(0,0); + // lcd.print("Push the buttons"); // print a simple message + //pinMode(10, OUTPUT); + //digitalWrite(10, HIGH); + + // lcd.init(); + lcd.clear(); + lcd.print("dit is een pager"); +#endif Serial.begin(9600); // Debugging only + +#ifdef RADIO Serial.println("RX init"); if (!manager.init()) - Serial.println("init failed"); + Serial.println("init failed"); +#endif + Serial.print("freeMemory()="); Serial.println(freeMemory()); context = pl_init(); - receiver = (struct pl_keypair *) malloc(sizeof(struct pl_keypair)); + // receiver = (struct pl_keypair *) malloc(sizeof(struct pl_keypair)); + + // init pager + // memcpy(receiver->private_key, tx_priv_key, ECC_COMPRESSED_SIZE-1); + // memcpy(receiver->compressed_point, tx_comp_p, ECC_COMPRESSED_SIZE); + +#ifdef LCD + lcd.setCursor(0,1); + // create receiver keypair and load in list + lcd.print("*"); +#endif + + /* + * load the keys from the base64 thingies + */ + receiver = (struct pl_keypair *)malloc(sizeof(struct pl_keypair)); + base64_decode((char *)receiver , (char *)&b64_key, (4*sizeof(struct pl_keypair) / 3)) ; + pl_load_key_in_list(context, receiver); + + // receiver = pl_create_keypair(context); + // + // create sender keypair + // kp = pl_create_keypair(context); + sender = (struct pl_keypair *)malloc(sizeof(struct pl_keypair)); + context->kp = (struct pl_keypair *)malloc(sizeof(struct pl_keypair)); + base64_decode((char *)sender , (char *)&b64_key2, (4*sizeof(struct pl_keypair) / 3)) ; + + // pl_load_key_in_list(context, kp); + // set default + context->kp = sender; +#ifdef LCD + lcd.clear(); + lcd.print("finished making keys"); +#endif } +#ifdef LCD +// read the buttons +int read_LCD_buttons() +{ + adc_key_in = analogRead(0); // read the value from the sensor + // my buttons when read are centered at these valies: 0, 144, 329, 504, 741 + // we add approx 50 to those values and check to see if we are close + if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result + // For V1.1 us this threshold + if (adc_key_in < 50) return btnRIGHT; + if (adc_key_in < 250) return btnUP; + if (adc_key_in < 450) return btnDOWN; + if (adc_key_in < 650) return btnLEFT; + if (adc_key_in < 850) return btnSELECT; + // For V1.0 comment the other threshold and use the one below: + /* + if (adc_key_in < 50) return btnRIGHT; + if (adc_key_in < 195) return btnUP; + if (adc_key_in < 380) return btnDOWN; + if (adc_key_in < 555) return btnLEFT; + if (adc_key_in < 790) return btnSELECT; + */ +} +#endif void display(char *msg) { -/* char line1[16]; - char line2[16]; - for(int i=0; i < MESSAGE_SIZE ; i++){ - if(i < 16) - line1[i] = msg[i]; - else - line2[i-16] = msg[i]; - }; -*/ - lcd.clear(); - lcd.println(msg); + /* char line1[16]; + char line2[16]; + for(int i=0; i < MESSAGE_SIZE ; i++){ + if(i < 16) + line1[i] = msg[i]; + else + line2[i-16] = msg[i]; + }; + */ + //lcd.clear(); + //lcd.println(msg); } +/* + void loop() + { + lcd.setCursor(9,1); // move cursor to second line "1" and 9 spaces over + lcd.print(millis()/1000); // display seconds elapsed since power-up + + + lcd.setCursor(0,1); // move to the begining of the second line + lcd_key = read_LCD_buttons(); // read the buttons + + switch (lcd_key) // depending on which button was pushed, we perform an action + { + case btnRIGHT: + { + lcd.print("RIGHT "); + break; + } + case btnLEFT: + { + lcd.print("LEFT "); + break; + } + case btnUP: + { + lcd.print("UP "); + break; + } + case btnDOWN: + { + lcd.print("DOWN "); + break; + } + case btnSELECT: + { + lcd.print("SELECT"); + break; + } + case btnNONE: + { + lcd.print("NONE "); + break; + } + } + + } + */ void loop() { - memcpy(receiver->private_key, tx_priv_key, ECC_COMPRESSED_SIZE-1); - memcpy(receiver->compressed_point, tx_comp_p, ECC_COMPRESSED_SIZE); + + Serial.println("bla\n"); +#ifdef LCD + lcd.setCursor(0, 1); + // print the number of seconds since reset: + lcd.print(millis()/100); +#endif + memcpy(context->msg->msg + 8, "bla", MSG_SIZE - 8); + + + memcpy(&context->msg->msg, clear_message, MSG_SIZE); + // context->kp = kp; + //to who to send the message to (get from kp) + memcpy(&context->receiver_compressed_point, &kp->compressed_point, sizeof(context->receiver_compressed_point)); //get msg with radio + //memcpy(context->msg->msg + 8, "bla", MSG_SIZE - 8); + pl_send_message(context); - context->kp = receiver; - pl_receive_message(context); - Serial.println("decrypted msg:"); + Serial.println("crypted message:"); Serial.println(context->msg->msg); + // base64_encode((char *)&output, context->msg->msg, MSG_SIZE); +#ifdef LCD + lcd.clear(); + lcd.setCursor(0,0); + lcd.print("crypted message:"); + delay(1000); + lcd.clear(); + lcd.setCursor(0,0); + lcd.print(context->msg->msg); +#endif - + // pl_receive_message(context); +#ifdef LCD + delay(1000); + lcd.clear(); + lcd.setCursor(0,0); + lcd.print("decrypted msg:"); + lcd.setCursor(0,0); + lcd.println(context->msg->msg); + delay(1000); + lcd.clear(); +#endif } + diff --git a/base-tx/test.c b/base-tx/test.c index e9cc251..afea6cb 100644 --- a/base-tx/test.c +++ b/base-tx/test.c @@ -37,6 +37,18 @@ int main() { f++; /* create keypairs */ kp = pl_create_keypair(context); + char *kp_b64, *decoded; + // 4*(n/3) + kp_b64 = malloc(4*(sizeof(struct pl_keypair) / 3)); + decoded = malloc(sizeof(struct pl_keypair)); + + + base64_encode(kp_b64, kp, sizeof(struct pl_keypair)); + printf("base64 keypair: %s \n", kp_b64); + + base64_decode(decoded , kp_b64, (4*sizeof(struct pl_keypair) / 3)) ; + + pl_load_key_in_list(context, kp); // set key to use for sending the message (FIXME) context->kp = kp; @@ -48,7 +60,7 @@ int main() { memcpy(&context->receiver_compressed_point, &kp->compressed_point, sizeof(context->receiver_compressed_point)); pl_send_message(context); - + printf("crypted msg: %s",context->msg->msg); /* receive the msg */ if ( pl_receive_message(context) == 1) { diff --git a/libs/LiquidCrystal/LiquidCrystal.cpp b/libs/LiquidCrystal/LiquidCrystal.cpp new file mode 100644 index 0000000..0653487 --- /dev/null +++ b/libs/LiquidCrystal/LiquidCrystal.cpp @@ -0,0 +1,310 @@ +#include "LiquidCrystal.h" + +#include +#include +#include +#include "Arduino.h" + +// When the display powers up, it is configured as follows: +// +// 1. Display clear +// 2. Function set: +// DL = 1; 8-bit interface data +// N = 0; 1-line display +// F = 0; 5x8 dot character font +// 3. Display on/off control: +// D = 0; Display off +// C = 0; Cursor off +// B = 0; Blinking off +// 4. Entry mode set: +// I/D = 1; Increment by 1 +// S = 0; No shift +// +// Note, however, that resetting the Arduino doesn't reset the LCD, so we +// can't assume that its in that state when a sketch starts (and the +// LiquidCrystal constructor is called). + +LiquidCrystal::LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable, + uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, + uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7) +{ + init(0, rs, rw, enable, d0, d1, d2, d3, d4, d5, d6, d7); +} + +LiquidCrystal::LiquidCrystal(uint8_t rs, uint8_t enable, + uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, + uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7) +{ + init(0, rs, 255, enable, d0, d1, d2, d3, d4, d5, d6, d7); +} + +LiquidCrystal::LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable, + uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3) +{ + init(1, rs, rw, enable, d0, d1, d2, d3, 0, 0, 0, 0); +} + +LiquidCrystal::LiquidCrystal(uint8_t rs, uint8_t enable, + uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3) +{ + init(1, rs, 255, enable, d0, d1, d2, d3, 0, 0, 0, 0); +} + +void LiquidCrystal::init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t enable, + uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, + uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7) +{ + _rs_pin = rs; + _rw_pin = rw; + _enable_pin = enable; + + _data_pins[0] = d0; + _data_pins[1] = d1; + _data_pins[2] = d2; + _data_pins[3] = d3; + _data_pins[4] = d4; + _data_pins[5] = d5; + _data_pins[6] = d6; + _data_pins[7] = d7; + + pinMode(_rs_pin, OUTPUT); + // we can save 1 pin by not using RW. Indicate by passing 255 instead of pin# + if (_rw_pin != 255) { + pinMode(_rw_pin, OUTPUT); + } + pinMode(_enable_pin, OUTPUT); + + if (fourbitmode) + _displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS; + else + _displayfunction = LCD_8BITMODE | LCD_1LINE | LCD_5x8DOTS; + + begin(16, 1); +} + +void LiquidCrystal::begin(uint8_t cols, uint8_t lines, uint8_t dotsize) { + if (lines > 1) { + _displayfunction |= LCD_2LINE; + } + _numlines = lines; + _currline = 0; + + // for some 1 line displays you can select a 10 pixel high font + if ((dotsize != 0) && (lines == 1)) { + _displayfunction |= LCD_5x10DOTS; + } + + // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION! + // according to datasheet, we need at least 40ms after power rises above 2.7V + // before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50 + delayMicroseconds(50000); + // Now we pull both RS and R/W low to begin commands + digitalWrite(_rs_pin, LOW); + digitalWrite(_enable_pin, LOW); + if (_rw_pin != 255) { + digitalWrite(_rw_pin, LOW); + } + + //put the LCD into 4 bit or 8 bit mode + if (! (_displayfunction & LCD_8BITMODE)) { + // this is according to the hitachi HD44780 datasheet + // figure 24, pg 46 + + // we start in 8bit mode, try to set 4 bit mode + write4bits(0x03); + delayMicroseconds(4500); // wait min 4.1ms + + // second try + write4bits(0x03); + delayMicroseconds(4500); // wait min 4.1ms + + // third go! + write4bits(0x03); + delayMicroseconds(150); + + // finally, set to 4-bit interface + write4bits(0x02); + } else { + // this is according to the hitachi HD44780 datasheet + // page 45 figure 23 + + // Send function set command sequence + command(LCD_FUNCTIONSET | _displayfunction); + delayMicroseconds(4500); // wait more than 4.1ms + + // second try + command(LCD_FUNCTIONSET | _displayfunction); + delayMicroseconds(150); + + // third go + command(LCD_FUNCTIONSET | _displayfunction); + } + + // finally, set # lines, font size, etc. + command(LCD_FUNCTIONSET | _displayfunction); + + // turn the display on with no cursor or blinking default + _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF; + display(); + + // clear it off + clear(); + + // Initialize to default text direction (for romance languages) + _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT; + // set the entry mode + command(LCD_ENTRYMODESET | _displaymode); + +} + +/********** high level commands, for the user! */ +void LiquidCrystal::clear() +{ + command(LCD_CLEARDISPLAY); // clear display, set cursor position to zero + delayMicroseconds(2000); // this command takes a long time! +} + +void LiquidCrystal::home() +{ + command(LCD_RETURNHOME); // set cursor position to zero + delayMicroseconds(2000); // this command takes a long time! +} + +void LiquidCrystal::setCursor(uint8_t col, uint8_t row) +{ + int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 }; + if ( row >= _numlines ) { + row = _numlines-1; // we count rows starting w/0 + } + + command(LCD_SETDDRAMADDR | (col + row_offsets[row])); +} + +// Turn the display on/off (quickly) +void LiquidCrystal::noDisplay() { + _displaycontrol &= ~LCD_DISPLAYON; + command(LCD_DISPLAYCONTROL | _displaycontrol); +} +void LiquidCrystal::display() { + _displaycontrol |= LCD_DISPLAYON; + command(LCD_DISPLAYCONTROL | _displaycontrol); +} + +// Turns the underline cursor on/off +void LiquidCrystal::noCursor() { + _displaycontrol &= ~LCD_CURSORON; + command(LCD_DISPLAYCONTROL | _displaycontrol); +} +void LiquidCrystal::cursor() { + _displaycontrol |= LCD_CURSORON; + command(LCD_DISPLAYCONTROL | _displaycontrol); +} + +// Turn on and off the blinking cursor +void LiquidCrystal::noBlink() { + _displaycontrol &= ~LCD_BLINKON; + command(LCD_DISPLAYCONTROL | _displaycontrol); +} +void LiquidCrystal::blink() { + _displaycontrol |= LCD_BLINKON; + command(LCD_DISPLAYCONTROL | _displaycontrol); +} + +// These commands scroll the display without changing the RAM +void LiquidCrystal::scrollDisplayLeft(void) { + command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT); +} +void LiquidCrystal::scrollDisplayRight(void) { + command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT); +} + +// This is for text that flows Left to Right +void LiquidCrystal::leftToRight(void) { + _displaymode |= LCD_ENTRYLEFT; + command(LCD_ENTRYMODESET | _displaymode); +} + +// This is for text that flows Right to Left +void LiquidCrystal::rightToLeft(void) { + _displaymode &= ~LCD_ENTRYLEFT; + command(LCD_ENTRYMODESET | _displaymode); +} + +// This will 'right justify' text from the cursor +void LiquidCrystal::autoscroll(void) { + _displaymode |= LCD_ENTRYSHIFTINCREMENT; + command(LCD_ENTRYMODESET | _displaymode); +} + +// This will 'left justify' text from the cursor +void LiquidCrystal::noAutoscroll(void) { + _displaymode &= ~LCD_ENTRYSHIFTINCREMENT; + command(LCD_ENTRYMODESET | _displaymode); +} + +// Allows us to fill the first 8 CGRAM locations +// with custom characters +void LiquidCrystal::createChar(uint8_t location, uint8_t charmap[]) { + location &= 0x7; // we only have 8 locations 0-7 + command(LCD_SETCGRAMADDR | (location << 3)); + for (int i=0; i<8; i++) { + write(charmap[i]); + } +} + +/*********** mid level commands, for sending data/cmds */ + +inline void LiquidCrystal::command(uint8_t value) { + send(value, LOW); +} + +inline size_t LiquidCrystal::write(uint8_t value) { + send(value, HIGH); + return 1; // assume sucess +} + +/************ low level data pushing commands **********/ + +// write either command or data, with automatic 4/8-bit selection +void LiquidCrystal::send(uint8_t value, uint8_t mode) { + digitalWrite(_rs_pin, mode); + + // if there is a RW pin indicated, set it low to Write + if (_rw_pin != 255) { + digitalWrite(_rw_pin, LOW); + } + + if (_displayfunction & LCD_8BITMODE) { + write8bits(value); + } else { + write4bits(value>>4); + write4bits(value); + } +} + +void LiquidCrystal::pulseEnable(void) { + digitalWrite(_enable_pin, LOW); + delayMicroseconds(1); + digitalWrite(_enable_pin, HIGH); + delayMicroseconds(1); // enable pulse must be >450ns + digitalWrite(_enable_pin, LOW); + delayMicroseconds(100); // commands need > 37us to settle +} + +void LiquidCrystal::write4bits(uint8_t value) { + for (int i = 0; i < 4; i++) { + pinMode(_data_pins[i], OUTPUT); + digitalWrite(_data_pins[i], (value >> i) & 0x01); + } + + pulseEnable(); +} + +void LiquidCrystal::write8bits(uint8_t value) { + for (int i = 0; i < 8; i++) { + pinMode(_data_pins[i], OUTPUT); + digitalWrite(_data_pins[i], (value >> i) & 0x01); + } + + pulseEnable(); +} diff --git a/libs/LiquidCrystal/LiquidCrystal.h b/libs/LiquidCrystal/LiquidCrystal.h new file mode 100644 index 0000000..24ec5af --- /dev/null +++ b/libs/LiquidCrystal/LiquidCrystal.h @@ -0,0 +1,106 @@ +#ifndef LiquidCrystal_h +#define LiquidCrystal_h + +#include +#include "Print.h" + +// commands +#define LCD_CLEARDISPLAY 0x01 +#define LCD_RETURNHOME 0x02 +#define LCD_ENTRYMODESET 0x04 +#define LCD_DISPLAYCONTROL 0x08 +#define LCD_CURSORSHIFT 0x10 +#define LCD_FUNCTIONSET 0x20 +#define LCD_SETCGRAMADDR 0x40 +#define LCD_SETDDRAMADDR 0x80 + +// flags for display entry mode +#define LCD_ENTRYRIGHT 0x00 +#define LCD_ENTRYLEFT 0x02 +#define LCD_ENTRYSHIFTINCREMENT 0x01 +#define LCD_ENTRYSHIFTDECREMENT 0x00 + +// flags for display on/off control +#define LCD_DISPLAYON 0x04 +#define LCD_DISPLAYOFF 0x00 +#define LCD_CURSORON 0x02 +#define LCD_CURSOROFF 0x00 +#define LCD_BLINKON 0x01 +#define LCD_BLINKOFF 0x00 + +// flags for display/cursor shift +#define LCD_DISPLAYMOVE 0x08 +#define LCD_CURSORMOVE 0x00 +#define LCD_MOVERIGHT 0x04 +#define LCD_MOVELEFT 0x00 + +// flags for function set +#define LCD_8BITMODE 0x10 +#define LCD_4BITMODE 0x00 +#define LCD_2LINE 0x08 +#define LCD_1LINE 0x00 +#define LCD_5x10DOTS 0x04 +#define LCD_5x8DOTS 0x00 + +class LiquidCrystal : public Print { +public: + LiquidCrystal(uint8_t rs, uint8_t enable, + uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, + uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7); + LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable, + uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, + uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7); + LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable, + uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3); + LiquidCrystal(uint8_t rs, uint8_t enable, + uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3); + + void init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t enable, + uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, + uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7); + + void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS); + + void clear(); + void home(); + + void noDisplay(); + void display(); + void noBlink(); + void blink(); + void noCursor(); + void cursor(); + void scrollDisplayLeft(); + void scrollDisplayRight(); + void leftToRight(); + void rightToLeft(); + void autoscroll(); + void noAutoscroll(); + + void createChar(uint8_t, uint8_t[]); + void setCursor(uint8_t, uint8_t); + virtual size_t write(uint8_t); + void command(uint8_t); + + using Print::write; +private: + void send(uint8_t, uint8_t); + void write4bits(uint8_t); + void write8bits(uint8_t); + void pulseEnable(); + + uint8_t _rs_pin; // LOW: command. HIGH: character. + uint8_t _rw_pin; // LOW: write to LCD. HIGH: read from LCD. + uint8_t _enable_pin; // activated by a HIGH pulse. + uint8_t _data_pins[8]; + + uint8_t _displayfunction; + uint8_t _displaycontrol; + uint8_t _displaymode; + + uint8_t _initialized; + + uint8_t _numlines,_currline; +}; + +#endif diff --git a/libs/LiquidCrystal/examples/Autoscroll/Autoscroll.ino b/libs/LiquidCrystal/examples/Autoscroll/Autoscroll.ino new file mode 100644 index 0000000..1127d8f --- /dev/null +++ b/libs/LiquidCrystal/examples/Autoscroll/Autoscroll.ino @@ -0,0 +1,74 @@ +/* + LiquidCrystal Library - Autoscroll + + Demonstrates the use a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch demonstrates the use of the autoscroll() + and noAutoscroll() functions to make new text scroll or not. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K resistor: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + + This example code is in the public domain. + + http://arduino.cc/en/Tutorial/LiquidCrystalAutoscroll + + */ + +// include the library code: +#include + +// initialize the library with the numbers of the interface pins +LiquidCrystal lcd(12, 11, 5, 4, 3, 2); + +void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(16,2); +} + +void loop() { + // set the cursor to (0,0): + lcd.setCursor(0, 0); + // print from 0 to 9: + for (int thisChar = 0; thisChar < 10; thisChar++) { + lcd.print(thisChar); + delay(500); + } + + // set the cursor to (16,1): + lcd.setCursor(16,1); + // set the display to automatically scroll: + lcd.autoscroll(); + // print from 0 to 9: + for (int thisChar = 0; thisChar < 10; thisChar++) { + lcd.print(thisChar); + delay(500); + } + // turn off automatic scrolling + lcd.noAutoscroll(); + + // clear screen for the next loop: + lcd.clear(); +} + diff --git a/libs/LiquidCrystal/examples/Blink/Blink.ino b/libs/LiquidCrystal/examples/Blink/Blink.ino new file mode 100644 index 0000000..9667b5d --- /dev/null +++ b/libs/LiquidCrystal/examples/Blink/Blink.ino @@ -0,0 +1,61 @@ +/* + LiquidCrystal Library - Blink + + Demonstrates the use a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch prints "Hello World!" to the LCD and makes the + cursor block blink. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K resistor: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + + This example code is in the public domain. + + http://arduino.cc/en/Tutorial/LiquidCrystalBlink + + */ + +// include the library code: +#include + +// initialize the library with the numbers of the interface pins +LiquidCrystal lcd(12, 11, 5, 4, 3, 2); + +void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(16, 2); + // Print a message to the LCD. + lcd.print("hello, world!"); +} + +void loop() { + // Turn off the blinking cursor: + lcd.noBlink(); + delay(3000); + // Turn on the blinking cursor: + lcd.blink(); + delay(3000); +} + + diff --git a/libs/LiquidCrystal/examples/Cursor/Cursor.ino b/libs/LiquidCrystal/examples/Cursor/Cursor.ino new file mode 100644 index 0000000..05862a4 --- /dev/null +++ b/libs/LiquidCrystal/examples/Cursor/Cursor.ino @@ -0,0 +1,61 @@ +/* + LiquidCrystal Library - Cursor + + Demonstrates the use a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch prints "Hello World!" to the LCD and + uses the cursor() and noCursor() methods to turn + on and off the cursor. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K resistor: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + + This example code is in the public domain. + + http://arduino.cc/en/Tutorial/LiquidCrystalCursor + + */ + +// include the library code: +#include + +// initialize the library with the numbers of the interface pins +LiquidCrystal lcd(12, 11, 5, 4, 3, 2); + +void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(16, 2); + // Print a message to the LCD. + lcd.print("hello, world!"); +} + +void loop() { + // Turn off the cursor: + lcd.noCursor(); + delay(500); + // Turn on the cursor: + lcd.cursor(); + delay(500); +} + diff --git a/libs/LiquidCrystal/examples/CustomCharacter/CustomCharacter.ino b/libs/LiquidCrystal/examples/CustomCharacter/CustomCharacter.ino new file mode 100644 index 0000000..d3ce479 --- /dev/null +++ b/libs/LiquidCrystal/examples/CustomCharacter/CustomCharacter.ino @@ -0,0 +1,138 @@ +/* + LiquidCrystal Library - Custom Characters + + Demonstrates how to add custom characters on an LCD display. + The LiquidCrystal library works with all LCD displays that are + compatible with the Hitachi HD44780 driver. There are many of + them out there, and you can usually tell them by the 16-pin interface. + + This sketch prints "I Arduino!" and a little dancing man + to the LCD. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K potentiometer: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + * 10K poterntiometer on pin A0 + + created21 Mar 2011 + by Tom Igoe + Based on Adafruit's example at + https://github.com/adafruit/SPI_VFD/blob/master/examples/createChar/createChar.pde + + This example code is in the public domain. + http://www.arduino.cc/en/Tutorial/LiquidCrystal + + Also useful: + http://icontexto.com/charactercreator/ + + */ + +// include the library code: +#include + +// initialize the library with the numbers of the interface pins +LiquidCrystal lcd(12, 11, 5, 4, 3, 2); + +// make some custom characters: +byte heart[8] = { + 0b00000, + 0b01010, + 0b11111, + 0b11111, + 0b11111, + 0b01110, + 0b00100, + 0b00000 +}; + +byte smiley[8] = { + 0b00000, + 0b00000, + 0b01010, + 0b00000, + 0b00000, + 0b10001, + 0b01110, + 0b00000 +}; + +byte frownie[8] = { + 0b00000, + 0b00000, + 0b01010, + 0b00000, + 0b00000, + 0b00000, + 0b01110, + 0b10001 +}; + +byte armsDown[8] = { + 0b00100, + 0b01010, + 0b00100, + 0b00100, + 0b01110, + 0b10101, + 0b00100, + 0b01010 +}; + +byte armsUp[8] = { + 0b00100, + 0b01010, + 0b00100, + 0b10101, + 0b01110, + 0b00100, + 0b00100, + 0b01010 +}; +void setup() { + // create a new character + lcd.createChar(0, heart); + // create a new character + lcd.createChar(1, smiley); + // create a new character + lcd.createChar(2, frownie); + // create a new character + lcd.createChar(3, armsDown); + // create a new character + lcd.createChar(4, armsUp); + + // set up the lcd's number of columns and rows: + lcd.begin(16, 2); + // Print a message to the lcd. + lcd.print("I "); + lcd.write(0); + lcd.print(" Arduino! "); + lcd.write(1); + +} + +void loop() { + // read the potentiometer on A0: + int sensorReading = analogRead(A0); + // map the result to 200 - 1000: + int delayTime = map(sensorReading, 0, 1023, 200, 1000); + // set the cursor to the bottom row, 5th position: + lcd.setCursor(4, 1); + // draw the little man, arms down: + lcd.write(3); + delay(delayTime); + lcd.setCursor(4, 1); + // draw him arms up: + lcd.write(4); + delay(delayTime); +} + + + diff --git a/libs/LiquidCrystal/examples/Display/Display.ino b/libs/LiquidCrystal/examples/Display/Display.ino new file mode 100644 index 0000000..a85effb --- /dev/null +++ b/libs/LiquidCrystal/examples/Display/Display.ino @@ -0,0 +1,61 @@ +/* + LiquidCrystal Library - display() and noDisplay() + + Demonstrates the use a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch prints "Hello World!" to the LCD and uses the + display() and noDisplay() functions to turn on and off + the display. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K resistor: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + + This example code is in the public domain. + + http://arduino.cc/en/Tutorial/LiquidCrystalDisplay + + */ + +// include the library code: +#include + +// initialize the library with the numbers of the interface pins +LiquidCrystal lcd(12, 11, 5, 4, 3, 2); + +void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(16, 2); + // Print a message to the LCD. + lcd.print("hello, world!"); +} + +void loop() { + // Turn off the display: + lcd.noDisplay(); + delay(500); + // Turn on the display: + lcd.display(); + delay(500); +} + diff --git a/libs/LiquidCrystal/examples/HelloWorld/HelloWorld.ino b/libs/LiquidCrystal/examples/HelloWorld/HelloWorld.ino new file mode 100644 index 0000000..e99957d --- /dev/null +++ b/libs/LiquidCrystal/examples/HelloWorld/HelloWorld.ino @@ -0,0 +1,58 @@ +/* + LiquidCrystal Library - Hello World + + Demonstrates the use a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch prints "Hello World!" to the LCD + and shows the time. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K resistor: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + + This example code is in the public domain. + + http://www.arduino.cc/en/Tutorial/LiquidCrystal + */ + +// include the library code: +#include + +// initialize the library with the numbers of the interface pins +LiquidCrystal lcd(12, 11, 5, 4, 3, 2); + +void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(16, 2); + // Print a message to the LCD. + lcd.print("hello, world!"); +} + +void loop() { + // set the cursor to column 0, line 1 + // (note: line 1 is the second row, since counting begins with 0): + lcd.setCursor(0, 1); + // print the number of seconds since reset: + lcd.print(millis()/1000); +} + diff --git a/libs/LiquidCrystal/examples/Scroll/Scroll.ino b/libs/LiquidCrystal/examples/Scroll/Scroll.ino new file mode 100644 index 0000000..0d6d8dc --- /dev/null +++ b/libs/LiquidCrystal/examples/Scroll/Scroll.ino @@ -0,0 +1,86 @@ +/* + LiquidCrystal Library - scrollDisplayLeft() and scrollDisplayRight() + + Demonstrates the use a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch prints "Hello World!" to the LCD and uses the + scrollDisplayLeft() and scrollDisplayRight() methods to scroll + the text. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K resistor: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + + This example code is in the public domain. + + http://arduino.cc/en/Tutorial/LiquidCrystalScroll + + */ + +// include the library code: +#include + +// initialize the library with the numbers of the interface pins +LiquidCrystal lcd(12, 11, 5, 4, 3, 2); + +void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(16, 2); + // Print a message to the LCD. + lcd.print("hello, world!"); + delay(1000); +} + +void loop() { + // scroll 13 positions (string length) to the left + // to move it offscreen left: + for (int positionCounter = 0; positionCounter < 13; positionCounter++) { + // scroll one position left: + lcd.scrollDisplayLeft(); + // wait a bit: + delay(150); + } + + // scroll 29 positions (string length + display length) to the right + // to move it offscreen right: + for (int positionCounter = 0; positionCounter < 29; positionCounter++) { + // scroll one position right: + lcd.scrollDisplayRight(); + // wait a bit: + delay(150); + } + + // scroll 16 positions (display length + string length) to the left + // to move it back to center: + for (int positionCounter = 0; positionCounter < 16; positionCounter++) { + // scroll one position left: + lcd.scrollDisplayLeft(); + // wait a bit: + delay(150); + } + + // delay at the end of the full loop: + delay(1000); + +} + diff --git a/libs/LiquidCrystal/examples/SerialDisplay/SerialDisplay.ino b/libs/LiquidCrystal/examples/SerialDisplay/SerialDisplay.ino new file mode 100644 index 0000000..a6f8f40 --- /dev/null +++ b/libs/LiquidCrystal/examples/SerialDisplay/SerialDisplay.ino @@ -0,0 +1,65 @@ +/* + LiquidCrystal Library - Serial Input + + Demonstrates the use a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch displays text sent over the serial port + (e.g. from the Serial Monitor) on an attached LCD. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K resistor: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + + This example code is in the public domain. + + http://arduino.cc/en/Tutorial/LiquidCrystalSerial + */ + +// include the library code: +#include + +// initialize the library with the numbers of the interface pins +LiquidCrystal lcd(12, 11, 5, 4, 3, 2); + +void setup(){ + // set up the LCD's number of columns and rows: + lcd.begin(16, 2); + // initialize the serial communications: + Serial.begin(9600); +} + +void loop() +{ + // when characters arrive over the serial port... + if (Serial.available()) { + // wait a bit for the entire message to arrive + delay(100); + // clear the screen + lcd.clear(); + // read all the available characters + while (Serial.available() > 0) { + // display each character to the LCD + lcd.write(Serial.read()); + } + } +} diff --git a/libs/LiquidCrystal/examples/TextDirection/TextDirection.ino b/libs/LiquidCrystal/examples/TextDirection/TextDirection.ino new file mode 100644 index 0000000..cabd8ea --- /dev/null +++ b/libs/LiquidCrystal/examples/TextDirection/TextDirection.ino @@ -0,0 +1,86 @@ + /* + LiquidCrystal Library - TextDirection + + Demonstrates the use a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch demonstrates how to use leftToRight() and rightToLeft() + to move the cursor. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K resistor: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + + This example code is in the public domain. + + http://arduino.cc/en/Tutorial/LiquidCrystalTextDirection + + */ + +// include the library code: +#include + +// initialize the library with the numbers of the interface pins +LiquidCrystal lcd(12, 11, 5, 4, 3, 2); + +int thisChar = 'a'; + +void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(16, 2); + // turn on the cursor: + lcd.cursor(); +} + +void loop() { + // reverse directions at 'm': + if (thisChar == 'm') { + // go right for the next letter + lcd.rightToLeft(); + } + // reverse again at 's': + if (thisChar == 's') { + // go left for the next letter + lcd.leftToRight(); + } + // reset at 'z': + if (thisChar > 'z') { + // go to (0,0): + lcd.home(); + // start again at 0 + thisChar = 'a'; + } + // print the character + lcd.write(thisChar); + // wait a second: + delay(1000); + // increment the letter: + thisChar++; +} + + + + + + + + diff --git a/libs/LiquidCrystal/examples/setCursor/setCursor.ino b/libs/LiquidCrystal/examples/setCursor/setCursor.ino new file mode 100644 index 0000000..e45c491 --- /dev/null +++ b/libs/LiquidCrystal/examples/setCursor/setCursor.ino @@ -0,0 +1,72 @@ +/* + LiquidCrystal Library - setCursor + + Demonstrates the use a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch prints to all the positions of the LCD using the + setCursor(0 method: + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K resistor: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + + This example code is in the public domain. + + http://arduino.cc/en/Tutorial/LiquidCrystalSetCursor + + */ + +// include the library code: +#include + +// these constants won't change. But you can change the size of +// your LCD using them: +const int numRows = 2; +const int numCols = 16; + +// initialize the library with the numbers of the interface pins +LiquidCrystal lcd(12, 11, 5, 4, 3, 2); + +void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(numCols,numRows); +} + +void loop() { + // loop from ASCII 'a' to ASCII 'z': + for (int thisLetter = 'a'; thisLetter <= 'z'; thisLetter++) { + // loop over the columns: + for (int thisCol = 0; thisCol < numRows; thisCol++) { + // loop over the rows: + for (int thisRow = 0; thisRow < numCols; thisRow++) { + // set the cursor position: + lcd.setCursor(thisRow,thisCol); + // print the letter: + lcd.write(thisLetter); + delay(200); + } + } + } +} + + diff --git a/libs/LiquidCrystal/keywords.txt b/libs/LiquidCrystal/keywords.txt new file mode 100644 index 0000000..132845c --- /dev/null +++ b/libs/LiquidCrystal/keywords.txt @@ -0,0 +1,37 @@ +####################################### +# Syntax Coloring Map For LiquidCrystal +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +LiquidCrystal KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +begin KEYWORD2 +clear KEYWORD2 +home KEYWORD2 +print KEYWORD2 +setCursor KEYWORD2 +cursor KEYWORD2 +noCursor KEYWORD2 +blink KEYWORD2 +noBlink KEYWORD2 +display KEYWORD2 +noDisplay KEYWORD2 +autoscroll KEYWORD2 +noAutoscroll KEYWORD2 +leftToRight KEYWORD2 +rightToLeft KEYWORD2 +scrollDisplayLeft KEYWORD2 +scrollDisplayRight KEYWORD2 +createChar KEYWORD2 + +####################################### +# Constants (LITERAL1) +####################################### + diff --git a/libs/pagerlib/pagerlib.c b/libs/pagerlib/pagerlib.c index 6817eaa..644e5e7 100644 --- a/libs/pagerlib/pagerlib.c +++ b/libs/pagerlib/pagerlib.c @@ -49,6 +49,7 @@ int rng (uint8_t *dest, unsigned size) { return 1; #else // arduino rng comes here + return 0; #endif } @@ -108,15 +109,19 @@ inline int pl_set_receiver(struct pl_ctx *ctx, struct pl_keypair *keypair) inline int pl_send_message(struct pl_ctx *ctx) { memset(ctx->shared_secret, 7, sizeof(ctx->shared_secret)); +// memset(ctx->msg->msg, 23, MSG_SIZE); +#ifndef ARDUINO /* create a random iv */ rng((char *)&ctx->msg->iv, sizeof(ctx->msg->iv)); +#else + memcpy(&ctx->msg->iv, &fakeiv, sizeof(ctx->msg->iv)); +#endif // copy compressed point into pager message memcpy(&ctx->msg->sender_compressed_point, &ctx->kp->compressed_point, sizeof(ctx->msg->sender_compressed_point)); //DBG("Sending message \n"); -#ifndef NOCRYPT /* decompress key */ uECC_decompress(ctx->receiver_compressed_point, ctx->decompressed_point, ctx->curve); @@ -141,7 +146,8 @@ inline int pl_send_message(struct pl_ctx *ctx) { ctx->aes_ctx = aes192_cbc_enc_start(&ctx->shared_secret, ctx->msg->iv); aes192_cbc_enc_continue(ctx->aes_ctx, ctx->msg->msg, MSG_SIZE); aes192_cbc_enc_finish(ctx->aes_ctx); - + memcpy(ctx->msg->msg, "not working??", MSG_SIZE); + #else mbedtls_aes_init( &ctx->aes_ctx ); @@ -159,7 +165,6 @@ inline int pl_send_message(struct pl_ctx *ctx) { mbedtls_aes_crypt_cbc( &ctx->aes_ctx, MBEDTLS_AES_ENCRYPT, MSG_SIZE, civ, (char *)&cmsg, (char *)&ctx->msg->msg ); mbedtls_aes_free (&ctx->aes_ctx); // DBG("message to send: %s \n ", ctx->msg); -#endif #endif /* @@ -173,6 +178,7 @@ inline int pl_send_message(struct pl_ctx *ctx) { */ // DBM("msg->msg in pl_send_message after crypt", sizeof(ctx->msg->msg), &ctx->msg->msg); // DBM("iv in pl_send_message after crypt", sizeof(ctx->msg->iv), &ctx->msg->iv); +// memcpy(&ctx->msg->msg, "not working?????????????????????????????????", 80); return 0; } @@ -185,7 +191,8 @@ inline int pl_receive_message(struct pl_ctx * ctx) // DBM("msg->msg in pl_receive_message before crypt", sizeof(ctx->msg->msg), &ctx->msg->msg); /* check if message is for us */ - struct list_kp * list; +#ifndef ARDUINO + struct list_kp * list; int found = 0; for(list = ctx->keypairs; list != NULL; list = list->next) { // printf("\n address in msg: %u address in list: %u \n", ctx->msg->address, list->id ); @@ -198,7 +205,7 @@ inline int pl_receive_message(struct pl_ctx * ctx) } // exit when address not found if (found == 0) return 0; - +#endif /* decompress the senders public key */ uECC_decompress(ctx->msg->sender_compressed_point, ctx->decompressed_point, ctx->curve); @@ -305,8 +312,10 @@ int pl_inbox_append(struct pl_ctx *ctx, struct pl_pagermessage *msg){ struct list_inbox *list, *ni, *last, *listprev; list = ctx->inbox; ctx->msgcount++; - printf("AP: count: %u", ctx->msgcount); +#ifndef ARDUINO + printf("AP: count: %u", ctx->msgcount); +#endif // make new list item ni = (struct list_inbox *) malloc( sizeof(struct list_inbox) ); ni->id = ctx->msgcount; @@ -338,6 +347,7 @@ int pl_inbox_append(struct pl_ctx *ctx, struct pl_pagermessage *msg){ } } } + return 1; } inline int pl_inbox_next(struct pl_ctx *ctx){ @@ -347,10 +357,11 @@ inline int pl_inbox_next(struct pl_ctx *ctx){ return 1; } else { +#ifndef ARDUINO printf("NEXT: already at last item \n"); +#endif return 0; } - } int pl_inbox_prev(struct pl_ctx *ctx){ @@ -361,7 +372,9 @@ int pl_inbox_prev(struct pl_ctx *ctx){ return 1; } else { +#ifndef ARDUINO printf("PREV: already at first item \n"); +#endif return 0; } } @@ -371,8 +384,10 @@ int pl_inbox_prev(struct pl_ctx *ctx){ int pl_inbox_delete(struct pl_ctx *ctx){ if (ctx->inbox_curr == NULL | ctx->inbox == NULL) { - printf("stomding"); - exit(1); + // make a inbox + + return 1; + } struct list_inbox * dm; @@ -405,10 +420,14 @@ int pl_inbox_display(struct pl_ctx *ctx) { if (ctx->inbox_curr != NULL) { struct list_inbox * list; list = ctx->inbox_curr; +#ifndef ARDUINO printf("m %u | from: %u to: %u %s \n", list->id , compressed_point_to_addr(list->msg->sender_compressed_point), list->msg->address, list->msg->msg ); +#endif return 1; } else { +#ifndef ARDUINO printf("DISPlAY: inbox is empty! \n"); +#endif return 0; } } @@ -416,10 +435,14 @@ int pl_inbox_display(struct pl_ctx *ctx) { int pl_inbox_display_all(struct pl_ctx *ctx) { struct list_inbox * list; int i = 0; +#ifndef ARDUINO printf("messages: \n "); +#endif for(list = ctx->inbox; list != NULL; list = list->next) { - printf("m %u | from: %u to: %u %s \n", list->id , compressed_point_to_addr(list->msg->sender_compressed_point), list->msg->address, list->msg->msg ); - i++; +#ifndef ARDUINO + printf("m %u | from: %u to: %u %s \n", list->id , compressed_point_to_addr(list->msg->sender_compressed_point), list->msg->address, list->msg->msg ); +#endif + i++; } } @@ -457,10 +480,13 @@ int pl_load_key_in_list(struct pl_ctx *ctx, struct pl_keypair *key){ int pl_print_keylist(struct pl_ctx *ctx) { struct list_kp * list; +#ifndef ARDUINO printf("the list of loaded keys: \n "); +#endif for(list = ctx->keypairs; list != NULL; list = list->next) { - printf("address in list: %u \n", list->id ); - +#ifndef ARDUINO + printf("address in list: %u \n", list->id ); +#endif } } diff --git a/libs/pagerlib/pagerlib.h b/libs/pagerlib/pagerlib.h index a1aa4d3..e5afcca 100644 --- a/libs/pagerlib/pagerlib.h +++ b/libs/pagerlib/pagerlib.h @@ -14,7 +14,7 @@ extern "C" #endif #include "../micro-ecc/uECC.h" - +#include "things.h" #ifdef ARDUINO #include @@ -27,13 +27,14 @@ extern "C" #endif #ifdef DEBUG - #define DBG(f_, ...) printf((f_), ##__VA_ARGS__); - #define DB(f_, ...) dump_buffer((f_), ##__VA_ARGS__); - #define DBM(f_, ...) dump_buffer_msg((f_), ##__VA_ARGS__); #ifdef ARDUINO // fixme arduino debug functions #define DBG #define DB #define DBM + #else + #define DBG(f_, ...) printf((f_), ##__VA_ARGS__); + #define DB(f_, ...) dump_buffer((f_), ##__VA_ARGS__); + #define DBM(f_, ...) dump_buffer_msg((f_), ##__VA_ARGS__); #endif #else // no debuging #define DBG -- GitLab