This is the project for the Old Model Robots for OU's Dr. Davis's Configurable Robots Research. This is being published so future robots can be set up easily.

Dependencies:   FatFileSystem MCP3008 Motor PinDetect QTR_8A SRF05 SSD1308_128x64_I2C mbed

Committer:
DrewSchaef
Date:
Wed Nov 01 15:57:59 2017 +0000
Revision:
0:bcad524c1856
Published the project to allow access for future work on the Configurable Robots Research Project(s).

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DrewSchaef 0:bcad524c1856 1 #include "mbed.h"
DrewSchaef 0:bcad524c1856 2 #include "FATFileSystem.h"
DrewSchaef 0:bcad524c1856 3 #include "Utils.h"
DrewSchaef 0:bcad524c1856 4
DrewSchaef 0:bcad524c1856 5 int MassStorage_ReadCapacity(int device, u32* blockCount, u32* blockSize);
DrewSchaef 0:bcad524c1856 6 int MassStorage_Read(int device, u32 blockAddr, u32 blockCount, u8* dst, u32 blockSize);
DrewSchaef 0:bcad524c1856 7 int MassStorage_Write(int device, u32 blockAddr, u32 blockCount, u8* dst, u32 blockSize);
DrewSchaef 0:bcad524c1856 8
DrewSchaef 0:bcad524c1856 9 class USBFileSystem : public FATFileSystem
DrewSchaef 0:bcad524c1856 10 {
DrewSchaef 0:bcad524c1856 11 int _device;
DrewSchaef 0:bcad524c1856 12 u32 _blockSize;
DrewSchaef 0:bcad524c1856 13 u32 _blockCount;
DrewSchaef 0:bcad524c1856 14
DrewSchaef 0:bcad524c1856 15 public:
DrewSchaef 0:bcad524c1856 16 USBFileSystem() : FATFileSystem("usb"),_device(0),_blockSize(0),_blockCount(0)
DrewSchaef 0:bcad524c1856 17 {
DrewSchaef 0:bcad524c1856 18 }
DrewSchaef 0:bcad524c1856 19
DrewSchaef 0:bcad524c1856 20 void SetDevice(int device)
DrewSchaef 0:bcad524c1856 21 {
DrewSchaef 0:bcad524c1856 22 _device = device;
DrewSchaef 0:bcad524c1856 23 }
DrewSchaef 0:bcad524c1856 24
DrewSchaef 0:bcad524c1856 25 virtual int disk_initialize()
DrewSchaef 0:bcad524c1856 26 {
DrewSchaef 0:bcad524c1856 27 return MassStorage_ReadCapacity(_device,&_blockCount,&_blockSize);
DrewSchaef 0:bcad524c1856 28 }
DrewSchaef 0:bcad524c1856 29
DrewSchaef 0:bcad524c1856 30 virtual int disk_write(const char *buffer, int block_number)
DrewSchaef 0:bcad524c1856 31 {
DrewSchaef 0:bcad524c1856 32 return MassStorage_Write(_device,block_number,1,(u8*)buffer,_blockSize);
DrewSchaef 0:bcad524c1856 33 }
DrewSchaef 0:bcad524c1856 34
DrewSchaef 0:bcad524c1856 35 virtual int disk_read(char *buffer, int block_number)
DrewSchaef 0:bcad524c1856 36 {
DrewSchaef 0:bcad524c1856 37 return MassStorage_Read(_device,block_number,1,(u8*)buffer,_blockSize);
DrewSchaef 0:bcad524c1856 38 }
DrewSchaef 0:bcad524c1856 39
DrewSchaef 0:bcad524c1856 40 virtual int disk_sectors()
DrewSchaef 0:bcad524c1856 41 {
DrewSchaef 0:bcad524c1856 42 return _blockCount;
DrewSchaef 0:bcad524c1856 43 }
DrewSchaef 0:bcad524c1856 44 };
DrewSchaef 0:bcad524c1856 45
DrewSchaef 0:bcad524c1856 46 void DumpFS(int depth, int count)
DrewSchaef 0:bcad524c1856 47 {
DrewSchaef 0:bcad524c1856 48 DIR *d = opendir("/usb");
DrewSchaef 0:bcad524c1856 49 if (!d)
DrewSchaef 0:bcad524c1856 50 {
DrewSchaef 0:bcad524c1856 51 printf("USB file system borked\n");
DrewSchaef 0:bcad524c1856 52 return;
DrewSchaef 0:bcad524c1856 53 }
DrewSchaef 0:bcad524c1856 54
DrewSchaef 0:bcad524c1856 55 printf("\nDumping root dir\n");
DrewSchaef 0:bcad524c1856 56 struct dirent *p;
DrewSchaef 0:bcad524c1856 57 for(;;)
DrewSchaef 0:bcad524c1856 58 {
DrewSchaef 0:bcad524c1856 59 p = readdir(d);
DrewSchaef 0:bcad524c1856 60 if (!p)
DrewSchaef 0:bcad524c1856 61 break;
DrewSchaef 0:bcad524c1856 62 int len = sizeof( dirent);
DrewSchaef 0:bcad524c1856 63 printf("%s %d\n", p->d_name, len);
DrewSchaef 0:bcad524c1856 64 }
DrewSchaef 0:bcad524c1856 65 closedir(d);
DrewSchaef 0:bcad524c1856 66 }
DrewSchaef 0:bcad524c1856 67
DrewSchaef 0:bcad524c1856 68 int OnDiskInsert(int device)
DrewSchaef 0:bcad524c1856 69 {
DrewSchaef 0:bcad524c1856 70 USBFileSystem fs;
DrewSchaef 0:bcad524c1856 71 fs.SetDevice(device);
DrewSchaef 0:bcad524c1856 72 DumpFS(0,0);
DrewSchaef 0:bcad524c1856 73 return 0;
DrewSchaef 0:bcad524c1856 74 }