![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
test st7735 on lpc1768 with mbed v5. bug with spi frequency...
TAR/tar.cpp@2:2946f9eefcae, 2020-04-08 (annotated)
- Committer:
- skydarc
- Date:
- Wed Apr 08 15:00:13 2020 +0000
- Revision:
- 2:2946f9eefcae
- Parent:
- 1:121b61eeffe7
v2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
skydarc | 1:121b61eeffe7 | 1 | #include "mbed.h" |
skydarc | 1:121b61eeffe7 | 2 | #include "tar.h" |
skydarc | 1:121b61eeffe7 | 3 | |
skydarc | 1:121b61eeffe7 | 4 | FILE* fopenTar(char *tarfile, char *namefile) { |
skydarc | 1:121b61eeffe7 | 5 | |
skydarc | 1:121b61eeffe7 | 6 | int i; |
skydarc | 1:121b61eeffe7 | 7 | char buf[32]; |
skydarc | 1:121b61eeffe7 | 8 | char sizeStr[12]; |
skydarc | 1:121b61eeffe7 | 9 | char *valExit = "error"; |
skydarc | 1:121b61eeffe7 | 10 | int size, offset = 0; |
skydarc | 1:121b61eeffe7 | 11 | |
skydarc | 1:121b61eeffe7 | 12 | FILE *Tar = fopen(tarfile, "r"); |
skydarc | 1:121b61eeffe7 | 13 | |
skydarc | 1:121b61eeffe7 | 14 | while(!feof(Tar)) { |
skydarc | 1:121b61eeffe7 | 15 | for(i=0; i <= strlen(namefile); i++) buf[i] = fgetc(Tar); |
skydarc | 1:121b61eeffe7 | 16 | |
skydarc | 1:121b61eeffe7 | 17 | if(!strcmp(buf, namefile)) { |
skydarc | 1:121b61eeffe7 | 18 | valExit = ""; |
skydarc | 1:121b61eeffe7 | 19 | break; |
skydarc | 1:121b61eeffe7 | 20 | } |
skydarc | 1:121b61eeffe7 | 21 | |
skydarc | 1:121b61eeffe7 | 22 | fseek(Tar , 124+offset , SEEK_SET); |
skydarc | 1:121b61eeffe7 | 23 | for(i=0; i < 12; i++) sizeStr[i] = fgetc(Tar); |
skydarc | 1:121b61eeffe7 | 24 | //printf("size string: %s; octal: %d; dec.: %x\n", sizeStr, atoi(sizeStr), oct2dec(atoi(sizeStr)) ); |
skydarc | 1:121b61eeffe7 | 25 | |
skydarc | 1:121b61eeffe7 | 26 | size = oct2dec(atoi(sizeStr)); |
skydarc | 1:121b61eeffe7 | 27 | if(offset % 512 != 0) offset += (size/512 + 2)*512; |
skydarc | 1:121b61eeffe7 | 28 | else offset += (size/512 + 1)*512; |
skydarc | 1:121b61eeffe7 | 29 | |
skydarc | 1:121b61eeffe7 | 30 | fseek(Tar , offset , SEEK_SET); |
skydarc | 1:121b61eeffe7 | 31 | } |
skydarc | 1:121b61eeffe7 | 32 | |
skydarc | 1:121b61eeffe7 | 33 | if(valExit == "error") { |
skydarc | 1:121b61eeffe7 | 34 | printf("file \"%s\" not find in tar\n", namefile); |
skydarc | 1:121b61eeffe7 | 35 | return NULL; |
skydarc | 1:121b61eeffe7 | 36 | } else { |
skydarc | 1:121b61eeffe7 | 37 | fseek(Tar, offset+512 , SEEK_SET); |
skydarc | 1:121b61eeffe7 | 38 | return Tar; |
skydarc | 1:121b61eeffe7 | 39 | } |
skydarc | 1:121b61eeffe7 | 40 | } |
skydarc | 1:121b61eeffe7 | 41 | |
skydarc | 1:121b61eeffe7 | 42 | int oct2dec(int n) /* Function to convert octal to decimal */ |
skydarc | 1:121b61eeffe7 | 43 | { |
skydarc | 1:121b61eeffe7 | 44 | int decimal=0, i=0, rem; |
skydarc | 1:121b61eeffe7 | 45 | while (n!=0) |
skydarc | 1:121b61eeffe7 | 46 | { |
skydarc | 1:121b61eeffe7 | 47 | rem = n%10; |
skydarc | 1:121b61eeffe7 | 48 | n/=10; |
skydarc | 1:121b61eeffe7 | 49 | decimal += rem*pow(8.0,i); |
skydarc | 1:121b61eeffe7 | 50 | ++i; |
skydarc | 1:121b61eeffe7 | 51 | } |
skydarc | 1:121b61eeffe7 | 52 | return decimal; |
skydarc | 1:121b61eeffe7 | 53 | } |