Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
avr-pager
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
yids
avr-pager
Commits
09df4daa
Commit
09df4daa
authored
Aug 28, 2016
by
yids
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of 185.52.224.4:yids/avr-pager
Conflicts: arduino-rx/Makefile
parents
5b50bcd9
e263b258
Changes
18
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
1499 additions
and
51 deletions
+1499
-51
arduino-rx/Makefile
arduino-rx/Makefile
+4
-1
arduino-rx/arduino-rx.ino
arduino-rx/arduino-rx.ino
+223
-32
base-tx/test.c
base-tx/test.c
+13
-1
libs/LiquidCrystal/LiquidCrystal.cpp
libs/LiquidCrystal/LiquidCrystal.cpp
+310
-0
libs/LiquidCrystal/LiquidCrystal.h
libs/LiquidCrystal/LiquidCrystal.h
+106
-0
libs/LiquidCrystal/examples/Autoscroll/Autoscroll.ino
libs/LiquidCrystal/examples/Autoscroll/Autoscroll.ino
+74
-0
libs/LiquidCrystal/examples/Blink/Blink.ino
libs/LiquidCrystal/examples/Blink/Blink.ino
+61
-0
libs/LiquidCrystal/examples/Cursor/Cursor.ino
libs/LiquidCrystal/examples/Cursor/Cursor.ino
+61
-0
libs/LiquidCrystal/examples/CustomCharacter/CustomCharacter.ino
...iquidCrystal/examples/CustomCharacter/CustomCharacter.ino
+138
-0
libs/LiquidCrystal/examples/Display/Display.ino
libs/LiquidCrystal/examples/Display/Display.ino
+61
-0
libs/LiquidCrystal/examples/HelloWorld/HelloWorld.ino
libs/LiquidCrystal/examples/HelloWorld/HelloWorld.ino
+58
-0
libs/LiquidCrystal/examples/Scroll/Scroll.ino
libs/LiquidCrystal/examples/Scroll/Scroll.ino
+86
-0
libs/LiquidCrystal/examples/SerialDisplay/SerialDisplay.ino
libs/LiquidCrystal/examples/SerialDisplay/SerialDisplay.ino
+65
-0
libs/LiquidCrystal/examples/TextDirection/TextDirection.ino
libs/LiquidCrystal/examples/TextDirection/TextDirection.ino
+86
-0
libs/LiquidCrystal/examples/setCursor/setCursor.ino
libs/LiquidCrystal/examples/setCursor/setCursor.ino
+72
-0
libs/LiquidCrystal/keywords.txt
libs/LiquidCrystal/keywords.txt
+37
-0
libs/pagerlib/pagerlib.c
libs/pagerlib/pagerlib.c
+39
-13
libs/pagerlib/pagerlib.h
libs/pagerlib/pagerlib.h
+5
-4
No files found.
arduino-rx/Makefile
View file @
09df4daa
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/ttyUSB1
#DEVICE_PATH = /dev/ttyUSB0
DEVICE_PATH
=
/tmp/simavr-uart0
TARGET
=
arduino-rx
arduino-rx/arduino-rx.ino
View file @
09df4daa
#include <stdarg.h>
#include <uECC.h>
#include <AESLib.h>
...
...
@@ -7,72 +8,262 @@
#include <SPI.h> // Not actualy used but needed to compile
#include <string.h>
#include <Wire.h>
#include <LCDI2C_LK162-12.h>
//
#include <LCDI2C_LK162-12.h>
#include <MemoryFree.h>
#include <pagerlib.h>
#include <LiquidCrystal.h>
#include <avr/pgmspace.h>
/*
#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
}
base-tx/test.c
View file @
09df4daa
...
...
@@ -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
)
{
...
...
libs/LiquidCrystal/LiquidCrystal.cpp
0 → 100644
View file @
09df4daa
#include "LiquidCrystal.h"
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#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
);
}