Hello help me please with the code =(. I can't include the button in the
menu. Look at the code. To me only to make that the cursor walked at
pushing. Thanks
code:
Hello help me please with the code =(. I can't include the button in the
menu. Look at the code. To me only to make that the cursor walked at
pushing. Thanks
code:
alexssey163:
Hello help me please with the code =(. I can't include the button in themenu. Look at the code. To me only to make that the cursor walked at
pushing. Thanks
code:
//==========================================
===========================
#include <WProgram.h>
#include <ks0108.h>//librerias for the LCD
#include <ks0108_Mega.h>
#include <SystemFont5x7.h>
#include <EEPROM.h>
#include <stdio.h>
#include <avr/pgmspace.h> //We store static arrays in flash
#define DISPSTR 4//Amount of the main lines of the display
#define FILENUMB 18 //Total quantity of files
#define FILEREW 4//Amount byte on each file
#define MAXDEPTH 3//the maximum depth ??????????? section
#define PROGV "v0.6c-RC1" //he program Version, is deduced in the
menu
int button1 = 2; // ?????? 1
int button2 = 3; // ?????? 2
int button3 = 4; // ?????? 3
int button4 = 5; // ?????? 4
byte butt;//stores the last pushed button
byte level;//stores level
volatile byte fileNumb=0;//Number of a current file
int workType=0;//he Flag of activity of this or that unit
volatile byte configLim[4];
byte brCrumbs[MAXDEPTH][2];//an array of grain crumbs.
Two-dimensional 1 byte - a turn of the programme, the second - a
cursor position
//an array of file structure
static byte fileStruct[FILENUMB*FILEREW] PROGMEM =
{
0,0,1,2,//a folder
1,0,0,0,//the program
2,0,0,0,//a config
3,0,2,15//a dynamic folder
};
//the Array of titles
prog_char file_0[] PROGMEM = "Folder";
prog_char file_1[] PROGMEM = "Programm";
prog_char file_2[] PROGMEM = "Config";
prog_char file_3[] PROGMEM = "Dyn Folder";
PROGMEM const char *fileNames[] = {
file_0,
file_1,
file_2,
file_3
};
char buffer[17]="MenuOS"; //n this variable we will store an element
title.
char buff[17];//n array storing current titles
byte fileData[4]; //and in this variable we will store element
parameters.
//an array of configs
PROGMEM static byte configsLimit[] = {
0,150,0//?????-?? ??????
};
//Data acquisition about a file
void fileGet(byte fnumb)//Data about a file. An input parameter - file
number
{
for (byte i=0;i<FILEREW;i++)
fileData=pgm_read_byte(&fileStruct[FILEREWfnumb+i]);//We read
out numerical values
strcpy_P(buffer, (char)pgm_read_word(&(fileNames[fnumb])));//we
Read out a title
}
void ConfigReadLimits(byte cnumb)//Data about a config. Input
???????? - config number
{
for (int i=0;i<3;i++)
configLim=pgm_read_byte(&configsLimit[cnumb3+i]);
_}_
_//Output agents of types of files*_
void programSelect()//??? ????? 0x01
{
workType=1;//Have included program cycling
dispStaticDraw(0);//We outline the screen
switch (fileData[2])
{ case 0://info about the program
dispHead("System info");
dispString(0,"MenuOS:");
dispString(1,PROGV);
dispString(2,"Kashkanov A.O.");
dispString(3,"http://rln.nnov.ru/");
delay(3000);
workType=0;
break;
}
fileReturn();
}
void configSelect(byte cnumb)//File type 0x02
{
workType=2;
ConfigReadLimits(cnumb);
while (workType==2)
{//We launch the program of editing of configs
ConfigDispStatic();
switch (buttonsStat())
{
case 3://button +
ConfigUpButton();
break;
case 1://button<
workType=0;//exist
break;
case 2:
ConfigDownButton();
break;
}
delay(200);
}
fileReturn();
}
void pageList()
{
dispStaticDraw(0);//We draw a statics
char buff[13];
char buff2[17];
byte currs;
if (!fileData[0])//
{
if ((brCrumbs[level][1]&B11111100)==(fileData[3]&B11111100))
currs=fileData[3]&B00000011;
else currs=3;
byte fstart=fileData[2]+(brCrumbs[level][1]&B11111100);//Number of
a file for output start.
for (byte i=0;i<=currs;i++)//We write from an array for static folders
{
strcpy_P(buff, (char*)pgm_read_word(&(fileNames[i+fstart])));//
dispString(i,buff);//We write from an array
}
}
else //
{
if ((brCrumbs[level][1]&B11111100)==(fileData[3]&B11111100))
currs=fileData[3]&B00000011;
else currs=3;
strcpy_P(buff,
(char*)pgm_read_word(&(fileNames[fileData[2]])));//?????? ?????
????????
for (byte i=0;i<=currs;i++)
{
sprintf(buff2, "%s %d", buff, (brCrumbs[level][1]&B11111100)+i);
dispString(i,buff2);
}
}
dispHead(buffer);
stringSelect();
}
//Output agents of buttons of the menu
void menuButtons(byte but)//
{
switch (but)
{
case 1://<
fileReturn();
break;
case 2://- And all that we should - change a cursor position
if (brCrumbs[level][1]>0) brCrumbs[level][1]--;
else brCrumbs[level][1]=fileData[3];//Have reached prior to the
*beginning, have begun with the end. *
pageList();//we outline the screen only when it is required
break;
case 3://+
if (brCrumbs[level][1]<fileData[3]) brCrumbs[level][1]++;
else brCrumbs[level][1]=0;//
pageList();
break;
case 4://>
fileSelect();
break;
}
delay(200);
}
void fileSelect()
{
if (!fileData[0])//
{
fileNumb=fileData[2]+brCrumbs[level][1];//We take number of a start
file and it is added how many we downwards have cracked.
}
else //The dynamic folder here is still easier
{
fileNumb=fileData[2];//
}
level++;//On level is deeper
brCrumbs[level][0]=fileNumb;//Have entered inside? Super, we will
write down ???? about our location.
fileGet(fileNumb);//we read out the information
byte fileType=fileData[0];//1 byte of a file Is readable
switch (fileType)//here it is added depending on file type.
{
case 0:
pageList();
break;
case 1:
programSelect();
break;
case 2:
configSelect(fileData[2]);
break;
case 3:
pageList();
break;
}
}
void fileReturn()
{
brCrumbs[level][0]=0;
brCrumbs[level][1]=0;
if (level>0) level--;//Being at level above, it is already possible to read
???? about the parent:
fileNumb=brCrumbs[level][0];//thus the cursor position isn't dropped!
We will return there, whence have come.
fileGet(fileNumb);//It is readable information about a file.
pageList();
}
//Operation with a drawing
void stringSelect()
{//Function highlights a line
byte curst=brCrumbs[level][1]&B00000011;//
GLCD.DrawRect(2, 18+8*curst, 5, 3, BLACK);//If our position, the black
cursor
}
void dispHead(char head[20])
{
GLCD.CursorTo(2,0);//
GLCD.Puts(head);//
}
void dispString(byte str, char textstr[17])
{
if ((str>=0) && (str<DISPSTR)){//Let's restrict operation area
GLCD.CursorTo(2,str+2);//
GLCD.Puts(textstr);//
}
}
void dispStaticDraw(byte buttons)//Draws separators, and buttons. The
general function for all units.
{
GLCD.ClearScreen();
GLCD.DrawHoriLine(0, 8, 127, BLACK);//he upper separator
GLCD.DrawHoriLine(0, 54, 127, BLACK);//The lower separator
GLCD.CursorTo(0,7);
switch (buttons)
{
case 0://Normal dial-up of buttons"< - + >"
GLCD.Puts(" < - + > ");//buttons
//Separators between buttons
buttSeparators(4);
break;
}
GLCD.InvertRect(0, 55, 127, 8 ) ;//Illumination of buttons
}
void buttSeparators(byte butt)
{
for (int i=1;i<butt;i++)
GLCD.DrawVertLine(30*i, 55, 8 , BLACK);
}
void setup()
{
pinMode(button1, INPUT); //I adjust ports of buttons on input
pinMode(button2, INPUT);
pinMode(button3, INPUT);
pinMode(button4, INPUT); //
digitalWrite(button1, HIGH); // include tightening resistors for buttons
to a broad gull "1"
digitalWrite(button2, HIGH);
digitalWrite(button3, HIGH);
digitalWrite(button4, HIGH);
DDRB=B00000000;
GLCD.Init(NON_INVERTED);
GLCD.ClearScreen();
GLCD.SelectFont(System5x7);
dispStaticDraw(0);
dispHead(buffer);
pageList();
}
void loop()
{
butt=buttonsStat();
if (butt)
{
dispStaticDraw(0);
dispHead(buffer);
menuButtons(butt);
delay(150);
}
}
alexssey163:
Hello help me please with the code =(. I can't include the button in themenu. Look at the code. To me only to make that the cursor walked at
pushing. Thanks
code:
Part 2/*==========================================
===================================
The general for all types of files the output agent of buttons. Returnspushed button number
============================================
=================================*/
byte buttonsStat()
{
byte button=0;
byte buttons=(~PINB)&B00001111;
if (buttons)
{
switch (buttons)
{
case 1://button +
button=3;
break;
case 2://button >
button=4;
break;
case 4://button <
button=1;
break;
case 8://button -
button=2;
break;
}
}
return button;
}/*==========================================
===================================
Code locations. Responsible for a config output:============================================
=================================*/
void ConfigUpButton()
{
if (configLim[1]==0)
{//
configLim[3]++;
}
else if (configLim[1]==1)
{//Means that variants only yes or not
configLim[3]=!configLim[3];
}
else{//
if (configLim[3]<configLim[1]) configLim[3]++;
else configLim[3]=configLim[0];
}
EEPROM.write(configLim[2],configLim[3]);}
void ConfigDownButton()
{
if (configLim[1]==0)
{//Means that without restrictionsif (configLim[3]>0) configLim[3]--;
else configLim[3]=0;
}
else if (configLim[1]==1)
{//Means that variants only yes or not
configLim[3]=!configLim[3];
}
else{//The changing:
if (configLim[3]>configLim[0]) configLim[3]--;
else configLim[3]=configLim[1];
}
EEPROM.write(configLim[2],configLim[3]);
}
void ConfigDispStatic()
{
GLCD.ClearScreen();
dispStaticDraw(0);
dispHead("Config redactor");
dispString(0,buffer);
if (configLim[1]==0)
{//Means that without restrictionsdispString(1,"Current: ");
configLim[3]=EEPROM.read(configLim[2]);
GLCD.PrintNumber(configLim[3]);
}
else if (configLim[1]==1)
{//Means that variants only yes or not
dispString(1,"Current: ");
configLim[3]=EEPROM.read(configLim[2]);
if (configLim[3]) GLCD.Puts("Yes");
else GLCD.Puts("No");
}
else{//The changing
dispString(1,"Minimum: ");
GLCD.CursorTo(11,3);//We put the cursor
GLCD.PrintNumber(configLim[0]);
dispString(2,"Maximum: ");
GLCD.CursorTo(11,4);//We put the cursor
GLCD.PrintNumber(configLim[1]);
dispString(3,"Current: ");
GLCD.CursorTo(11,5);//We put the cursor
configLim[3]=EEPROM.read(configLim[2]);
GLCD.PrintNumber(configLim[3]);
}
}