Commit 4cbf34cc authored by alaskalinuxuser's avatar alaskalinuxuser
Browse files

added button reading.

parent 4b98fe22
......@@ -56,7 +56,7 @@
#define FONA_RX 11 // Microcontroller TX
// this is a large buffer for replies
char replybuffer[255];
char replybuffer[180];
#include <SoftwareSerial.h>
SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
......@@ -64,10 +64,7 @@ SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
SoftwareSerial *fonaSerial = &fonaSS;
// Use this one for LTE CAT-M/NB-IoT modules (like SIM7000)
// Notice how we don't include the reset pin because it's reserved for emergencies on the LTE module!
#if defined(SIMCOM_7000) || defined(SIMCOM_7500)
Adafruit_FONA_LTE fona = Adafruit_FONA_LTE();
#endif
uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout = 0);
uint8_t type;
......@@ -81,8 +78,8 @@ char sendText[21];
// A custom glyph (Network Status)...
static const byte glyphN[] = { 0xe0, 0x00, 0xf8, 0x00, 0xfe };
int screenNumber = 2; // The menu screen number.
int menuNumber = 0; // The selected menu item.
int screenNumber = 1; // The menu screen number.
int menuNumber = 285; // The selected menu item.
int updateScreen = 0; // A counter to update the screen.
int numLetter = 0;
static PCD8544 lcd;
......@@ -101,21 +98,25 @@ int adc_key_in = 0;
#define btnNONE 6
int read_LCD_buttons(){ // read the 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
// We make this the 1st option for speed reasons since it will be the most likely result
if (adc_key_in > 1000) return btnNONE;
// For V1.1 us this threshold
if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 150) return btnUP;
if (adc_key_in < 400) return btnDOWN;
if (adc_key_in < 550) return btnLEFT;
if (adc_key_in < 750) return btnSELECT;
if (adc_key_in < 900) return btnBACK;
adc_key_in = 0;
//adc_key_in = analogRead(A0); // read the value from the sensor
Serial.print("anolog0:"); Serial.println(adc_key_in);
if (adc_key_in > 550) return btnRIGHT;
//adc_key_in = analogRead(A1); // read the value from the sensor
Serial.print("anolog1:"); Serial.println(adc_key_in);
if (adc_key_in > 550) return btnUP;
adc_key_in = analogRead(A2); // read the value from the sensor
Serial.print("anolog2:"); Serial.println(adc_key_in);
if (adc_key_in > 550) return btnDOWN;
adc_key_in = analogRead(A3); // read the value from the sensor
Serial.print("anolog3:"); Serial.println(adc_key_in);
if (adc_key_in > 550) return btnLEFT;
adc_key_in = analogRead(A4); // read the value from the sensor
Serial.print("anolog4:"); Serial.println(adc_key_in);
if (adc_key_in > 550) return btnSELECT;
adc_key_in = analogRead(A5); // read the value from the sensor
Serial.print("anolog5:"); Serial.println(adc_key_in);
if (adc_key_in > 550) return btnBACK;
return btnNONE; // when all others fail, return this.
}
......@@ -180,7 +181,7 @@ void setup() {
//fona.enableSleepMode(true);
//fona.set_eDRX(1, 4, "0010");
//fona.enablePSM(true);
fona.setNetLED(true, 2, 64, 3000); // on/off, mode, timer_on, timer_off
//fona.setNetLED(true, 2, 64, 3000); // on/off, mode, timer_on, timer_off
printMenu();
}
......@@ -189,11 +190,9 @@ void printMenu(void) {
Serial.println(F("Print [m]enu"));
Serial.println(F("Read SIM [C]CID"));
Serial.println(F("[U]nlock SIM"));
Serial.println(F("S[i]gnal strength (RSSI)"));
Serial.println(F("Network in[f]o"));
Serial.println(F("[N]umber of SMS's"));
Serial.println(F("[r]ead SMS #"));
Serial.println(F("[R]ead all SMS"));
Serial.println(F("[d]elete SMS #"));
Serial.println(F("[s]end SMS"));
Serial.println(F("Network [t]ime")); // Works just by being connected to network
......@@ -201,7 +200,6 @@ void printMenu(void) {
Serial.println(F("[g] Disable cellular data"));
Serial.println(F("Read [w]ebpage"));
Serial.println(F("Post to [W]ebsite"));
Serial.println(F("[P]ost to dweet.io via LTE CAT-M")); // This can be SIM800/808/900/7000
Serial.println(F("GPS [O]n"));
Serial.println(F("GPS [o]ff"));
Serial.println(F("[L]ocation"));
......@@ -211,6 +209,10 @@ void printMenu(void) {
void loop() {
//Get the time.
char buffer[23];
fona.getTime(buffer, 23);
//*********************** Status Bar ******************
// Build the information bar.
if (updateScreen == 0) {
......@@ -256,6 +258,7 @@ void loop() {
updateScreen++;
} else if (updateScreen == 10000) {
updateScreen = -1;
} else {
updateScreen++;
delay(1);
......@@ -267,9 +270,20 @@ void loop() {
}
//*********************** Screen updates ******************
// Clear the display....
lcd.setCursor(0, 1);
lcd.print(" ");
lcd.setCursor(0, 2);
lcd.print(" ");
lcd.setCursor(0, 3);
lcd.print(" ");
lcd.setCursor(0, 4);
lcd.print(" ");
lcd.setCursor(0, 5);
lcd.print(" ");
switch (screenNumber){
case 1:{
case 1:{ // Main screen
lcd.setCursor(0, 1);
lcd.print("TEXT");
lcd.setCursor(0, 2);
......@@ -277,12 +291,10 @@ void loop() {
lcd.setCursor(0, 3);
lcd.print("PROGRAMS");
lcd.setCursor(0, 4);
char buffer[23];
fona.getTime(buffer, 23);
lcd.print(" ");lcd.print(buffer);
break;
}
case 2:{
case 2:{ // Location screen
lcd.setCursor(0, 1);
lcd.print("SEND LOCATION");
lcd.setCursor(0, 2);
......@@ -291,13 +303,135 @@ void loop() {
lcd.print(gpsdata);} else { lcd.print("Turn on GPS.");}
break;
}
case 3:{ // GPS screen
lcd.setCursor(0, 1);
lcd.print("VIEW LOCATION");
lcd.setCursor(0, 2);
lcd.print("COMPASS");
lcd.setCursor(0, 3);
lcd.print("GPS ON");
lcd.setCursor(0, 4);
lcd.print("GPS OFF");
break;
}
case 4:{ // Compass screen // TODO: Make Compass work
lcd.setCursor(0, 4);
lcd.print("MAIN MENU");
break;
}
case 5:{ // Phone send number screen. // TODO: make this work.
lcd.setCursor(0, 1);
lcd.print("SEND TO: ");
lcd.setCursor(0, 4);
lcd.print("-SELECT TO SEND-");
break;
}
case 6:{ // SMS screen
lcd.setCursor(0, 1);
lcd.print("READ SMS");
lcd.setCursor(0, 2);
lcd.print("SEND SMS");
lcd.setCursor(0, 3);
lcd.print("DELETE ALL SMS");
lcd.setCursor(0, 4);
lcd.print(" ");
break;
}
case 7:{ // Type message screen // TODO: make this work.
lcd.setCursor(0, 1);
lcd.print("TYPE MESSAGE:");
lcd.setCursor(0, 4);
lcd.print("-SELECT TO SEND-");
break;
}
case 8:{ // Delete all messages screen.
lcd.setCursor(0, 1);
lcd.print("DELETE ALL");
lcd.setCursor(0, 2);
lcd.print("MESSAGES?");
lcd.setCursor(0, 3);
lcd.print(" NO");
lcd.setCursor(0, 4);
lcd.print(" YES");
break;
}
case 9:{ // View all messages screen // TODO: make this work.
lcd.setCursor(0, 4);
lcd.print("-SELECT TO SCROLL-");
break;
}
case 10:{ // Read message screen // TODO: make this work.
lcd.setCursor(0, 3);
lcd.print("-REPLY");
lcd.setCursor(0, 4);
lcd.print("-DELETE");
break;
}
case 11:{ // Delete message screen
lcd.setCursor(0, 1);
lcd.print("DELETE");
lcd.setCursor(0, 2);
lcd.print("MESSAGE?");
lcd.setCursor(0, 3);
lcd.print(" NO");
lcd.setCursor(0, 4);
lcd.print(" YES");
break;
}
case 12:{ // Programs screen
lcd.setCursor(0, 1);
lcd.print("LINEMODE BROWSER");
lcd.setCursor(0, 2);
lcd.print("GAMES");
lcd.setCursor(0, 3);
lcd.print("SETTINGS");
break;
}
case 13:{ // Settings screen
lcd.setCursor(0, 1);
lcd.print("NETWORK");
lcd.setCursor(0, 2);
lcd.print("SCREEN");
break;
}
case 14:{ // Network Settings screen
lcd.setCursor(0, 1);
lcd.print("DATA ON");
lcd.setCursor(0, 2);
lcd.print("DATA OFF");
lcd.setCursor(0, 3);
lcd.print("NET INFO");
break;
}
case 15:{ // Network info screen
/* read the RSSI
uint8_t n = fona.getRSSI();
int8_t r;
Serial.print(F("RSSI = ")); Serial.print(n); Serial.print(": ");
if (n == 0) r = -115;
if (n == 1) r = -111;
if (n == 31) r = -52;
if ((n >= 2) && (n <= 30)) {
r = map(n, 2, 30, -110, -54);
}*/
fona.getNetworkInfo();
lcd.setCursor(0, 1);
lcd.print(replybuffer);
lcd.setCursor(0, 4);
lcd.print("MAIN MENU");
break;
}
}
//*********************** Screen updates ******************
//*********************** Button Reading ******************
lcd_key = read_LCD_buttons(); // read the buttons
int waiting = 0;
while ( waiting < 3000 ){
waiting++;
delay(1);
switch (lcd_key){
case btnRIGHT:{
......@@ -325,6 +459,7 @@ void loop() {
break;
}
}
}
//*********************** Button Reading ******************
......@@ -561,23 +696,6 @@ void checkSerialConn() {
break;
}
case 'i': {
// read the RSSI
uint8_t n = fona.getRSSI();
int8_t r;
Serial.print(F("RSSI = ")); Serial.print(n); Serial.print(": ");
if (n == 0) r = -115;
if (n == 1) r = -111;
if (n == 31) r = -52;
if ((n >= 2) && (n <= 30)) {
r = map(n, 2, 30, -110, -54);
}
Serial.print(r); Serial.println(F(" dBm"));
break;
}
case 'f': {
// Get connection type, cellular band, carrier name, etc.
fona.getNetworkInfo();
......@@ -612,35 +730,6 @@ void checkSerialConn() {
break;
}
case 'R': {
// read all SMS
int8_t smsnum = fona.getNumSMS();
uint16_t smslen;
int8_t smsn;
smsn = 0; // 1 indexed
for ( ; smsn < smsnum; smsn++) {
Serial.print(F("\n\rReading SMS #")); Serial.println(smsn);
if (!fona.readSMS(smsn, replybuffer, 250, &smslen)) { // pass in buffer and max len!
Serial.println(F("F!"));
break;
}
// if the length is zero, its a special case where the index number is higher
// so increase the max we'll look at!
if (smslen == 0) {
Serial.println(F("[empty slot]"));
smsnum++;
continue;
}
Serial.print(F("***** SMS #")); Serial.print(smsn);
Serial.print(" ("); Serial.print(smslen); Serial.println(F(") bytes *****"));
Serial.println(replybuffer);
Serial.println(F("*****"));
}
break;
}
case 'd': {
// delete an SMS
......@@ -710,7 +799,7 @@ void checkSerialConn() {
char gpsdata[120];
fona.getGPS(0, gpsdata, 120);
Serial.println(F("Reply in format: mode,fixstatus,utctime(yyyymmddHHMMSS),latitude,longitude,altitude,speed,course,fixmode,reserved1,HDOP,PDOP,VDOP,reserved2,view_satellites,used_satellites,reserved3,C/N0max,HPA,VPA"));
Serial.println(F("mode,fixstat,time(yyyymmddHHMMSS),lat,long,alt,spd,crse,fixmode,reserved1,HDOP,PDOP,VDOP,reserved2,view_sats,used_sats,reserved3,C/N0max,HPA,VPA"));
Serial.println(gpsdata);
......
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