![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
EA EPAPER
Dependencies: BurstSPI EaEpaper SDFileSystem frdm_tsi_slider mbed
main.cpp@0:41e5a06d916f, 2015-04-20 (annotated)
- Committer:
- jendo1969
- Date:
- Mon Apr 20 11:47:36 2015 +0000
- Revision:
- 0:41e5a06d916f
EPAPER
;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jendo1969 | 0:41e5a06d916f | 1 | #include "mbed.h" |
jendo1969 | 0:41e5a06d916f | 2 | #include "EaEpaper.h" |
jendo1969 | 0:41e5a06d916f | 3 | #include "SDFileSystem.h" |
jendo1969 | 0:41e5a06d916f | 4 | #include "tsi_sensor.h" |
jendo1969 | 0:41e5a06d916f | 5 | #include "img0.h" |
jendo1969 | 0:41e5a06d916f | 6 | |
jendo1969 | 0:41e5a06d916f | 7 | #include <string> |
jendo1969 | 0:41e5a06d916f | 8 | #include <vector> |
jendo1969 | 0:41e5a06d916f | 9 | |
jendo1969 | 0:41e5a06d916f | 10 | /* This defines will be replaced by PinNames soon */ |
jendo1969 | 0:41e5a06d916f | 11 | #if defined (TARGET_KL25Z) || defined (TARGET_KL46Z) |
jendo1969 | 0:41e5a06d916f | 12 | #define ELEC0 9 |
jendo1969 | 0:41e5a06d916f | 13 | #define ELEC1 10 |
jendo1969 | 0:41e5a06d916f | 14 | #elif defined (TARGET_KL05Z) |
jendo1969 | 0:41e5a06d916f | 15 | #define ELEC0 9 |
jendo1969 | 0:41e5a06d916f | 16 | #define ELEC1 8 |
jendo1969 | 0:41e5a06d916f | 17 | #else |
jendo1969 | 0:41e5a06d916f | 18 | #error TARGET NOT DEFINED |
jendo1969 | 0:41e5a06d916f | 19 | #endif |
jendo1969 | 0:41e5a06d916f | 20 | |
jendo1969 | 0:41e5a06d916f | 21 | EaEpaper epaper(PTD7, // PWR_CTRL |
jendo1969 | 0:41e5a06d916f | 22 | PTD6, // BORDER |
jendo1969 | 0:41e5a06d916f | 23 | PTE31, // DISCHARGE |
jendo1969 | 0:41e5a06d916f | 24 | PTA17, // RESET_DISP |
jendo1969 | 0:41e5a06d916f | 25 | PTA16, // BUSY |
jendo1969 | 0:41e5a06d916f | 26 | PTC17, // SSEL |
jendo1969 | 0:41e5a06d916f | 27 | PTD4, // PWM |
jendo1969 | 0:41e5a06d916f | 28 | PTD2,PTD3,PTD1, // MOSI,MISO,SCLK |
jendo1969 | 0:41e5a06d916f | 29 | // PTE0,PTE1); // SDA,SDL |
jendo1969 | 0:41e5a06d916f | 30 | PTC11,PTC10); // SDA,SDL |
jendo1969 | 0:41e5a06d916f | 31 | |
jendo1969 | 0:41e5a06d916f | 32 | //SDFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name); |
jendo1969 | 0:41e5a06d916f | 33 | SDFileSystem sd(PTE1, PTE3, PTE2, PTE4, "sd" ); |
jendo1969 | 0:41e5a06d916f | 34 | |
jendo1969 | 0:41e5a06d916f | 35 | //Serial pc(USBTX,USBRX); |
jendo1969 | 0:41e5a06d916f | 36 | |
jendo1969 | 0:41e5a06d916f | 37 | vector<string> filenames; //filenames are stored in a vector string |
jendo1969 | 0:41e5a06d916f | 38 | |
jendo1969 | 0:41e5a06d916f | 39 | extern uint8_t _newImage[EA_IMG_BUF_SZ]; |
jendo1969 | 0:41e5a06d916f | 40 | |
jendo1969 | 0:41e5a06d916f | 41 | Bitmap bitmARM0 = { |
jendo1969 | 0:41e5a06d916f | 42 | 264, // XSize |
jendo1969 | 0:41e5a06d916f | 43 | 176, // YSize |
jendo1969 | 0:41e5a06d916f | 44 | 33, // Bytes in Line |
jendo1969 | 0:41e5a06d916f | 45 | (char*)img0_bits // Pointer to picture data |
jendo1969 | 0:41e5a06d916f | 46 | }; |
jendo1969 | 0:41e5a06d916f | 47 | |
jendo1969 | 0:41e5a06d916f | 48 | char img_bits[5808]; |
jendo1969 | 0:41e5a06d916f | 49 | Bitmap bitmIMG0 = { |
jendo1969 | 0:41e5a06d916f | 50 | 264, // XSize |
jendo1969 | 0:41e5a06d916f | 51 | 176, // YSize |
jendo1969 | 0:41e5a06d916f | 52 | 33, // Bytes in Line |
jendo1969 | 0:41e5a06d916f | 53 | img_bits // Pointer to picture data |
jendo1969 | 0:41e5a06d916f | 54 | }; |
jendo1969 | 0:41e5a06d916f | 55 | |
jendo1969 | 0:41e5a06d916f | 56 | void read_file_names(char *dir) |
jendo1969 | 0:41e5a06d916f | 57 | { |
jendo1969 | 0:41e5a06d916f | 58 | DIR *dp; |
jendo1969 | 0:41e5a06d916f | 59 | struct dirent *dirp; |
jendo1969 | 0:41e5a06d916f | 60 | dp = opendir(dir); |
jendo1969 | 0:41e5a06d916f | 61 | //read all directory and file names in current directory into filename vector |
jendo1969 | 0:41e5a06d916f | 62 | while((dirp = readdir(dp)) != NULL) { |
jendo1969 | 0:41e5a06d916f | 63 | filenames.push_back(string(dirp->d_name)); |
jendo1969 | 0:41e5a06d916f | 64 | } |
jendo1969 | 0:41e5a06d916f | 65 | closedir(dp); |
jendo1969 | 0:41e5a06d916f | 66 | } |
jendo1969 | 0:41e5a06d916f | 67 | |
jendo1969 | 0:41e5a06d916f | 68 | int read_filedata(char* fname) |
jendo1969 | 0:41e5a06d916f | 69 | { |
jendo1969 | 0:41e5a06d916f | 70 | char buf[128]; |
jendo1969 | 0:41e5a06d916f | 71 | char sbuf[10]; |
jendo1969 | 0:41e5a06d916f | 72 | int line_idx, idx, len, i,j; |
jendo1969 | 0:41e5a06d916f | 73 | uint8_t val; |
jendo1969 | 0:41e5a06d916f | 74 | |
jendo1969 | 0:41e5a06d916f | 75 | int ret = 0; |
jendo1969 | 0:41e5a06d916f | 76 | |
jendo1969 | 0:41e5a06d916f | 77 | // strcpy(path, "/sd"); |
jendo1969 | 0:41e5a06d916f | 78 | // strcat(path, fname); |
jendo1969 | 0:41e5a06d916f | 79 | |
jendo1969 | 0:41e5a06d916f | 80 | // pc.printf("PATH = %s\n", path); |
jendo1969 | 0:41e5a06d916f | 81 | |
jendo1969 | 0:41e5a06d916f | 82 | FILE *fp = fopen(fname, "r"); |
jendo1969 | 0:41e5a06d916f | 83 | if(fp == NULL) |
jendo1969 | 0:41e5a06d916f | 84 | { |
jendo1969 | 0:41e5a06d916f | 85 | // pc.printf("Could not open file for write\n"); |
jendo1969 | 0:41e5a06d916f | 86 | ret = 1; |
jendo1969 | 0:41e5a06d916f | 87 | return ret; |
jendo1969 | 0:41e5a06d916f | 88 | } |
jendo1969 | 0:41e5a06d916f | 89 | |
jendo1969 | 0:41e5a06d916f | 90 | line_idx = 0; |
jendo1969 | 0:41e5a06d916f | 91 | idx = 0; |
jendo1969 | 0:41e5a06d916f | 92 | |
jendo1969 | 0:41e5a06d916f | 93 | // while( fgets(buf, sizeof(buf), fp) != NULL ) |
jendo1969 | 0:41e5a06d916f | 94 | for(j=0;j<484;j++) |
jendo1969 | 0:41e5a06d916f | 95 | { |
jendo1969 | 0:41e5a06d916f | 96 | fgets(buf, sizeof(buf), fp); |
jendo1969 | 0:41e5a06d916f | 97 | line_idx++; |
jendo1969 | 0:41e5a06d916f | 98 | |
jendo1969 | 0:41e5a06d916f | 99 | // pc.printf("line=%d:%s", line_idx, buf); |
jendo1969 | 0:41e5a06d916f | 100 | |
jendo1969 | 0:41e5a06d916f | 101 | if(line_idx == 1) |
jendo1969 | 0:41e5a06d916f | 102 | { |
jendo1969 | 0:41e5a06d916f | 103 | if(strstr(buf,"264") == NULL ) |
jendo1969 | 0:41e5a06d916f | 104 | { |
jendo1969 | 0:41e5a06d916f | 105 | ret = 1; |
jendo1969 | 0:41e5a06d916f | 106 | break; |
jendo1969 | 0:41e5a06d916f | 107 | } |
jendo1969 | 0:41e5a06d916f | 108 | } |
jendo1969 | 0:41e5a06d916f | 109 | if(line_idx == 2) |
jendo1969 | 0:41e5a06d916f | 110 | { |
jendo1969 | 0:41e5a06d916f | 111 | if(strstr(buf,"176") == NULL ) |
jendo1969 | 0:41e5a06d916f | 112 | { |
jendo1969 | 0:41e5a06d916f | 113 | ret = 1; |
jendo1969 | 0:41e5a06d916f | 114 | break; |
jendo1969 | 0:41e5a06d916f | 115 | } |
jendo1969 | 0:41e5a06d916f | 116 | } |
jendo1969 | 0:41e5a06d916f | 117 | if(line_idx == 3) |
jendo1969 | 0:41e5a06d916f | 118 | { |
jendo1969 | 0:41e5a06d916f | 119 | continue; |
jendo1969 | 0:41e5a06d916f | 120 | } |
jendo1969 | 0:41e5a06d916f | 121 | |
jendo1969 | 0:41e5a06d916f | 122 | len = strlen(buf); |
jendo1969 | 0:41e5a06d916f | 123 | |
jendo1969 | 0:41e5a06d916f | 124 | for(i=0;i<len;i++) |
jendo1969 | 0:41e5a06d916f | 125 | { |
jendo1969 | 0:41e5a06d916f | 126 | if(buf[i] == ',') |
jendo1969 | 0:41e5a06d916f | 127 | { |
jendo1969 | 0:41e5a06d916f | 128 | strncpy(sbuf, &buf[i-4], 4); |
jendo1969 | 0:41e5a06d916f | 129 | /* 型変換 */ |
jendo1969 | 0:41e5a06d916f | 130 | sscanf(sbuf, "%x", &val); |
jendo1969 | 0:41e5a06d916f | 131 | img_bits[idx] = val; |
jendo1969 | 0:41e5a06d916f | 132 | idx++; |
jendo1969 | 0:41e5a06d916f | 133 | // i=i+4; |
jendo1969 | 0:41e5a06d916f | 134 | } |
jendo1969 | 0:41e5a06d916f | 135 | else if(buf[i] == '}') |
jendo1969 | 0:41e5a06d916f | 136 | { |
jendo1969 | 0:41e5a06d916f | 137 | strncpy(sbuf, &buf[i-5], 4); |
jendo1969 | 0:41e5a06d916f | 138 | /* 型変換 */ |
jendo1969 | 0:41e5a06d916f | 139 | sscanf(sbuf, "%x", &val); |
jendo1969 | 0:41e5a06d916f | 140 | img_bits[idx] = val; |
jendo1969 | 0:41e5a06d916f | 141 | idx++; |
jendo1969 | 0:41e5a06d916f | 142 | } |
jendo1969 | 0:41e5a06d916f | 143 | else if(buf[i] == 0x0D) |
jendo1969 | 0:41e5a06d916f | 144 | { |
jendo1969 | 0:41e5a06d916f | 145 | break; |
jendo1969 | 0:41e5a06d916f | 146 | } |
jendo1969 | 0:41e5a06d916f | 147 | } |
jendo1969 | 0:41e5a06d916f | 148 | } |
jendo1969 | 0:41e5a06d916f | 149 | |
jendo1969 | 0:41e5a06d916f | 150 | fclose(fp); |
jendo1969 | 0:41e5a06d916f | 151 | |
jendo1969 | 0:41e5a06d916f | 152 | return ret; |
jendo1969 | 0:41e5a06d916f | 153 | } |
jendo1969 | 0:41e5a06d916f | 154 | |
jendo1969 | 0:41e5a06d916f | 155 | int main() |
jendo1969 | 0:41e5a06d916f | 156 | { |
jendo1969 | 0:41e5a06d916f | 157 | char str1[17]; |
jendo1969 | 0:41e5a06d916f | 158 | int i; |
jendo1969 | 0:41e5a06d916f | 159 | |
jendo1969 | 0:41e5a06d916f | 160 | // pc.printf("\nHello World!\n"); |
jendo1969 | 0:41e5a06d916f | 161 | |
jendo1969 | 0:41e5a06d916f | 162 | TSIAnalogSlider tsi(ELEC0, ELEC1, 40); |
jendo1969 | 0:41e5a06d916f | 163 | |
jendo1969 | 0:41e5a06d916f | 164 | epaper.cls(); |
jendo1969 | 0:41e5a06d916f | 165 | |
jendo1969 | 0:41e5a06d916f | 166 | // read file names into vector of strings |
jendo1969 | 0:41e5a06d916f | 167 | //read_file_names("/sd"); |
jendo1969 | 0:41e5a06d916f | 168 | |
jendo1969 | 0:41e5a06d916f | 169 | while (true) |
jendo1969 | 0:41e5a06d916f | 170 | { |
jendo1969 | 0:41e5a06d916f | 171 | float w; |
jendo1969 | 0:41e5a06d916f | 172 | int cnt; |
jendo1969 | 0:41e5a06d916f | 173 | int stop_flag = 0; |
jendo1969 | 0:41e5a06d916f | 174 | |
jendo1969 | 0:41e5a06d916f | 175 | for(i=0;i<1000;i++) |
jendo1969 | 0:41e5a06d916f | 176 | { |
jendo1969 | 0:41e5a06d916f | 177 | if(i==0) |
jendo1969 | 0:41e5a06d916f | 178 | { |
jendo1969 | 0:41e5a06d916f | 179 | epaper.print_bm(bitmARM0, 1, 1); |
jendo1969 | 0:41e5a06d916f | 180 | epaper.write_disp(); // update screen |
jendo1969 | 0:41e5a06d916f | 181 | wait(0.1); |
jendo1969 | 0:41e5a06d916f | 182 | } |
jendo1969 | 0:41e5a06d916f | 183 | else |
jendo1969 | 0:41e5a06d916f | 184 | { |
jendo1969 | 0:41e5a06d916f | 185 | sprintf(str1,"%d",i); |
jendo1969 | 0:41e5a06d916f | 186 | char idir[14] = "/sd/"; |
jendo1969 | 0:41e5a06d916f | 187 | char dir[100] = ""; |
jendo1969 | 0:41e5a06d916f | 188 | strcat(dir,idir); |
jendo1969 | 0:41e5a06d916f | 189 | strcat(dir,"/"); |
jendo1969 | 0:41e5a06d916f | 190 | strcat(dir,str1); |
jendo1969 | 0:41e5a06d916f | 191 | strcat(dir,".xbm"); |
jendo1969 | 0:41e5a06d916f | 192 | // dir[4] = 0x30 + i; |
jendo1969 | 0:41e5a06d916f | 193 | // if(read_filedata("/sd/1.xbm")== 0) |
jendo1969 | 0:41e5a06d916f | 194 | if(read_filedata(dir)== 0) |
jendo1969 | 0:41e5a06d916f | 195 | { |
jendo1969 | 0:41e5a06d916f | 196 | epaper.print_bm(bitmIMG0, 1, 1); |
jendo1969 | 0:41e5a06d916f | 197 | epaper.write_disp(); // update screen |
jendo1969 | 0:41e5a06d916f | 198 | } |
jendo1969 | 0:41e5a06d916f | 199 | else |
jendo1969 | 0:41e5a06d916f | 200 | { |
jendo1969 | 0:41e5a06d916f | 201 | continue; |
jendo1969 | 0:41e5a06d916f | 202 | } |
jendo1969 | 0:41e5a06d916f | 203 | cnt = 0; |
jendo1969 | 0:41e5a06d916f | 204 | while (true) |
jendo1969 | 0:41e5a06d916f | 205 | { |
jendo1969 | 0:41e5a06d916f | 206 | w = tsi.readPercentage(); |
jendo1969 | 0:41e5a06d916f | 207 | if(w > 0.8) |
jendo1969 | 0:41e5a06d916f | 208 | { |
jendo1969 | 0:41e5a06d916f | 209 | stop_flag = 1; |
jendo1969 | 0:41e5a06d916f | 210 | break; |
jendo1969 | 0:41e5a06d916f | 211 | } |
jendo1969 | 0:41e5a06d916f | 212 | else if(w > 0.3) |
jendo1969 | 0:41e5a06d916f | 213 | { |
jendo1969 | 0:41e5a06d916f | 214 | break; |
jendo1969 | 0:41e5a06d916f | 215 | } |
jendo1969 | 0:41e5a06d916f | 216 | cnt++; |
jendo1969 | 0:41e5a06d916f | 217 | if(cnt > 100) |
jendo1969 | 0:41e5a06d916f | 218 | { |
jendo1969 | 0:41e5a06d916f | 219 | break; |
jendo1969 | 0:41e5a06d916f | 220 | } |
jendo1969 | 0:41e5a06d916f | 221 | wait(0.1); |
jendo1969 | 0:41e5a06d916f | 222 | } |
jendo1969 | 0:41e5a06d916f | 223 | // epaper.cls(); |
jendo1969 | 0:41e5a06d916f | 224 | if(stop_flag == 1) |
jendo1969 | 0:41e5a06d916f | 225 | { |
jendo1969 | 0:41e5a06d916f | 226 | break; |
jendo1969 | 0:41e5a06d916f | 227 | } |
jendo1969 | 0:41e5a06d916f | 228 | } |
jendo1969 | 0:41e5a06d916f | 229 | } |
jendo1969 | 0:41e5a06d916f | 230 | } |
jendo1969 | 0:41e5a06d916f | 231 | } |