effect
As shown in the figure:
technological process
User login - > function selection - > corresponding function
thinking
-
For the use of the whole software, the acquisition of touch screen coordinate points is indispensable, so we open a separate thread to obtain touch screen coordinate points and run from beginning to end
-
Then, considering that there are two forms of password login, we have to open two threads to handle it. We can set a global variable whether to log in, and then cycle all the time when we don't log in, so the problem of login can be solved
-
Next is the function page. When the user logs in the interface, he will jump to the function selection page. What I do here is "order now" on the left and "historical order" on the right
-
For "order now", what we need to do is to add or reduce each commodity, and finally place an order. After placing an order, we will store the data of this order number in the corresponding file
-
For the "historical order", we need to pay attention to the storage, information processing and layout of the order number. I save trouble here, so only 10 records are displayed
-
Another is to create a thread to obtain temperature and humidity, and then display it in the upper left corner in real time after the user logs in
code
Main logic flow
In order to understand the process more clearly, I only show main C. please get the rest from Github https://github.com/MangataTS/GEC6818-project
If you can't open it, you can quickly download it from here: http://acm.mangata.ltd/file/2/project.zip
#include <stdio.h> #include <pthread.h> #include "picture.h" #include "getxy.h" #include "font.h" #include "UARTdh11.h" #include "RFID.h" #include <stdbool.h> #include <string.h> #include <termios.h> #include <stdlib.h> #include <time.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> #define true 1 #define false 0 #define PASSLEN 4 //************Material content************ char *number[]={//number "sucai/0.bmp", "sucai/1.bmp", "sucai/2.bmp", "sucai/3.bmp", "sucai/4.bmp", "sucai/5.bmp", "sucai/6.bmp", "sucai/7.bmp", "sucai/8.bmp", "sucai/9.bmp", }; char *del="sucai/del.bmp"; char *login="sucai/login.bmp"; char *background="sucai/back.bmp"; char *whiteblock="sucai/whiteblock.bmp"; char *shownumbers="sucai/shownumbers.bmp"; char *Error_login="sucai/errorlogin.bmp"; char *Login_Logo="sucai/login_logo.bmp"; char *NC[]={ "sucai/CMWZ.bmp", "sucai/FMYZC.bmp", "sucai/KKNC.bmp", "sucai/LMBH.bmp" }; char *JGB="sucai/JGB.bmp"; char *XIADAN="sucai/XDCN.bmp"; //************Material content************ int locpass=0; int tolid = 0; struct Good{ int value; int number; char name[20]; }; int IDok; //Identification default failed 0 failed 1 succeeded char a[20][40]; extern char WsdString[20]; void *Pcamera(void *arg); #if 1 //Initialization, read information from file void Message_init(){ FILE *fp_message = fopen("Message_table.txt","r"); if(fp_message == NULL) { fp_message = fopen("Message_table.txt","w"); fclose(fp_message); return; } char buf[40]; while(fgets(buf,40,fp_message)){//Read these order information strcpy(a[tolid++],buf); tolid %= 10;//Limit reading ten } fclose(fp_message); } //Display main interface void show_Main(){ show_anybmp(background,0,0);//background show_anybmp(Login_Logo,90,90);//logo Init_Font(); Display_characterX(300,0,"Whole milk tea",0x00D2691E,3); UnInit_Font(); //Display numeric keypad for(int x = 310,i = 1;i <= 3; ++i,x += 60){ for(int y = 240,j = 1;j <= 3; ++j,y += 60){ show_anybmp(number[(i-1)*3+j],x,y); } } show_anybmp(number[0],360,420);//Number 0 show_anybmp(del,590,240);//Delete key show_anybmp(login,590,340);//Login key show_anybmp(shownumbers,280,90);//Displays the number entered } //Order interface void show_Right(struct Good *goods){ Init_Font(); Clean_Area(0, 0, 800, 480, 0x00FFFFFF); printf("YES2\n"); show_anybmp(NC[0],250,0); show_anybmp(NC[1],500,0); show_anybmp(NC[2],250,240); show_anybmp(NC[3],500,240); show_anybmp(JGB,700,0); //The upper left corner of the item displays the quantity of the item char num[10]; Clean_Area(250,0,20,20,0x00FF0000); sprintf(num,"%d",goods[0].number); Display_characterX(250,0,num,0x00FFFFFF,1); Clean_Area(500,0,20,20,0x00FF0000); sprintf(num,"%d",goods[1].number); Display_characterX(500,0,num,0x00FFFFFF,1); Clean_Area(250,240,20,20,0x00FF0000); sprintf(num,"%d",goods[2].number); Display_characterX(250,240,num,0x00FFFFFF,1); Clean_Area(500,240,20,20,0x00FF0000); sprintf(num,"%d",goods[3].number); Display_characterX(500,240,num,0x00FFFFFF,1); //The upper left corner of the item displays the quantity of the item //logo? int sum_number = 0; int sum_value = 0; for(int i = 0;i < 4; ++i){ sum_number += goods[i].number;//Total quantity sum_value += goods[i].value * goods[i].number;//Total value } // Display_characterX(10,10, "temperature and humidity:", 0x00D2691E,2); Display_characterX(10,90,WsdString,0x00D2691E,2); Display_characterX(10,300,"number:",0x00D2691E,2); sprintf(num,"%d",sum_number); Display_characterX(120,300,num,0x00D2691E,2); Display_characterX(10,350,"total:",0x00D2691E,2); sprintf(num,"%d¥",sum_value); Display_characterX(120,350,num,0x00D2691E,2); Clean_Area(0,0,250,80,0x00FFD700);//Back button Display_characterX(65,20,"return",0x00FFFFFF,3); Clean_Area(0,400,250,80,0x00FFD700);//confirm button Display_characterX(10,420,"Confirm order",0x00FFFFFF,3); //quantity // Items in the upper left corner Clean_Area(250, 200, 199, 40, 0x00FFF0F5); Display_characterX(250,180,"-",0x00D2691E,5); Display_characterX(350,180,"+",0x00D2691E,5); // Items in the upper right corner Clean_Area(500, 200, 199, 40, 0x00FFF0F5); Display_characterX(500,180,"-",0x00D2691E,5); Display_characterX(600,180,"+",0x00D2691E,5); // Items in the lower left corner Clean_Area(250, 440, 199, 40, 0x00FFF0F5); Display_characterX(250,420,"-",0x00D2691E,5); Display_characterX(350,420,"+",0x00D2691E,5); // Items in the lower right corner Clean_Area(500, 440, 199, 40, 0x00FFF0F5); Display_characterX(500,420,"-",0x00D2691E,5); Display_characterX(600,420,"+",0x00D2691E,5); UnInit_Font(); } void Faild_login(){ show_anybmp(Error_login,100,90); sleep(1);//Sleep for 1s show_Main();//Clear the main interface locpass = 0;//Move the password pointer to the beginning } //Password thread int is_in(int x,int y,int startx,int starty,int endx,int endy){//Judge whether the touch point is within this point if(x >= startx && x <= endx && y >= starty && y<= endy){//If within this range, 1 is returned return 1; } return 0; } // void *Ppass(void *arg) { char password[4]; char *banzipassword="4399";//Built in password while(!IDok) { // printf("(%d,%d)\n",x,y); if(x == -1 || y == -1) continue; if(x > 590 && x < 690 && y > 240 && y < 300){//Click the delete box is_in(x,y,590,240,690,300) if(locpass == 0) {//Indicates that the password box is empty printf("The password box is empty!\n"); } else{//Delete operation locpass--; show_anybmp(whiteblock,280+60*locpass,90);//Overwrite previous position } x = y = 0; } else if(x > 590 && x < 690 && y > 340 && y < 400){//Click the login box is_in(x,y,590,340,690,400) if(locpass != 4){ printf("Password box is not full!\n"); } else{ int fg = true; for(int i = 0;i < PASSLEN; ++i) { if(password[i] != banzipassword[i]){ fg = false; } } if(fg) {//If so, display the reward picture printf("The password is correct!\n"); x = y = 0; IDok = 1; printf("Pass password authentication!\n"); } else {//If you're wrong printf("Wrong password!\n"); Faild_login(); } } x = y = -1; } else{ if(locpass == 4) {//The password box is full printf("The password box is full!\n"); } else{//Click the number box int locnumber; for(int XX = 310,i = 1;i <= 3; ++i,XX += 60){ for(int YY = 240,j = 1;j <= 3; ++j,YY += 60){ if(x > XX && x < (XX + 60) && y > YY && y < (YY + 60)){//is_in(x,y,XX,YY,XX+60,YY+60) locnumber = (i-1)*3+j; show_anybmp(number[locnumber],280+locpass*60,90);//Displays the number entered password[locpass++] = '0'+locnumber; } } } if(x > 360 && x < 420 && y > 420 && y < 480) {//Number 0 is_ in(x,y,360,420,420,480) locnumber = 0; show_anybmp(number[locnumber], 280 + locpass * 60, 90); password[locpass++] = '0' + locnumber; } } x = y = -1; } } pthread_exit(NULL); //Exit the thread } //RFID thread void *Prfid(void *arg) { //1. Open serial port device int fd = open("/dev/ttySAC1" , O_RDWR|O_NOCTTY); if(fd < 0) { perror ("open failed 1"); exit(0); } printf("fd = %d\n",fd); //2. Initialize serial port set_serial_uart(fd); char request[8] = {0}; get_Sjz(request); char fpz[9] = {0}; get_Fpz(fpz); char buf[10] = {0}; int ret; printf("[%d]\n", __LINE__); while(!IDok) { printf("[%d]\n", __LINE__); ret = write(fd, request, 7); printf("write ret = %d\n",ret); for(int i = 0;i < 7; ++i) { printf("%x",request[i]); } putchar('\n'); ret = read(fd, buf, 10); printf("read ret = %d\n",ret); printf("buf[2] = %x\n",buf[2]); printf("[%d]\n", __LINE__); if(ret > 0) { if(buf[2] == 0) { printf("Request succeeded\n"); write(fd, fpz, 8); ret = read(fd, buf, 10); if(ret > 0) { printf("Anti collision\n"); if(buf[0] == 0x0a && buf[2] == 0x00){ int cardid = (buf[7]<<24) | (buf[6] << 16) | (buf[5] << 8) | buf[4]; if(cardid == 0x3D458719){ IDok = 1; break; } printf("OX%X\n",cardid); printf("CARDID = 0x%x 0x%x 0x%x 0x%x\n",buf[7],buf[6],buf[5],buf[4]); sleep(2); } } } else { printf("request was aborted\n"); } } } printf("exit RFID*****************\n"); pthread_exit(NULL); //Exit the thread } //Single pop-up window void submit_table(struct Good *goods){//Submit page show_anybmp(XIADAN,200,40);//Display pictures of successful orders FILE* fd_table = fopen("Message_table.txt","w"); char buf[40]; memset(buf,0,sizeof buf); int value = 0; for(int i = 0;i < 4; ++i) value += goods[i].value * goods[i].number; time_t timep; struct tm *p; time(&timep); p = gmtime(&timep); char TIM[20]; sprintf(TIM,"date:%d-%d-%d ",(int)(1900+p->tm_year),(int)(1+p->tm_mon),(int)p->tm_mday); strcat(buf,TIM); char HF[20]; sprintf(HF,"cost: %d",value); strcat(buf,HF); printf("buf = %s \ntolid = %d\n",buf,tolid); strcpy(a[tolid++],buf); tolid%=10; for(int i = 0;i < 10; ++i) { if(strcmp(a[i],"")) fprintf(fd_table,"%s\n",a[i]); } fclose(fd_table); sleep(1);//Pause for 1s } void histoy_submit_table() { Init_Font(); Display_characterX(10,30,WsdString,0x00D2691E,2); Clean_Area(0, 0, 800, 480, 0x00FFE4E1);//Refresh background Display_characterX(280,0,"Historical order",0x00D2691E,4); Clean_Area(700, 0, 100, 80, 0x00DCDCDC);//Return box Display_characterX(690,15,"return",0x00D2691E,3); //This order is the five on the left int cnt = 0; for(int i = 0;i < 5; ++i) { if(strcmp(a[i],"\n") == 0 || strcmp(a[i],"") == 0) continue; a[i][strlen(a[i])-1] ='\0'; Display_characterX(0,80 + cnt * 80,a[i],0x00FFFFFF,2); cnt++; } for(int i = 5;i < 10; ++i) { a[i][strlen(a[i])-1] ='\0'; if(strcmp(a[i],"\n") == 0 || strcmp(a[i],"") == 0) continue; if(cnt < 5) { Display_characterX(0,80 + cnt * 80,a[i],0x00FFFFFF,2); } else { Display_characterX(400,80 + (cnt-5) * 80,a[i],0x00FFFFFF,2); } cnt++; } while(1){ Clean_Area(0, 0, 200, 80, 0x00FFE4E1);//Refresh background Display_characterX(10,30,WsdString,0x00D2691E,2); if(x > 700 && x < 800 && y > 0 && y < 80) {//Return box UnInit_Font(); return; } } } void show_check(){ Init_Font(); Clean_Area(0, 0, 400, 480, 0x00FFA500);//Left order Display_characterX(50,200,"Immediate order",0x00FF4500,4); Clean_Area(400, 0, 400, 480, 0x00AFEEEE);//Right historical order Display_characterX(450,200,"Historical order",0x00FF4500,4); UnInit_Font(); } #endif int main(int argc, char *argv[]) { IDok = 0; //Initialize device file Message_init();//Historical order lcd_init(); //LCD screen ts_init(); //touch screen //Start coordinate acquisition thread pthread_t coordTid; pthread_create(&coordTid, NULL, getxy, NULL); //Real time coordinate acquisition show_Main(); //Identity authentication: password identification or RFID pthread_t passTid, rfidTid, cameraTid, dht11Tid; pthread_create(&passTid, NULL, Ppass, NULL); //Create password thread pthread_create(&rfidTid, NULL, Prfid, NULL); //Create rfid thread pthread_create(&dht11Tid, NULL, funcTH, NULL); //Create dht11 thread - > temperature and humidity while(!IDok); //Until authentication is successful show_check(); while(1) { Init_Font(); Clean_Area(0, 0, 200, 80, 0x00FFA500);//Temperature and humidity Display_characterX(10,10,WsdString,0x00D2691E,2); UnInit_Font(); if(x > 0 && x < 400 && y > 0 && y < 480) {//Left entry point list x = y = -1; struct Good G[4]; memset(G,0,sizeof G); for(int i = 0;i < 4; ++i) G[i].number = 0; G[0].value = 13;//Strawberry balls G[1].value = 10;//Honey grapefruit G[2].value = 12;//Cocoa milk tea G[3].value = 11;//Lemon mint show_Right(G); while(1) { Init_Font(); Clean_Area(0, 80, 200, 80, 0x00FFFFFF);//Left order Display_characterX(10,90,WsdString,0x00D2691E,2); UnInit_Font(); if(x > 250 && x < 350 && y > 200 && y < 240) {//Delete in upper left corner printf("LEFT_UP_DEL\n"); if(G[0].number) G[0].number--; show_Right(G); x = y = -1; } else if(x > 350 && x < 450 && y > 200 && y < 240) {//Increase in upper left corner printf("LEFT_UP_ADD\n"); G[0].number++; show_Right(G); x = y = -1; } else if(x > 500 && x < 600 && y > 200 && y < 240) {//Delete in the upper right corner printf("RIGHT_UP_DEL\n"); if(G[1].number) G[1].number--; show_Right(G); x = y = -1; } else if(x > 600 && x < 700 && y > 200 && y < 240) {//Increase in upper right corner printf("RIGHT_UP_ADD\n"); G[1].number++; show_Right(G); x = y = -1; } else if(x > 250 && x < 350 && y > 440 && y < 480) {//Delete in the lower left corner printf("LEFT_DOWN_DEL\n"); if(G[2].number) G[2].number--; show_Right(G); x = y = -1; } else if(x > 350 && x < 450 && y > 440 && y < 480) {//Increase of left lower foot printf("LEFT_DOWN_ADD\n"); G[2].number++; show_Right(G); x = y = -1; } else if(x > 500 && x < 600 && y > 440 && y < 480) {//Delete in the lower right corner printf("LEFT_DOWN_DEL\n"); if(G[3].number) G[3].number--; show_Right(G); x = y = -1; } else if(x > 600 && x < 700 && y > 440 && y < 480) {//Increase in lower right corner printf("RIGHT_DOWN_ADD\n"); G[3].number++; show_Right(G); x = y = -1; } else if(x > 0 && x < 250 && y > 400 && y < 480) {//Demand for order submission printf("SUBMIT_S\n"); if(G[0].number + G[1].number + G[2].number + G[3].number == 0){//If it is not selected, it cannot be submitted x = y = -1; continue; } submit_table(G); show_Right(G); x = y = -1; } else if(x > 0 && x < 250 && y > 0 && y < 80) {//Return to the previous interface x = y = -1; show_check(); break; } } x = y = -1; } else if(x > 400 && x < 800 && y > 0 && y < 480){//Enter historical order x = y = -1; histoy_submit_table(); x = y = -1; show_check(); } } //Resource release lcd_close(); //LCD screen ts_close(); //touch screen return 0; }
There are many notes here. I believe you can understand them. I won't repeat them one by one
Some small pits
1. After obtaining coordinates every time, be sure to clear them, or manually assign a coordinate point that will not be used, otherwise it will continue to point
2. The serious problem is that the refresh frequency is too high
3. The coordinate points of the control must be planned in advance
4. This font The H font is slightly tilted, so don't try to correct it
5. My makefile has been modified. If you want to run directly, you have to change the makefile. You don't have to say how to change it
6. If the RFID module does not respond, the wire may be loose
7. The read function of RFID module thread is blocked. The reason is unknown
8. Look back