forked from itead/ITEADLIB_Arduino_Nextion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NexUpload.h
executable file
·142 lines (126 loc) · 3.21 KB
/
NexUpload.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/**
* @file NexUpload.h
*
* The definition of class NexUpload.
*
* @author Chen Zengpeng (email:<zengpeng.chen@itead.cc>)
* @date 2016/3/29
*
* @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*/
#ifndef __NEXUPLOAD_H__
#define __NEXUPLOAD_H__
#include <Arduino.h>
#include <SPI.h>
#include <SD.h>
#include "NexHardware.h"
/**
* @addtogroup CoreAPI
* @{
*/
/**
*
* Provides the API for nextion to download the ftf file.
*/
class NexUpload
{
public: /* methods */
/**
* Constructor.
*
* @param file_name - tft file name.
* @param SD_chip_select - sd chip select pin.
* @param download_baudrate - set download baudrate.
*/
NexUpload(const char *file_name,const uint8_t SD_chip_select,uint32_t download_baudrate);
/**
* Constructor.
*
* @param file_Name - tft file name.
* @param SD_chip_select - sd chip select pin.
* @param download_baudrate - set download baudrate.
*/
NexUpload(const String file_Name,const uint8_t SD_chip_select,uint32_t download_baudrate);
/**
* destructor.
*
*/
~NexUpload(){}
/*
* start download.
*
* @return none.
*/
void upload();
private: /* methods */
/*
* get communicate baudrate.
*
* @return communicate baudrate.
*
*/
uint16_t _getBaudrate(void);
/*
* check tft file.
*
* @return true if success, false for failure.
*/
bool _checkFile(void);
/*
* search communicate baudrate.
*
* @param baudrate - communicate baudrate.
*
* @return true if success, false for failure.
*/
bool _searchBaudrate(uint32_t baudrate);
/*
* set download baudrate.
*
* @param baudrate - set download baudrate.
*
* @return true if success, false for failure.
*/
bool _setDownloadBaudrate(uint32_t baudrate);
/**
* start dowload tft file to nextion.
*
* @return none.
*/
bool _downloadTftFile(void);
/*
* Send command to Nextion.
*
* @param cmd - the string of command.
*
* @return none.
*/
void sendCommand(const char* cmd);
/*
* Receive string data.
*
* @param buffer - save string data.
* @param timeout - set timeout time.
* @param recv_flag - if recv_flag is true,will braak when receive 0x05.
*
* @return the length of string buffer.
*
*/
uint16_t recvRetString(String &string, uint32_t timeout = 100,bool recv_flag = false);
private: /* data */
uint32_t _baudrate; /*nextion serail baudrate*/
const char *_file_name; /*nextion tft file name*/
File _myFile; /*nextion ftf file*/
uint32_t _undownloadByte; /*undownload byte of tft file*/
uint8_t _SD_chip_select; /*sd chip select pin*/
uint32_t _download_baudrate; /*download baudrate*/
};
/**
* @}
*/
#endif /* #ifndef __NEXDOWNLOAD_H__ */