Source code for the Curilights Controller. See http://www.saccade.com/writing/projects/CuriController/ for details.
Dependencies: FatFileSystem mbed
This is the source code for the Curilights controller. This lets you interactively control a string of Curilights. It provides a simple click-wheel user interface for changing colors, brightness and behavior. It responds to movement and lighting.
Finished Controller
System Block Diagram
SDFileSystem.h@0:6da5625a6946, 2011-12-29 (annotated)
- Committer:
- isonno
- Date:
- Thu Dec 29 01:59:53 2011 +0000
- Revision:
- 0:6da5625a6946
Contest submission version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
isonno |
0:6da5625a6946 | 1 | /* mbed SDFileSystem Library, for providing file access to SD cards |
isonno |
0:6da5625a6946 | 2 | * Copyright (c) 2008-2010, sford |
isonno |
0:6da5625a6946 | 3 | * |
isonno |
0:6da5625a6946 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
isonno |
0:6da5625a6946 | 5 | * of this software and associated documentation files (the "Software"), to deal |
isonno |
0:6da5625a6946 | 6 | * in the Software without restriction, including without limitation the rights |
isonno |
0:6da5625a6946 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
isonno |
0:6da5625a6946 | 8 | * copies of the Software, and to permit persons to whom the Software is |
isonno |
0:6da5625a6946 | 9 | * furnished to do so, subject to the following conditions: |
isonno |
0:6da5625a6946 | 10 | * |
isonno |
0:6da5625a6946 | 11 | * The above copyright notice and this permission notice shall be included in |
isonno |
0:6da5625a6946 | 12 | * all copies or substantial portions of the Software. |
isonno |
0:6da5625a6946 | 13 | * |
isonno |
0:6da5625a6946 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
isonno |
0:6da5625a6946 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
isonno |
0:6da5625a6946 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
isonno |
0:6da5625a6946 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
isonno |
0:6da5625a6946 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
isonno |
0:6da5625a6946 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
isonno |
0:6da5625a6946 | 20 | * THE SOFTWARE. |
isonno |
0:6da5625a6946 | 21 | */ |
isonno |
0:6da5625a6946 | 22 | |
isonno |
0:6da5625a6946 | 23 | #ifndef MBED_SDFILESYSTEM_H |
isonno |
0:6da5625a6946 | 24 | #define MBED_SDFILESYSTEM_H |
isonno |
0:6da5625a6946 | 25 | |
isonno |
0:6da5625a6946 | 26 | #ifndef MBED_H |
isonno |
0:6da5625a6946 | 27 | #include "mbed.h" |
isonno |
0:6da5625a6946 | 28 | #endif |
isonno |
0:6da5625a6946 | 29 | |
isonno |
0:6da5625a6946 | 30 | #include "FATFileSystem.h" |
isonno |
0:6da5625a6946 | 31 | |
isonno |
0:6da5625a6946 | 32 | /** Access the filesystem on an SD Card using SPI |
isonno |
0:6da5625a6946 | 33 | * |
isonno |
0:6da5625a6946 | 34 | * @code |
isonno |
0:6da5625a6946 | 35 | * #include "mbed.h" |
isonno |
0:6da5625a6946 | 36 | * #include "SDFileSystem.h" |
isonno |
0:6da5625a6946 | 37 | * |
isonno |
0:6da5625a6946 | 38 | * SDFileSystem sd(p5, p6, p7, p12, "sd"); // mosi, miso, sclk, cs |
isonno |
0:6da5625a6946 | 39 | * |
isonno |
0:6da5625a6946 | 40 | * int main() { |
isonno |
0:6da5625a6946 | 41 | * FILE *fp = fopen("/sd/myfile.txt", "w"); |
isonno |
0:6da5625a6946 | 42 | * fprintf(fp, "Hello World!\n"); |
isonno |
0:6da5625a6946 | 43 | * fclose(fp); |
isonno |
0:6da5625a6946 | 44 | * } |
isonno |
0:6da5625a6946 | 45 | */ |
isonno |
0:6da5625a6946 | 46 | class SDFileSystem : public FATFileSystem { |
isonno |
0:6da5625a6946 | 47 | public: |
isonno |
0:6da5625a6946 | 48 | |
isonno |
0:6da5625a6946 | 49 | /** Create the File System for accessing an SD Card using SPI |
isonno |
0:6da5625a6946 | 50 | * |
isonno |
0:6da5625a6946 | 51 | * @param mosi SPI mosi pin connected to SD Card |
isonno |
0:6da5625a6946 | 52 | * @param miso SPI miso pin conencted to SD Card |
isonno |
0:6da5625a6946 | 53 | * @param sclk SPI sclk pin connected to SD Card |
isonno |
0:6da5625a6946 | 54 | * @param cs DigitalOut pin used as SD Card chip select |
isonno |
0:6da5625a6946 | 55 | * @param name The name used to access the virtual filesystem |
isonno |
0:6da5625a6946 | 56 | */ |
isonno |
0:6da5625a6946 | 57 | SDFileSystem(PinName mosi, PinName miso, PinName sclk, PinName cs, const char* name); |
isonno |
0:6da5625a6946 | 58 | virtual int disk_initialize(); |
isonno |
0:6da5625a6946 | 59 | virtual int disk_write(const char *buffer, int block_number); |
isonno |
0:6da5625a6946 | 60 | virtual int disk_read(char *buffer, int block_number); |
isonno |
0:6da5625a6946 | 61 | virtual int disk_status(); |
isonno |
0:6da5625a6946 | 62 | virtual int disk_sync(); |
isonno |
0:6da5625a6946 | 63 | virtual int disk_sectors(); |
isonno |
0:6da5625a6946 | 64 | |
isonno |
0:6da5625a6946 | 65 | protected: |
isonno |
0:6da5625a6946 | 66 | |
isonno |
0:6da5625a6946 | 67 | int _cmd(int cmd, int arg); |
isonno |
0:6da5625a6946 | 68 | int _cmdx(int cmd, int arg); |
isonno |
0:6da5625a6946 | 69 | int _cmd8(); |
isonno |
0:6da5625a6946 | 70 | int _cmd58(); |
isonno |
0:6da5625a6946 | 71 | int initialise_card(); |
isonno |
0:6da5625a6946 | 72 | int initialise_card_v1(); |
isonno |
0:6da5625a6946 | 73 | int initialise_card_v2(); |
isonno |
0:6da5625a6946 | 74 | |
isonno |
0:6da5625a6946 | 75 | int _read(char *buffer, int length); |
isonno |
0:6da5625a6946 | 76 | int _write(const char *buffer, int length); |
isonno |
0:6da5625a6946 | 77 | int _sd_sectors(); |
isonno |
0:6da5625a6946 | 78 | int _sectors; |
isonno |
0:6da5625a6946 | 79 | |
isonno |
0:6da5625a6946 | 80 | SPI _spi; |
isonno |
0:6da5625a6946 | 81 | DigitalOut _cs; |
isonno |
0:6da5625a6946 | 82 | }; |
isonno |
0:6da5625a6946 | 83 | |
isonno |
0:6da5625a6946 | 84 | #endif |