Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Ping SDFileSystem mbed-src
Diff: format.cpp
- Revision:
- 1:7070fb876a2c
- Parent:
- 0:2f48b11b154f
- Child:
- 2:9a51bb2694aa
diff -r 2f48b11b154f -r 7070fb876a2c format.cpp
--- a/format.cpp Thu Dec 31 05:16:23 2015 +0000
+++ b/format.cpp Thu Dec 31 06:10:30 2015 +0000
@@ -7,42 +7,16 @@
char buf[BUFSIZE];
uint16_t FileData[FDATA_NUM]={0}, num, data;
uint8_t spi_num, h_byte, l_byte;
- uint16_t spi_data;
int i;
FILE *fp;
+ char *fname="/sd/mydir/sdtest.txt";
+ char *dname="/sd/mydir";
+
+ mkdir(dname, 0777);
+
pc.printf("Hello World!\n");
- mkdir("/sd/mydir", 0777);
-
- while(1){
-
- val = nucleo.receive();
- if(!val) return;
-
- spi_num = device.read();
- h_byte = device.read();
- l_byte = device.read();
-
- if((spi_num&0x80)>>7 == 1){
-
- }
- else{
-
- }
- if(val) {
-
- packet = (front_dis&0x00FF);
- nucleo.reply(packet);
- packet = (front_dis&0xFF00)>>8;
- nucleo.reply(packet);
- packet = (rear_dis&0x00FF);
- nucleo.reply(packet);
- packet = (rear_dis&0xFF00)>>8;
- nucleo.reply(packet);
- }
- // example writing to SD card, sford
-
- fp = fopen("/sd/mydir/sdtest.txt", "r");
+ fp = fopen(fname, "r");
if(fp == NULL) {
error("Could not open file for read\n");
}
@@ -61,7 +35,7 @@
}
}
fclose(fp);
-
+ /*
FileData[0] = 1;
FileData[1] = 2;
FileData[2] = 5;
@@ -73,10 +47,44 @@
FileData[8] = 50;
FileData[9] = 100;
- fp = fopen("/sd/mydir/sdtest.txt", "w");
+ fp = fopen(fname, "w");
for(i=0; i<FDATA_NUM; i++) fprintf(fp, "%d, %ld\n", i, FileData[i]);
fclose(fp);
+ */
+
+ while(1){
+
+ val = nucleo.receive();
+ if(!val) continue;
+
+ spi_num = device.read();
+ h_byte = device.read();
+ l_byte = device.read();
+
+ if((spi_num&0x80)>>7 == 1){//writing to sd
+ spi_num = spi_num & 0x7F;
+ if((spi_num>=0)&&(spi_num<FDATA_NUM)){
+ FileData[spi_num] = (h_byte<<8) | l_byte;
+ //pc.printf("%d, %ld\n", num, FileData[num]);
+ fp = fopen(fname, "w");
+ for(i=0; i<FDATA_NUM; i++) fprintf(fp, "%d, %ld\n", i, FileData[i]);
+ fclose(fp);
+ }
+ }
+ else{//reading from sd
+ spi_num = spi_num & 0x7F;
+ if((spi_num>=0)&&(spi_num<FDATA_NUM)){
+ h_byte = (FileData[spi_num] & 0xFF00)>>8;
+ l_byte = (FileData[spi_num] & 0x00FF);
+
+ packet = h_byte;
+ nucleo.reply(packet);
+
+ packet = l_byte;
+ nucleo.reply(packet);
+ }
+ }
//pc.printf("Goodbye World!\n");
}
}
@@ -124,10 +132,24 @@
#ifdef COLOR_SENSOR
void Color_System(void){
-
+ uint8_t val, order, packet;
+ uint8_t h_byte, l_byte;
+ uint16_t data;
+
while(1){
-
- ColorSensor[0]
+ while(1){
+ val = nucleo.receive();
+ if(val){
+ order = nucleo.read();
+ order %= SENSOR_X_COLOR;
+ data = ColorSensor[order/SENSOR_NUM][order%COLOR_NUM].read_u16();
+ packet = (data & 0xFF00)>>8;
+ nucleo.reply(packet);
+ }
+ else{
+ break;
+ }
+ }
}
}
#endif /*COLOR_SENSOR*/
@@ -157,18 +179,17 @@
for(ch=0; ch<IR_NUM[ic]; ch++){//Ch
command_high = START_BIT | MODE_SINGLE | ((ch & 0x04) >> 2);
command_low = (ch & 0x03) << 6;
-
+
cs[ic] = 0;
-
+
ir.write(command_high);
high_byte = ir.write(command_low) & 0x0F;
low_byte = ir.write(0);
-
+
cs[ic] = 1;
wait_us(1);
-
- //ir_data[ic][ch] = (high_byte << 8) | low_byte;
- ir_data[ic][ch] = ((high_byte << 4) | (low_byte >> 4))&0xFF;
+ ir_data[ic][ch] = ((high_byte << 4) | (low_byte >> 4))&0xFF;
+
}
}
while(1){
@@ -177,12 +198,6 @@
order = nucleo.read();
packet = ir_data[order/10][order%10] & 0x00FF;
nucleo.reply(packet);
- //for(ic=0; ic<IC_NUM; ic++){//IC
- // for(ch=0; ch<IR_NUM[ic]; ch++){//Ch
- // packet = ir_data[ic][ch] & 0x00FF;
- // nucleo.reply(packet);
- // }
- //}
}
else{
break;