More HACMan stuff

Dependencies:   FatFileSystem SDFileSystem mbed

Files at this revision

API Documentation at this revision

Comitter:
TBSliver
Date:
Thu Jun 11 13:49:01 2015 +0000
Commit message:
Initial no idea whats here commit

Changed in this revision

FatFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
fileSys.cpp Show annotated file Show diff for this revision Revisions of this file
fileSys.h Show annotated file Show diff for this revision Revisions of this file
ledSign.cpp Show annotated file Show diff for this revision Revisions of this file
ledSign.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
txtFile.cpp Show annotated file Show diff for this revision Revisions of this file
txtFile.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r f433ff34d66b FatFileSystem.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FatFileSystem.lib	Thu Jun 11 13:49:01 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/TBSliver/code/FatFileSystem/#e4324838bc6f
diff -r 000000000000 -r f433ff34d66b SDFileSystem.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SDFileSystem.lib	Thu Jun 11 13:49:01 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/SomeRandomBloke/code/SDFileSystem/#9c5f0c655284
diff -r 000000000000 -r f433ff34d66b fileSys.cpp
diff -r 000000000000 -r f433ff34d66b fileSys.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/fileSys.h	Thu Jun 11 13:49:01 2015 +0000
@@ -0,0 +1,16 @@
+#ifndef FILESYS_H
+#define FILESYS_H
+
+#include "mbed.h"
+#include "SDFileSystem.h"
+#include <string>
+
+class FileSys {
+
+public:
+
+private:
+
+};
+
+#endif
\ No newline at end of file
diff -r 000000000000 -r f433ff34d66b ledSign.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ledSign.cpp	Thu Jun 11 13:49:01 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 f433ff34d66b ledSign.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ledSign.h	Thu Jun 11 13:49:01 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 f433ff34d66b main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Jun 11 13:49:01 2015 +0000
@@ -0,0 +1,152 @@
+#include "mbed.h"
+#include "SDFileSystem.h"
+#include <string>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "ledSign.h"
+#include "txtFile.h"
+
+int frameLength = 4167;
+
+SDFileSystem sd(p5, p6, p7, p8, "sd");
+LedSign sign;
+
+Timer timer;
+
+//displaying stuff and variables needed
+void displayLed(char ledFile[]);
+bool ledParsed = false;
+int noFrames = 0;
+int curFrame = 0;
+int frameTime = 0;
+void writeFrame(int frame);
+
+
+//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 rootDir[10];
+
+void readDir();
+
+int curFile;
+
+void buttonCheck();
+
+DigitalIn buttonUp(p9);
+DigitalIn buttonDown(p10);
+
+int buttonCount = 0;
+
+//DigitalOut myled1(LED1);
+//DigitalOut myled2(LED2);
+
+int main() {
+    sign.enable();
+    readDir();
+    
+    /*for(int i = 0; i < 10 ; i++) {
+    printf("%s\n", rootDir[i]);
+    }*/
+    
+    curFile = 0;
+    
+    while(true) {
+    //myled1 = !myled1;
+    char toShow[20];
+    sprintf(toShow,"/sd/%s", rootDir[curFile]);
+    displayLed(toShow);
+    buttonCheck();
+    } 
+}
+
+void displayLed(char ledFile[]) {
+    TxtFile file(ledFile, "r");
+    if(file.isOpen()) {
+    
+        if(!ledParsed) {
+            noFrames = file.totalFrames();
+            curFrame = 0;
+            ledParsed = true;
+        }
+        
+        if(timer.read_ms() >= frameTime) {
+        //myled2 = !myled2;
+        timer.stop();
+        timer.reset();
+        if(curFrame == 0) {
+            frameTime = file.frameTime(curFrame);
+            for(int i=0;i<32;i++) {
+                for(int j=0;j<128;j++) {
+                    int pointing = (curFrame * frameLength) + 7 + (i * 130) + j;
+                    readRow[j] = file.getChar(pointing) - '0';
+                }
+                sign.writeRow(readRow, i);
+            }
+            sign.swapBank();
+            curFrame++;
+            timer.start();
+        } else {
+            frameTime = file.frameTime(curFrame);
+            for(int i=0;i<32;i++) {
+                for(int j=0;j<128;j++) {
+                    int pointing = (curFrame * frameLength) + 7 + (i * 130) + j;
+                    readRow[j] = file.getChar(pointing) - '0';
+                }
+                sign.writeRow(readRow, i);
+            }
+            sign.swapBank();
+            curFrame++;
+            timer.start();
+        }
+        
+        if(curFrame == noFrames) {
+            curFrame = 0;
+        }
+        
+        }
+        
+        
+    }
+}
+
+void readDir() {
+    DIR *d;
+    struct dirent *p;
+
+    d = opendir("/sd");
+    if (d != NULL) {
+        int i = 0;
+        while ((p = readdir(d)) != NULL) {
+            rootDir[i] = p->d_name;
+            //printf(" - %s\n", p->d_name);
+            i++;
+        }
+    } else {
+        //printf("Could not open directory!\n");
+    }
+    closedir(d);
+}
+
+void buttonCheck() {
+    if(buttonUp && (buttonCount == 0)) {
+        curFile++;
+        ledParsed = false;
+        buttonCount = 10;
+    }
+    if(buttonDown && (buttonCount == 0)) {
+        curFile--;
+        ledParsed = false;
+        buttonCount = 10;
+    }
+    if(curFile>9)
+        curFile = 0;
+    else if(curFile<0)
+        curFile = 9;
+    
+    if(buttonCount != 0)
+        buttonCount--;
+}
\ No newline at end of file
diff -r 000000000000 -r f433ff34d66b mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Jun 11 13:49:01 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/737756e0b479
\ No newline at end of file
diff -r 000000000000 -r f433ff34d66b txtFile.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/txtFile.cpp	Thu Jun 11 13:49:01 2015 +0000
@@ -0,0 +1,71 @@
+#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) {
+
+
+    if ((fp = fopen(fileAddr, readWrite)) == NULL) {
+        isFileOpen = false;
+    } else {
+        isFileOpen = 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;
+}
+
+/**
+* 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;
+}
+
+int TxtFile::frameTime(int frame) { //a frame is 5 digits of timer, 128x32 bytes of data, with 33 line ends
+    fseek(fp, (frame * 4167), SEEK_SET);
+    char numberIn[5];
+    for (int i=0;i<5;i++)
+    {
+        numberIn[i] = fgetc(fp);
+    }
+    return atoi(numberIn);
+}
+
+int TxtFile::totalFrames() {
+    fseek(fp, 0, SEEK_END); // seek to end of file
+    int size = ftell(fp);       // get current file pointer
+    fseek(fp, 0, SEEK_SET); // seek back to beginning of file
+    return (size + 2)/4167;
+}
+
+char TxtFile::getChar(int seek) {
+    fseek(fp, seek, SEEK_SET);
+    return fgetc(fp);
+}
\ No newline at end of file
diff -r 000000000000 -r f433ff34d66b txtFile.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/txtFile.h	Thu Jun 11 13:49:01 2015 +0000
@@ -0,0 +1,34 @@
+#ifndef TXTFILE_H
+#define TXTFILE_H
+
+#include "mbed.h"
+#include "SDFileSystem.h"
+#include <string>
+#include <stdio.h>
+#include <stdlib.h>
+
+class TxtFile {
+
+public:
+    //constructor and deconstructor
+    TxtFile(char fileAddr[], char *readWrite);
+    ~TxtFile();
+    
+    //returns whether a file is open or not
+    bool isOpen();                  //done
+    
+    //closes the file and returns true if successful
+    bool closeFile();
+    
+    int frameTime(int frame);
+    int totalFrames();
+    char getChar(int seek);
+    
+private:
+
+    FILE *fp;
+    bool isFileOpen;                //value representing if the file is open or not
+
+};
+
+#endif
\ No newline at end of file