More HACMan stuff again
Dependencies: FatFileSystem SDFileSystem mbed
Revision 0:ddc821040077, committed 2015-06-11
- Comitter:
- TBSliver
- Date:
- Thu Jun 11 13:50:10 2015 +0000
- Commit message:
- Initial no idea whats here commit
Changed in this revision
diff -r 000000000000 -r ddc821040077 FATFileSystem.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FATFileSystem.lib Thu Jun 11 13:50:10 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_unsupported/code/FatFileSystem/#333d6e93e58f
diff -r 000000000000 -r ddc821040077 SDFileSystem.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SDFileSystem.lib Thu Jun 11 13:50:10 2015 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/TBSliver/code/SDFileSystem/#e4c66f393f73
diff -r 000000000000 -r ddc821040077 ledSign.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ledSign.cpp Thu Jun 11 13:50:10 2015 +0000 @@ -0,0 +1,134 @@ +#include "ledSign.h" + +// Sign Output Pins + +BusOut address(p17, p18, p19, p20); // Address 0 to 16 +BusOut colour(p15, p16); // 0 = off, 1 = red, 2 = green, 3 = orange + +DigitalOut abTop(p14); // bank A or B switch for Top Row - 0 = A, 1 = B +DigitalOut clkTop(p13); // clock for Top Row +DigitalOut weTop(p28); // Write Enable for Top Row +DigitalOut aeTop(p27); // Address Enable for Top Row +DigitalOut enbTop(p26); // Enable for Top Row + +DigitalOut abBot(p25); // bank A or B switch for Bottom Row - 0 = A, 1 = B +DigitalOut clkBot(p24); // clock for Bottom Row +DigitalOut weBot(p23); // Write Enable for Bottom Row +DigitalOut aeBot(p22); // Address Enable for Bottom Row +DigitalOut enbBot(p21); // Enable for Bottom Row + +LedSign::LedSign() { + address = 0; + colour = 0; + abTop = 0; + clkTop = 0; + weTop = 0; + aeTop = 0; + enbTop = 0; + abBot = 0; + clkBot = 0; + weBot = 0; + aeBot = 0; + enbBot = 0; +} + +void LedSign::enable() { + enbTop = 1; + enbBot = 1; +} + +void LedSign::disable() { + enbTop = 0; + enbBot = 0; +} + +void LedSign::swapBank() { + (abTop) ? abTop = 0 : abTop = 1; + (abBot) ? abBot = 0 : abBot = 1; +} + +void LedSign::writeRow(int * pointer, int wRow) { + if(wRow <= 15) { + for(int col = 0; col < 128; col++) { + colour = *(pointer + col); + clockTop(); + } + + writeTop(wRow); + } + if(wRow >= 16) { + for(int col = 0; col < 128; col++) { + colour = *(pointer + col); + clockBot(); + } + + writeBot(wRow - 16); + } +} + +void LedSign::writeScreenColour(int newColour) { + colour = newColour; //set colour to write to screen + for (int i=0; i<128; i++) { // clock in 128 bits to turn all the LED's on + clockIn(); + } + + for (int i=0; i<16; i++) { //actually write them for all lines + writeTop(i); + writeBot(i); + } + + swapBank(); + +} + +//********************Private Declerations******************** + +void LedSign::writeTop(int topAddress) { + address = topAddress; + aeTop = 1; + wait_us(1); + weTop = 1; + wait_us(1); + weTop = 0; + wait_us(1); + aeTop = 0; + wait_us(1); +} + +void LedSign::writeBot(int botAddress) { + address = botAddress; + aeBot = 1; + wait_us(1); + weBot = 1; + wait_us(1); + weBot = 0; + wait_us(1); + aeBot = 0; + wait_us(1); +} + +void LedSign::clockTop() { + wait_us(1); + clkTop = 1; + wait_us(1); + clkTop = 0; + wait_us(1); +} + +void LedSign::clockBot() { + wait_us(1); + clkBot = 1; + wait_us(1); + clkBot = 0; + wait_us(1); +} + +void LedSign::clockIn() { + wait_us(1); + clkTop = 1; + clkBot = 1; + wait_us(1); + clkTop = 0; + clkBot = 0; + wait_us(1); +} \ No newline at end of file
diff -r 000000000000 -r ddc821040077 ledSign.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ledSign.h Thu Jun 11 13:50:10 2015 +0000 @@ -0,0 +1,46 @@ +/* +ledSign.h + +Header file for all LED sign processes for control + +*/ + +#ifndef LEDSIGN_H +#define LEDSIGN_H + +#include "mbed.h" + +class LedSign { + +public: + +//Constructor - initialise all pins to 0 +LedSign(); + +void enable(); +void disable(); + +//Swaps the display buffers +void swapBank(); + +//writes a colour to the whole screen +void writeScreenColour(int newColour); + +//write a row of LED's to the back buffer +void writeRow(int * pointer, int wRow); + +private: + +//Write the top and bottom buffer lines to memory +void writeTop(int topAddress); +void writeBot(int botAddress); + +//clock data into top and bottom banks +void clockTop(); +void clockBot(); +void clockIn(); + +}; + + +#endif \ No newline at end of file
diff -r 000000000000 -r ddc821040077 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Jun 11 13:50:10 2015 +0000 @@ -0,0 +1,72 @@ +#include "mbed.h" +#include "SDFileSystem.h" +#include <string> + +#include "ledSign.h" +#include "txtFile.h" + +SDFileSystem sd(p5, p6, p7, p8, "sd"); + + +//int testRow[128] = {1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2}; + +int readRow[128]; +//char buffer[300]; + +//string frameTotal = "FrameTotal="; + +int main() { + //LedSign sign; + //sign.enable(); + + TxtFile file("/sd/main.txt", "r"); + + file.seekPos(28); + + printf("%d\n\r", file.lineLength()); + + + + + + + + /* + //fseek(fp, 37, SEEK_SET); //SEEK_SET to go from start of file, SEEK_END to go from end of file, SEEK_CUR to go form current place + + FILE *fp = fopen("/sd/main.txt","r"); + + long int totalFrames = 5; + + char *pointing;// = &buffer[12]; + + fgets(buffer, 300, fp); + printf(buffer); + printf("\n\r"); + printf("%d",strlen(buffer)); + printf("\n\r"); + if (frameTotal.compare(buffer)) { + printf("WAHOO\n\r"); + fseek(fp, 0, SEEK_SET); + fgets(buffer, 300, fp); + printf("\n\r"); + printf("%d",strlen(buffer)); + printf("\n\r"); + printf(buffer); + fseek(fp, 11, SEEK_SET); + fgets(buffer, 300, fp); + printf("\n\r"); + printf("%d",strlen(buffer)); + printf("\n\r"); + printf(buffer); + printf("\n\r"); + totalFrames = strtol(buffer,&pointing,10); + printf("%d",totalFrames); + printf("\n\r"); + } + printf(buffer);*/ + + + +} +
diff -r 000000000000 -r ddc821040077 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Jun 11 13:50:10 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/b4b9f287a47e \ No newline at end of file
diff -r 000000000000 -r ddc821040077 txtFile.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/txtFile.cpp Thu Jun 11 13:50:10 2015 +0000 @@ -0,0 +1,189 @@ +#include "txtFile.h" + + +/** +* Constructor when called opens a file +* +* @param fileAddr +* the address of the file, either local, sd or whatever +* @param readWrite +* whether reading or writing to the file +*/ +TxtFile::TxtFile(char fileAddr[], char *readWrite, bool doParseFile) { + + isFileOpen = false; + isFileParsed = false; + currentFilePos = 0; + + if ((fp = fopen(fileAddr, readWrite)) == NULL) { + isFileOpen = false; + } else { + isFileOpen = true; + } + + if(doParseFile) { + parseFile(); + isFileParsed = true; + } +} + +/** +* Destructor when called closes the open file +*/ +TxtFile::~TxtFile() { + closeFile(); +} + +/** +* Returns true if the file is open +* +* @returns isFileOpen +*/ +bool TxtFile::isOpen() { + return isFileOpen; +} + +/** +* Returns true if file has been parsed +* +* @returns isFileParsed +*/ +bool TxtFile::isParsed() { + return isFileParsed; +} + +/** +* Checks if the file is open, and closes it if it is +* +* @returns isClosed +* returns true if a file was closed, false if not +*/ +bool TxtFile::closeFile() { + if (isOpen()) { + fclose(fp); + return true; + } else + return false; +} + +/** +* Counts the number of lines, and sets line start positions +*/ +void TxtFile::parseFile() { + int c = 0; //current character + int cPrev = 0; //previous character + int lengthCount = 0; //local length counter + int lineCount = 0; //local line counter + int curPos = 0; //current position in file + + if (!isFileParsed) { //check to see if not already done + seekPos(0); //seek to beginning of file + + c = fgetc(fp); //get first character + fileLineStart[lineCount] = curPos; //first line ALWAYS starts at zero... so far anyway + + while (c != EOF) { //while not at the end of the file + if ((c != '\n') && (c != '\r')) { //if not a newline or carriage return + lengthCount++; //increment length counter + } + + if (((c == '\n') && (cPrev == '\r')) || ((c == '\r') && (cPrev == '\n'))) { //if a newline (\r\n or \n\r) + fileLineLength[lineCount] = lengthCount; //set fileLineLength for current line to lengthCount + lineCount++; //increment line counter + lengthCount = 0; //reset lengthCount + fileLineStart[lineCount] = curPos + 1; //set file line start to next position - may not need the +1? + } + curPos++; + cPrev = c; + c = getc(fp); + } + + noLines = lineCount; + + isFileParsed = true; + seekPos(0); //seek back to the beginning of the file + } +} + +/** +* Returns the number of lines in the file +* +* @returns noLines +*/ +int TxtFile::lineCount() ( + return noLines; +} + +/** +* Seeks to the position in the current opened file +* +* @params seekLoc +* byte location to seek to +*/ +void TxtFile::seekPos(int seekLoc) { + fseek(fp, seekLoc, SEEK_SET); + currentFilePos = seekLoc; +} + +int TxtFile::getPos() { + return currentFilePos; +} + +int TxtFile::seekLineStart() { + int backCount = 0; + int c = 0; + + c = fgetc(fp); //get character at current position + + while ((c != '\n') && (c != '\r')) { //check if character is a newline or carriage return + backCount++; //increment backCount + fseek(fp, -2, SEEK_CUR); //seek back 2, 1 for the fgetc, 1 more to actually go back one + c = fgetc(fp); //get a new character + } + currentFilePos -= backCount; + return backCount; +} + +int TxtFile::seekLineEnd() { + int count = 0; + int c = 0; + + c = fgetc(fp); //get character at position after the newline or carriage return + + while ((c != '\n') && (c != '\r')) { //check if character is a newline or carriage return + count++; //increment main counter + c = fgetc(fp); //get a new character + } + currentFilePos += count; + return count; +} + +void TxtFile::seekLine(int line) { + if(isFileParsed) { + seekPos(fileLineStart[line - 1]); + } +} + +/** +* Returns the line length of the current line the 'seek head' is on +* +* @returns lineLength +*/ +int TxtFile::lineLength() { + int count; //initialise all values needed + + seekLineStart(); + + count = seekLineEnd(); + + return count; //return count, which is the number of characters in the line +} + +/** +* +*/ +void csvToIntArray(int line, int arrayStart, int arrayEnd, int *array) { + + +// int i = char a - '0' <---- really easy way to convert char to int. :D +} \ No newline at end of file
diff -r 000000000000 -r ddc821040077 txtFile.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/txtFile.h Thu Jun 11 13:50:10 2015 +0000 @@ -0,0 +1,79 @@ +/* +txtFile.h + +Header file containing outline for all methods dealing +with txt file data, editing, reading, searching etc. + +*/ + +#ifndef TXTFILE_H +#define TXTFILE_H + +#include "mbed.h" +#include "SDFileSystem.h" +#include <string> + +class TxtFile { + +public: +//constructor and deconstructor + TxtFile(char fileAddr[], char *readWrite, bool doParseFile); + ~TxtFile(); + + //returns whether a file is open or not + bool isOpen(); //done + + //closes the file and returns true if successful + bool closeFile(); //done + + //returns if the file is parsed or not + bool isParsed(); //done + + //counts the number of lines and sets the line start locations + void parseFile(); //needs testing + + //returns the number of lines + int lineCount(); + + //seeks to the position seekLoc + void seekPos(int seekLoc); //done + + //returns currentFilePos + int getPos(); //done + + //seeks to the start of the current line + int seekLineStart(); + + //seeks to the end of the current line + int seekLineEnd(); + + //seeks to a specific line start + void seekLine(int line); + + //returns which line pointer is on + int getLine(); + + //returns the length of the current line + int lineLength(); //done + + //converts a csv in a file to an array - will only read off one line + void csvToIntArray(int line, int arrayStart, int arrayEnd, int *array); + + //reads a line + void readLine(int line); + + +private: + + FILE *fp; + + bool isFileOpen; //value representing if the file is open or not + bool isFileParsed; //representing if the file has been parsed or not + + int noLines; //number of lines in the file, with a -1 offset (1 line = 0, 2 lines = 1 etc) + int fileLineStart[]; //starting seek location for every line in the file + int fileLineLength[]; //length of each line + int currentFilePos; //current position in the file relative to the start +}; + +#endif \ No newline at end of file