Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 28 additions & 25 deletions src/M5StackSAM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ void M5SAM::clearList(){
}

void M5SAM::addList(String inStr){
if(inStr.length()<=M5SAM_LIST_MAX_LABEL_SIZE and inStr.length()>0 and list_count < M5SAM_LIST_MAX_COUNT){
if(inStr.length()<=listMaxLabelSize and inStr.length()>0 and list_count < M5SAM_LIST_MAX_COUNT){
list_labels[list_count] = inStr;
list_count++;
}
if(list_count>0){
if(list_count > M5SAM_LIST_PAGE_LABELS){
list_lastpagelines = list_count % M5SAM_LIST_PAGE_LABELS;
if(list_count > listPagination){
list_lastpagelines = list_count % listPagination;
if(list_lastpagelines>0){
list_pages = (list_count - list_lastpagelines) / M5SAM_LIST_PAGE_LABELS;
list_pages = (list_count - list_lastpagelines) / listPagination;
list_pages++;
}else{
list_pages = list_count / M5SAM_LIST_PAGE_LABELS;
list_pages = list_count / listPagination;
}
}else{
list_pages = 1;
Expand All @@ -58,69 +58,72 @@ byte M5SAM::getListID(){
return list_idx;
}
void M5SAM::setListID(byte idx) {
if(idx< list_page * M5SAM_LIST_PAGE_LABELS + list_lines){
if(idx< list_page * listPagination + list_lines){
list_idx = idx;
}
list_page = list_idx / M5SAM_LIST_PAGE_LABELS;
list_page = list_idx / listPagination;
}

String M5SAM::getListString(){
return list_labels[list_idx];
}

void M5SAM::nextList( bool renderAfter ){
if(list_idx< list_page * M5SAM_LIST_PAGE_LABELS + list_lines - 1){
if(list_idx< list_page * listPagination + list_lines - 1){
list_idx++;
}else{
if(list_page<list_pages - 1){
list_page++;
}else{
list_page = 0;
}
list_idx = list_page * M5SAM_LIST_PAGE_LABELS;
list_idx = list_page * listPagination;
}
if( renderAfter ) showList();
}

void M5SAM::drawListItem(byte inIDX, byte postIDX){
if(inIDX==list_idx){
M5.Lcd.drawString(list_labels[inIDX],15,80+(postIDX*20),2);
M5.Lcd.drawString(">",3,80+(postIDX*20),2);
M5.Lcd.drawString(list_labels[inIDX],15,listPageLabelsOffset+(postIDX*20),2);
M5.Lcd.drawString(">",3,listPageLabelsOffset+(postIDX*20),2);
}else{
M5.Lcd.drawString(list_labels[inIDX],15,80+(postIDX*20),2);
M5.Lcd.drawString(list_labels[inIDX],15,listPageLabelsOffset+(postIDX*20),2);
}
}

void M5SAM::showList(){
windowClr();
byte labelid = 0;
M5.Lcd.drawCentreString(listCaption,M5.Lcd.width()/2,45,2);
M5.Lcd.setTextDatum( listCaptionDatum );
//M5.Lcd.drawCentreString(listCaption,M5.Lcd.width()/2,45,2);
M5.Lcd.drawString(listCaption, listCaptionXPos, listCaptionYPos, 2);
M5.Lcd.setTextDatum( TL_DATUM );
if((list_page + 1) == list_pages){
if(list_lastpagelines == 0 and list_count >= M5SAM_LIST_PAGE_LABELS){
list_lines = M5SAM_LIST_PAGE_LABELS;
for(byte i = 0;i<M5SAM_LIST_PAGE_LABELS;i++){
labelid = i+(list_page*M5SAM_LIST_PAGE_LABELS);
if(list_lastpagelines == 0 and list_count >= listPagination){
list_lines = listPagination;
for(byte i = 0;i<listPagination;i++){
labelid = i+(list_page*listPagination);
drawListItem(labelid,i);
}
}else{
if(list_pages>1){
list_lines = list_lastpagelines;
for(byte i = 0;i<list_lastpagelines;i++){
labelid = i+(list_page*M5SAM_LIST_PAGE_LABELS);
labelid = i+(list_page*listPagination);
drawListItem(labelid,i);
}
}else{
list_lines = list_count;
for(byte i = 0;i<list_count;i++){
labelid = i+(list_page*M5SAM_LIST_PAGE_LABELS);
labelid = i+(list_page*listPagination);
drawListItem(labelid,i);
}
}
}
}else{
list_lines = M5SAM_LIST_PAGE_LABELS;
for(byte i = 0;i<M5SAM_LIST_PAGE_LABELS;i++){
labelid = i+(list_page*M5SAM_LIST_PAGE_LABELS);
list_lines = listPagination;
for(byte i = 0;i<listPagination;i++){
labelid = i+(list_page*listPagination);
drawListItem(labelid,i);
}
}
Expand Down Expand Up @@ -148,7 +151,7 @@ void M5SAM::GoToLevel(byte inlevel){

void M5SAM::execute(){
if(menuList[levelIDX][menuIDX].gotoLevel==-1){
(*menuList[levelIDX][menuIDX].function)();
(*menuList[levelIDX][menuIDX].function)();
}else{
GoToLevel(menuList[levelIDX][menuIDX].gotoLevel);
}
Expand Down Expand Up @@ -229,7 +232,7 @@ void M5SAM::btnRestore(){
M5.Lcd.drawCentreString(lastBtnTittle[2],221+30,M5.Lcd.height()-28+6,2);
M5.Lcd.setTextColor(menutextcolor,windowcolor);
}

/*
void M5SAM::keyboardEnable(){
pinMode(5, INPUT);
attachInterrupt(digitalPinToInterrupt(5), keyboardIRQ, FALLING);
Expand All @@ -250,7 +253,7 @@ void M5SAM::keyboardIRQ(){
}
_keyboardIRQRcvd = HIGH;
}

*/
void M5SAM::drawMenu(String inmenuttl, String inbtnAttl, String inbtnBttl, String inbtnCttl, unsigned int inmenucolor, unsigned int inwindowcolor, unsigned int intxtcolor){
lastBtnTittle[0] = inbtnAttl;
lastBtnTittle[1] = inbtnBttl;
Expand Down
14 changes: 9 additions & 5 deletions src/M5StackSAM.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#include <M5Stack.h>

/*
// why was it even here ?
#if defined(WIRING) && WIRING >= 100
#include <Wiring.h>
#elif defined(ARDUINO) && ARDUINO >= 100
#include <Arduino.h>
#else
#include <WProgram.h>
#endif

*/
#ifndef M5StackSAM_h
#define M5StackSAM_h

Expand All @@ -18,8 +19,6 @@
#ifndef M5SAM_LIST_MAX_COUNT
#define M5SAM_LIST_MAX_COUNT 128
#endif
#define M5SAM_LIST_MAX_LABEL_SIZE 36
#define M5SAM_LIST_PAGE_LABELS 6

volatile static uint8_t _keyboardIRQRcvd;
volatile static uint8_t _keyboardChar;
Expand Down Expand Up @@ -48,6 +47,12 @@ class M5SAM {
void setListCaption(String inCaption);
String keyboardGetString();
String lastBtnTittle[3];
uint8_t listMaxLabelSize = 36; // list labels will be trimmed
uint8_t listPagination = 6;
uint8_t listPageLabelsOffset = 80; // initially 80, pixels offset from top screen for list items
uint8_t listCaptionDatum = TC_DATUM; // initially TC_DATUM=top centered, TL_DATUM=top left (default), top/right/bottom/left
uint16_t listCaptionXPos = 160; // initially M5.Lcd.width()/2, text cursor position-x for list caption
uint16_t listCaptionYPos = 45; // initially 45, text cursor position-x for list caption

private:
String listCaption;
Expand All @@ -66,7 +71,6 @@ class M5SAM {
char btnCtitle[M5SAM_BTN_TITLE_MAX_SIZE + 1];
signed char gotoLevel;
void (*function)();

};
String list_labels[M5SAM_LIST_MAX_COUNT];
byte list_lastpagelines;
Expand Down