PokittoLib is the library needed for programming the Pokitto DIY game console (www.pokitto.com)
Dependents: YATTT sd_map_test cPong SnowDemo ... more
PokittoLib
Library for programming Pokitto hardware
How to Use
- Import this library to online compiler (see button "import" on the right hand side
- DO NOT import mbed-src anymore, a better version is now included inside PokittoLib
- Change My_settings.h according to your project
- Start coding!
POKITTO_CORE/PokittoDisk.cpp@66:6281a40d73e6, 2019-03-23 (annotated)
- Committer:
- Pokitto
- Date:
- Sat Mar 23 20:03:34 2019 +0000
- Revision:
- 66:6281a40d73e6
- Parent:
- 52:c04087025cab
Updated pokittolib to current embitz dev branch
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Pokitto | 52:c04087025cab | 1 | /**************************************************************************/ |
Pokitto | 52:c04087025cab | 2 | /*! |
Pokitto | 52:c04087025cab | 3 | @file Pokitto_disk.cpp |
Pokitto | 52:c04087025cab | 4 | @author Jonne Valola |
Pokitto | 52:c04087025cab | 5 | |
Pokitto | 52:c04087025cab | 6 | @section LICENSE |
Pokitto | 52:c04087025cab | 7 | |
Pokitto | 52:c04087025cab | 8 | Pokitto development stage library |
Pokitto | 52:c04087025cab | 9 | Software License Agreement |
Pokitto | 52:c04087025cab | 10 | |
Pokitto | 52:c04087025cab | 11 | Copyright (c) 2015, Jonne Valola ("Author") |
Pokitto | 52:c04087025cab | 12 | All rights reserved. |
Pokitto | 52:c04087025cab | 13 | |
Pokitto | 52:c04087025cab | 14 | This library is intended solely for the purpose of Pokitto development. |
Pokitto | 52:c04087025cab | 15 | |
Pokitto | 52:c04087025cab | 16 | Redistribution and use in source and binary forms, with or without |
Pokitto | 52:c04087025cab | 17 | modification requires written permission from Author. |
Pokitto | 52:c04087025cab | 18 | */ |
Pokitto | 52:c04087025cab | 19 | /**************************************************************************/ |
Pokitto | 52:c04087025cab | 20 | |
Pokitto | 52:c04087025cab | 21 | #include "Pokitto.h" |
Pokitto | 52:c04087025cab | 22 | |
Pokitto | 52:c04087025cab | 23 | #define SD_MOSI_PORT 0 |
Pokitto | 52:c04087025cab | 24 | #define SD_MISO_PORT 0 |
Pokitto | 52:c04087025cab | 25 | #define SD_SCK_PORT 0 |
Pokitto | 52:c04087025cab | 26 | #define SD_CS_PORT 0 |
Pokitto | 52:c04087025cab | 27 | #define SD_MOSI_PIN 9 |
Pokitto | 52:c04087025cab | 28 | #define SD_MISO_PIN 8 |
Pokitto | 52:c04087025cab | 29 | #define SD_SCK_PIN 6 |
Pokitto | 52:c04087025cab | 30 | #define SD_CS_PIN 7 |
Pokitto | 52:c04087025cab | 31 | |
Pokitto | 52:c04087025cab | 32 | #if POK_ENABLE_SD > 0 |
Pokitto | 52:c04087025cab | 33 | PFFS::BYTE res; |
Pokitto | 52:c04087025cab | 34 | PFFS::FATFS fs; /* File system object */ |
Pokitto | 52:c04087025cab | 35 | PFFS::FATDIR dir; /* Directory object */ |
Pokitto | 52:c04087025cab | 36 | PFFS::FILINFO fno; /* File information */ |
Pokitto | 52:c04087025cab | 37 | |
Pokitto | 52:c04087025cab | 38 | //static FATFS *FatFs; /* Pointer to the file system object (logical drive) */ |
Pokitto | 52:c04087025cab | 39 | |
Pokitto | 52:c04087025cab | 40 | bool diropened=false; |
Pokitto | 52:c04087025cab | 41 | |
Pokitto | 52:c04087025cab | 42 | #define SPEAKER 3 |
Pokitto | 52:c04087025cab | 43 | //#define BUFFER_SIZE 256 // was 128 |
Pokitto | 52:c04087025cab | 44 | #define SONGLENGTH 0x1BFBCD // 1072223 |
Pokitto | 52:c04087025cab | 45 | #define FILESIZE 0x1BFBCD |
Pokitto | 52:c04087025cab | 46 | |
Pokitto | 52:c04087025cab | 47 | uint8_t filemode = FILE_MODE_UNINITIALIZED; |
Pokitto | 52:c04087025cab | 48 | char currentfile[15]; // holds current file's name |
Pokitto | 52:c04087025cab | 49 | |
Pokitto | 52:c04087025cab | 50 | SPI device(CONNECT_MOSI,CONNECT_MISO,CONNECT_SCK); |
Pokitto | 52:c04087025cab | 51 | //DigitalOut mmccs(CONNECT_CS); |
Pokitto | 52:c04087025cab | 52 | |
Pokitto | 52:c04087025cab | 53 | const char *get_filename_ext(const char *filename) { |
Pokitto | 52:c04087025cab | 54 | const char *dot = strrchr(filename, '.'); |
Pokitto | 52:c04087025cab | 55 | if(!dot || dot == filename) return ""; |
Pokitto | 52:c04087025cab | 56 | return dot + 1; |
Pokitto | 52:c04087025cab | 57 | } |
Pokitto | 52:c04087025cab | 58 | |
Pokitto | 66:6281a40d73e6 | 59 | //__attribute__((section(".SD_Code"))) |
Pokitto | 66:6281a40d73e6 | 60 | void initSDGPIO() { |
Pokitto | 52:c04087025cab | 61 | LPC_GPIO_PORT->DIR[SD_MOSI_PORT] |= (1 << SD_MOSI_PIN ); |
Pokitto | 52:c04087025cab | 62 | LPC_GPIO_PORT->DIR[SD_MISO_PORT] |= (1 << SD_MISO_PIN ); |
Pokitto | 52:c04087025cab | 63 | LPC_GPIO_PORT->DIR[SD_SCK_PORT] |= (1 << SD_SCK_PIN ); |
Pokitto | 52:c04087025cab | 64 | LPC_GPIO_PORT->DIR[SD_CS_PORT] |= (1 << SD_CS_PIN ); |
Pokitto | 52:c04087025cab | 65 | } |
Pokitto | 52:c04087025cab | 66 | |
Pokitto | 66:6281a40d73e6 | 67 | //__attribute__((section(".SD_Code"))) |
Pokitto | 66:6281a40d73e6 | 68 | int pokInitSD() { |
Pokitto | 52:c04087025cab | 69 | initSDGPIO(); |
Pokitto | 52:c04087025cab | 70 | res = PFFS::disk_initialize(); |
Pokitto | 52:c04087025cab | 71 | //res = disk_initialize(0); |
Pokitto | 52:c04087025cab | 72 | res = (pf_mount(&fs)); |
Pokitto | 52:c04087025cab | 73 | res = pf_opendir(&dir,""); |
Pokitto | 52:c04087025cab | 74 | if (res) diropened=false; |
Pokitto | 52:c04087025cab | 75 | else diropened=true; |
Pokitto | 52:c04087025cab | 76 | return res; |
Pokitto | 52:c04087025cab | 77 | } |
Pokitto | 52:c04087025cab | 78 | |
Pokitto | 52:c04087025cab | 79 | |
Pokitto | 52:c04087025cab | 80 | void emptyFname() { |
Pokitto | 52:c04087025cab | 81 | for (int i=0; i<13; i++) fno.fname[i]=NULL; |
Pokitto | 52:c04087025cab | 82 | } |
Pokitto | 52:c04087025cab | 83 | |
Pokitto | 52:c04087025cab | 84 | /** PUBLIC FUNCTIONS **/ |
Pokitto | 52:c04087025cab | 85 | |
Pokitto | 66:6281a40d73e6 | 86 | char* getFirstDirEntry(char* path) { |
Pokitto | 52:c04087025cab | 87 | res=0; |
Pokitto | 52:c04087025cab | 88 | if (!diropened) { |
Pokitto | 52:c04087025cab | 89 | pokInitSD(); |
Pokitto | 52:c04087025cab | 90 | } |
Pokitto | 66:6281a40d73e6 | 91 | res = pf_opendir(&dir,path); |
Pokitto | 52:c04087025cab | 92 | emptyFname(); |
Pokitto | 52:c04087025cab | 93 | res = pf_readdir(&dir,&fno); //returns 0 if everything is OK |
Pokitto | 52:c04087025cab | 94 | if (res) return 0; |
Pokitto | 52:c04087025cab | 95 | while (res==0) { //while res is ok |
Pokitto | 52:c04087025cab | 96 | if ((fno.fattrib & 0x02)==0) { |
Pokitto | 52:c04087025cab | 97 | if (fno.fattrib & 0x10) { |
Pokitto | 52:c04087025cab | 98 | fno.fname[8]='.'; |
Pokitto | 52:c04087025cab | 99 | fno.fname[9]='D'; |
Pokitto | 52:c04087025cab | 100 | fno.fname[10]='I'; |
Pokitto | 52:c04087025cab | 101 | fno.fname[11]='R'; |
Pokitto | 52:c04087025cab | 102 | fno.fname[12]='\0'; |
Pokitto | 52:c04087025cab | 103 | } |
Pokitto | 52:c04087025cab | 104 | return fno.fname; |
Pokitto | 52:c04087025cab | 105 | } |
Pokitto | 52:c04087025cab | 106 | emptyFname(); |
Pokitto | 52:c04087025cab | 107 | res = pf_readdir(&dir,&fno); //returns 0 if everything is OK |
Pokitto | 52:c04087025cab | 108 | if (res==0 && dir.index==0) break; |
Pokitto | 52:c04087025cab | 109 | } |
Pokitto | 52:c04087025cab | 110 | return 0; |
Pokitto | 52:c04087025cab | 111 | } |
Pokitto | 52:c04087025cab | 112 | |
Pokitto | 66:6281a40d73e6 | 113 | char* getFirstDirEntry() { |
Pokitto | 66:6281a40d73e6 | 114 | return getFirstDirEntry(""); |
Pokitto | 66:6281a40d73e6 | 115 | } |
Pokitto | 66:6281a40d73e6 | 116 | |
Pokitto | 52:c04087025cab | 117 | char* getNextDirEntry() { |
Pokitto | 52:c04087025cab | 118 | if (!diropened) pokInitSD(); |
Pokitto | 52:c04087025cab | 119 | emptyFname(); |
Pokitto | 52:c04087025cab | 120 | res = pf_readdir(&dir,&fno); //returns 0 if everything is OK |
Pokitto | 52:c04087025cab | 121 | if (res==0) { |
Pokitto | 52:c04087025cab | 122 | while (fno.fattrib & 0x02 && !res) {emptyFname(); res = pf_readdir(&dir,&fno);} //system/hidden file |
Pokitto | 52:c04087025cab | 123 | if (fno.fattrib & 0x10) { |
Pokitto | 52:c04087025cab | 124 | int a=12; |
Pokitto | 52:c04087025cab | 125 | while (a) { |
Pokitto | 52:c04087025cab | 126 | fno.fname[a] = fno.fname[a-1]; |
Pokitto | 52:c04087025cab | 127 | a--; |
Pokitto | 52:c04087025cab | 128 | } |
Pokitto | 52:c04087025cab | 129 | if (fno.fname[0]) { |
Pokitto | 52:c04087025cab | 130 | fno.fname[0]='/'; |
Pokitto | 52:c04087025cab | 131 | a=0; |
Pokitto | 52:c04087025cab | 132 | while (fno.fname[a]) a++; |
Pokitto | 52:c04087025cab | 133 | fno.fname[a]='/'; |
Pokitto | 52:c04087025cab | 134 | } |
Pokitto | 52:c04087025cab | 135 | |
Pokitto | 52:c04087025cab | 136 | /*fno.fname[a++]='.'; |
Pokitto | 52:c04087025cab | 137 | fno.fname[a++]='D'; |
Pokitto | 52:c04087025cab | 138 | fno.fname[a++]='I'; |
Pokitto | 52:c04087025cab | 139 | fno.fname[a++]='R'; |
Pokitto | 52:c04087025cab | 140 | fno.fname[a]='\0';*/ |
Pokitto | 52:c04087025cab | 141 | } |
Pokitto | 52:c04087025cab | 142 | return fno.fname; |
Pokitto | 52:c04087025cab | 143 | } |
Pokitto | 52:c04087025cab | 144 | return NULL; |
Pokitto | 52:c04087025cab | 145 | } |
Pokitto | 52:c04087025cab | 146 | |
Pokitto | 52:c04087025cab | 147 | char* getNextFile (char* ext){ |
Pokitto | 52:c04087025cab | 148 | |
Pokitto | 52:c04087025cab | 149 | if (!diropened) pokInitSD(); |
Pokitto | 52:c04087025cab | 150 | int a=1; |
Pokitto | 52:c04087025cab | 151 | emptyFname(); |
Pokitto | 52:c04087025cab | 152 | res = pf_readdir(&dir,&fno); //returns 0 if everything is OK |
Pokitto | 52:c04087025cab | 153 | while (res==0 || a) { //while there are entries and |
Pokitto | 52:c04087025cab | 154 | if (dir.index==0) return 0; //end of list |
Pokitto | 52:c04087025cab | 155 | a = strcmp((const char*)get_filename_ext(fno.fname),(const char*)ext); // returns 0 if strings are identical |
Pokitto | 52:c04087025cab | 156 | if (strcmp(ext,"")==0 && (fno.fattrib & 0x10) == 0) a=0; |
Pokitto | 52:c04087025cab | 157 | if (a == 0 && (fno.fattrib & 0x10) == 0) return fno.fname; |
Pokitto | 52:c04087025cab | 158 | if (fno.fname[0]==NULL) return NULL; //end of files |
Pokitto | 52:c04087025cab | 159 | //if (fno.fattrib&0x10) return NULL; //its a directory |
Pokitto | 52:c04087025cab | 160 | emptyFname(); |
Pokitto | 52:c04087025cab | 161 | res = pf_readdir(&dir,&fno); //returns 0 if everything is OK |
Pokitto | 52:c04087025cab | 162 | } |
Pokitto | 52:c04087025cab | 163 | return 0; |
Pokitto | 52:c04087025cab | 164 | } |
Pokitto | 52:c04087025cab | 165 | |
Pokitto | 52:c04087025cab | 166 | |
Pokitto | 52:c04087025cab | 167 | char* getNextFile() { |
Pokitto | 52:c04087025cab | 168 | return getNextFile(""); |
Pokitto | 52:c04087025cab | 169 | } |
Pokitto | 52:c04087025cab | 170 | |
Pokitto | 66:6281a40d73e6 | 171 | char* getFirstFile(char* ext, char* path) { |
Pokitto | 52:c04087025cab | 172 | res=0; |
Pokitto | 52:c04087025cab | 173 | if (!diropened) { |
Pokitto | 52:c04087025cab | 174 | pokInitSD(); |
Pokitto | 52:c04087025cab | 175 | } |
Pokitto | 66:6281a40d73e6 | 176 | res = pf_opendir(&dir,path); |
Pokitto | 52:c04087025cab | 177 | emptyFname(); |
Pokitto | 52:c04087025cab | 178 | res = pf_readdir(&dir,&fno); //returns 0 if everything is OK |
Pokitto | 52:c04087025cab | 179 | if (res) return 0; |
Pokitto | 52:c04087025cab | 180 | while (res==0 || (fno.fattrib & 0x10) == 0) { |
Pokitto | 52:c04087025cab | 181 | int a=0; |
Pokitto | 52:c04087025cab | 182 | a = strcmp((const char*)get_filename_ext(fno.fname),(const char*)ext); // returns 0 if strings are identical |
Pokitto | 52:c04087025cab | 183 | if (!strcmp(ext,"")) a=0; |
Pokitto | 52:c04087025cab | 184 | if ( a == 0 && (fno.fattrib & 0x10) == 0) return fno.fname; |
Pokitto | 52:c04087025cab | 185 | emptyFname(); |
Pokitto | 52:c04087025cab | 186 | res = pf_readdir(&dir,&fno); //returns 0 if everything is OK |
Pokitto | 52:c04087025cab | 187 | if (fno.fname[0]==NULL) break; //end of directory reached, no files found |
Pokitto | 52:c04087025cab | 188 | if (res==0 && dir.index==0) break; |
Pokitto | 52:c04087025cab | 189 | } |
Pokitto | 52:c04087025cab | 190 | return 0; |
Pokitto | 52:c04087025cab | 191 | } |
Pokitto | 52:c04087025cab | 192 | |
Pokitto | 66:6281a40d73e6 | 193 | char* getFirstFile(char* ext) { |
Pokitto | 66:6281a40d73e6 | 194 | return getFirstFile(ext, ""); |
Pokitto | 66:6281a40d73e6 | 195 | } |
Pokitto | 66:6281a40d73e6 | 196 | |
Pokitto | 52:c04087025cab | 197 | char* getFirstFile() { |
Pokitto | 52:c04087025cab | 198 | return getFirstFile(""); |
Pokitto | 52:c04087025cab | 199 | } |
Pokitto | 52:c04087025cab | 200 | |
Pokitto | 52:c04087025cab | 201 | int isThisFileOpen(char* buffer){ |
Pokitto | 52:c04087025cab | 202 | int a=0; |
Pokitto | 52:c04087025cab | 203 | a = strcmp((const char*)buffer,(const char*)currentfile); // returns 0 if strings are identical |
Pokitto | 52:c04087025cab | 204 | if ( a == 0 && filemode != FILE_MODE_FAILED) return 1; |
Pokitto | 52:c04087025cab | 205 | return 0; |
Pokitto | 52:c04087025cab | 206 | } |
Pokitto | 52:c04087025cab | 207 | |
Pokitto | 52:c04087025cab | 208 | int fileOK() { |
Pokitto | 52:c04087025cab | 209 | if (filemode != FILE_MODE_FAILED) return 1; |
Pokitto | 52:c04087025cab | 210 | return 0; |
Pokitto | 52:c04087025cab | 211 | } |
Pokitto | 52:c04087025cab | 212 | |
Pokitto | 52:c04087025cab | 213 | uint8_t fileOpen(char* buffer, char fmode) { |
Pokitto | 52:c04087025cab | 214 | int err; |
Pokitto | 52:c04087025cab | 215 | if (filemode == FILE_MODE_UNINITIALIZED) { |
Pokitto | 52:c04087025cab | 216 | int a = pf_mount(&fs); |
Pokitto | 52:c04087025cab | 217 | if (a) return 1; // 1 means error in this context |
Pokitto | 52:c04087025cab | 218 | } |
Pokitto | 52:c04087025cab | 219 | |
Pokitto | 52:c04087025cab | 220 | filemode = fmode; |
Pokitto | 52:c04087025cab | 221 | err = PFFS::pf_open(buffer); |
Pokitto | 52:c04087025cab | 222 | if (err==0) { |
Pokitto | 52:c04087025cab | 223 | strcpy(currentfile,(const char*)buffer); |
Pokitto | 52:c04087025cab | 224 | return 0; // 0 means all clear |
Pokitto | 52:c04087025cab | 225 | } |
Pokitto | 52:c04087025cab | 226 | // file open failed |
Pokitto | 52:c04087025cab | 227 | filemode = FILE_MODE_FAILED; |
Pokitto | 52:c04087025cab | 228 | return 1; // 1 means failed |
Pokitto | 52:c04087025cab | 229 | } |
Pokitto | 52:c04087025cab | 230 | |
Pokitto | 52:c04087025cab | 231 | void fileClose() { |
Pokitto | 52:c04087025cab | 232 | filemode = FILE_MODE_UNINITIALIZED; |
Pokitto | 52:c04087025cab | 233 | for (uint8_t i=0; i<15; i++) currentfile[i]=0; |
Pokitto | 52:c04087025cab | 234 | } |
Pokitto | 52:c04087025cab | 235 | |
Pokitto | 52:c04087025cab | 236 | char fileGetChar() { |
Pokitto | 52:c04087025cab | 237 | PFFS::BYTE buff[1]; |
Pokitto | 52:c04087025cab | 238 | PFFS::WORD br; |
Pokitto | 52:c04087025cab | 239 | int err = PFFS::pf_read(buff, 1, &br); /* Read data to the buff[] */ |
Pokitto | 52:c04087025cab | 240 | return buff[0]; |
Pokitto | 52:c04087025cab | 241 | } |
Pokitto | 52:c04087025cab | 242 | |
Pokitto | 52:c04087025cab | 243 | void filePutChar(char c) { |
Pokitto | 52:c04087025cab | 244 | PFFS::WORD bw; |
Pokitto | 52:c04087025cab | 245 | PFFS::pf_write((const void*)&c, 1, &bw); |
Pokitto | 52:c04087025cab | 246 | PFFS::pf_write(0, 0, &bw); |
Pokitto | 52:c04087025cab | 247 | } |
Pokitto | 52:c04087025cab | 248 | |
Pokitto | 52:c04087025cab | 249 | void fileWriteBytes(uint8_t * b, uint16_t n) { |
Pokitto | 52:c04087025cab | 250 | PFFS::WORD bw; |
Pokitto | 52:c04087025cab | 251 | PFFS::pf_write((const void*)&b, n, &bw); |
Pokitto | 52:c04087025cab | 252 | PFFS::pf_write(0, 0, &bw); |
Pokitto | 52:c04087025cab | 253 | } |
Pokitto | 52:c04087025cab | 254 | |
Pokitto | 52:c04087025cab | 255 | uint16_t fileReadBytes(uint8_t * b, uint16_t n) { |
Pokitto | 52:c04087025cab | 256 | PFFS::WORD br; |
Pokitto | 52:c04087025cab | 257 | PFFS::pf_read(b, n, &br); /* Read data to the buff[] */ |
Pokitto | 52:c04087025cab | 258 | return br; /* Return number of bytes read */ |
Pokitto | 52:c04087025cab | 259 | } |
Pokitto | 52:c04087025cab | 260 | |
Pokitto | 52:c04087025cab | 261 | void fileSeekAbsolute(long n) { |
Pokitto | 52:c04087025cab | 262 | res = PFFS::pf_lseek(n); |
Pokitto | 52:c04087025cab | 263 | } |
Pokitto | 52:c04087025cab | 264 | |
Pokitto | 52:c04087025cab | 265 | void fileSeekRelative(long n) { |
Pokitto | 52:c04087025cab | 266 | if (n<0) if (fs.fptr < -n) n=-fs.fptr; |
Pokitto | 52:c04087025cab | 267 | else if (n>0) if (fs.fptr+n > fs.fsize) n=fs.fsize-fs.fptr; |
Pokitto | 52:c04087025cab | 268 | res = PFFS::pf_lseek(fs.fptr + n); |
Pokitto | 52:c04087025cab | 269 | } |
Pokitto | 52:c04087025cab | 270 | |
Pokitto | 52:c04087025cab | 271 | void fileRewind() { |
Pokitto | 52:c04087025cab | 272 | res = PFFS::pf_lseek(0); |
Pokitto | 52:c04087025cab | 273 | } |
Pokitto | 52:c04087025cab | 274 | |
Pokitto | 52:c04087025cab | 275 | void fileEnd() { |
Pokitto | 52:c04087025cab | 276 | res = PFFS::pf_lseek(fs.fsize); |
Pokitto | 52:c04087025cab | 277 | } |
Pokitto | 52:c04087025cab | 278 | |
Pokitto | 52:c04087025cab | 279 | long int fileGetPosition() { |
Pokitto | 52:c04087025cab | 280 | return fs.fptr; |
Pokitto | 52:c04087025cab | 281 | } |
Pokitto | 52:c04087025cab | 282 | |
Pokitto | 52:c04087025cab | 283 | uint8_t filePeek(long n) { |
Pokitto | 52:c04087025cab | 284 | PFFS::pf_lseek(n); |
Pokitto | 52:c04087025cab | 285 | return fileGetChar(); |
Pokitto | 52:c04087025cab | 286 | } |
Pokitto | 52:c04087025cab | 287 | |
Pokitto | 52:c04087025cab | 288 | void filePoke(long n, uint8_t c) { |
Pokitto | 52:c04087025cab | 289 | PFFS::pf_lseek(n); |
Pokitto | 52:c04087025cab | 290 | filePutChar(c); |
Pokitto | 52:c04087025cab | 291 | } |
Pokitto | 52:c04087025cab | 292 | |
Pokitto | 52:c04087025cab | 293 | int fileReadLine(char* destination, int maxchars) { |
Pokitto | 52:c04087025cab | 294 | int n=0; |
Pokitto | 52:c04087025cab | 295 | char c=1; |
Pokitto | 52:c04087025cab | 296 | char linebuf[80]; |
Pokitto | 52:c04087025cab | 297 | fileReadBytes((uint8_t*)linebuf,80); |
Pokitto | 52:c04087025cab | 298 | int index=0; |
Pokitto | 52:c04087025cab | 299 | while (c!=NULL) { |
Pokitto | 52:c04087025cab | 300 | c = linebuf[index++]; |
Pokitto | 52:c04087025cab | 301 | if (n == 0) { |
Pokitto | 52:c04087025cab | 302 | while (c == '\n' || c == '\r') c = linebuf[index++]; // skip empty lines |
Pokitto | 52:c04087025cab | 303 | } |
Pokitto | 52:c04087025cab | 304 | n++; |
Pokitto | 52:c04087025cab | 305 | if (c=='\n' || c=='\r' || n==maxchars-1) c=NULL; //prevent buffer overflow |
Pokitto | 52:c04087025cab | 306 | *destination++ = c; |
Pokitto | 52:c04087025cab | 307 | } |
Pokitto | 52:c04087025cab | 308 | fileSeekRelative(-80+index); //rewind |
Pokitto | 52:c04087025cab | 309 | return n; //number of characters read |
Pokitto | 52:c04087025cab | 310 | } |
Pokitto | 52:c04087025cab | 311 | |
Pokitto | 52:c04087025cab | 312 | int dirOpen() { |
Pokitto | 52:c04087025cab | 313 | return PFFS::pf_opendir(&dir,""); |
Pokitto | 52:c04087025cab | 314 | } |
Pokitto | 52:c04087025cab | 315 | |
Pokitto | 52:c04087025cab | 316 | int dirUp() { |
Pokitto | 52:c04087025cab | 317 | |
Pokitto | 52:c04087025cab | 318 | return 0; |
Pokitto | 52:c04087025cab | 319 | } |
Pokitto | 52:c04087025cab | 320 | #endif // POK_ENABLE_SD |
Pokitto | 52:c04087025cab | 321 | |
Pokitto | 52:c04087025cab | 322 | |
Pokitto | 52:c04087025cab | 323 |