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: Control_Yokutan_CANver1 ADXL345_I2C mbed MPU6050
Fork of Souda_Yokutan_ver528TF by
Revision 59:2ec104dcd0e7, committed 2017-07-12
- Comitter:
- jaity
- Date:
- Wed Jul 12 12:33:00 2017 +0000
- Parent:
- 22:b38bc18ec3a1
- Commit message:
- (?????)???????????????????????
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sat Jan 28 02:28:06 2017 +0000
+++ b/main.cpp Wed Jul 12 12:33:00 2017 +0000
@@ -23,6 +23,8 @@
#define ERURON_TRIM_INI_L 113 //元々95
#define DRUG_TRIM_INI_L 110
+const char *configfilename = "config.csv";
+
CAN can(p30,p29);
CANMessage recmsg;
Serial pc(USBTX,USBRX);
@@ -35,16 +37,17 @@
DigitalOut led1(LED1);
AnalogIn drugAna(p20);
AnalogIn eruronAna(p19);
-DigitalIn LRstatePin(p14);
-DigitalIn setTrimPin(p15);
-DigitalIn EDstatePin(p16);
-DigitalIn checkMaxDegPin(p17);
+DigitalIn LRstatePin(p11);
+DigitalIn setTrimPin(p12);
+DigitalIn EDstatePin(p14);
+DigitalIn checkMaxDegPin(p15);
DigitalOut debugLED(LED2);
DigitalOut led3(LED3);
DigitalOut led4(LED4);
Ticker sendDatasTicker;
//Ticker toStringTicker;
Ticker receiveDatasTicker;
+LocalFileSystem local("local");
char toSendDatas[TO_SEND_DATAS_NUM];
char controlValues[CONTROL_VALUES_NUM];//0:eruruon,1:drug
@@ -102,8 +105,50 @@
return true;
}
+
+// configファイル作成
+int makeConfigFile() {
+ FILE *fp;
+ if((fp = fopen(configfilename, "w")) == NULL) {
+ pc.printf("can't open %s\n", configfilename);
+ return -1;
+ }
+ fprintf(fp, "// This is Yokutan %s.\n", LRstatePin ? "R" : "L");
+ fprintf(fp, "eruronTrim,drugTrim,eruronMoveDeg,drugMoveDeg\n");
+ fclose(fp);
+ return 0;
+}
+
+// config内容をファイルに追記
+int writeConfig() {
+ FILE *fp;
+ if((fp = fopen(configfilename, "a")) == NULL) {
+ pc.printf("can't open %s\n", configfilename);
+ return -1;
+ }
+ fprintf(fp, "%f,%f,%f,%f", eruronTrim, drugTrim, eruronMoveDeg, drugMoveDeg);
+ fclose(fp);
+ return 0;
+}
+
+// configの最新情報を読み込み
+int readConfig() {
+ FILE *fp;
+ char s[256];
+ if((fp = fopen(configfilename, "r")) == NULL) {
+ return -1;
+ }
+ while(fgets(s, 255, fp) != NULL) {
+ sprintf(s, "%lf,%lf,%lf,%lf", &eruronTrim, &drugTrim, &eruronMoveDeg, &drugMoveDeg);
+ }
+ fclose(fp);
+ return 0;
+}
+
void init(){
- if(!LRstatePin){
+ if(readConfig() == -1) {
+ makeConfigFile();
+ } else if(!LRstatePin){
eruronTrim = ERURON_TRIM_INI_L;
drugTrim = DRUG_TRIM_INI_L;
eruronMoveDeg = ERURON_MOVE_DEG_INI_L;
@@ -217,11 +262,17 @@
int main(){
init();
while(1){
- while(setTrimPin){
- setTrim();
+ if(setTrimPin) {
+ do {
+ setTrim();
+ } while(setTrimPin);
+ writeConfig();
}
- while(checkMaxDegPin){
- checkMaxDeg();
+ if(checkMaxDegPin) {
+ do {
+ checkMaxDeg();
+ } while(checkMaxDegPin);
+ writeConfig();
}
// pc.printf("eT:%f\n\r",eruronTrim);
pc.printf("eruronTrim:%f drugTrim:%f ",eruronTrim,drugTrim);
