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.
cmd_set_get.cpp
00001 #include "mbed.h" 00002 #include "CommandProcessor.h" 00003 #include "globals.h" 00004 00005 #define FPRINT(a) pc->printf("%s: %f\n", #a, a) 00006 #define DPRINT(a) pc->printf("%s: %d\n", #a, a) 00007 00008 void cmd_ls(Serial *pc) { 00009 DPRINT(PREFS_VALID); 00010 FPRINT(I_LIMIT); 00011 FPRINT(KP); 00012 FPRINT(KI); 00013 FPRINT(F_SW); 00014 FPRINT(THROTTLE_DEADBAND); 00015 FPRINT(ANALOG_THROTTLE_LOW); 00016 FPRINT(ANALOG_THROTTLE_HI); 00017 } 00018 00019 void cmd_ls2(Serial *pc, char *buf) { 00020 if (strcmp(buf, "src") == 0) { 00021 pc->printf("%s\n", src_to_str(BREMS_src)); 00022 return; 00023 } 00024 if (strcmp(buf, "op") == 0) { 00025 pc->printf("%s\n", op_to_str(BREMS_op)); 00026 return; 00027 } 00028 00029 float *fptr = checkf(buf); 00030 if (fptr != NULL) pc->printf("%s: %f\n", buf, *fptr); 00031 int *nptr = NULL; 00032 if (fptr == NULL) nptr = checkn(buf); 00033 if (nptr != NULL) pc->printf("%s: %d\n", buf, *nptr); 00034 if (nptr == NULL && fptr == NULL) pc->printf("%s\n", "No Such Parameter"); 00035 } 00036 00037 void cmd_set(Serial *pc, char *buf, char *val) { 00038 float *fptr = checkf(buf); 00039 if (fptr != NULL) *fptr = (float) (atof(val)); 00040 int *nptr = NULL; 00041 if (fptr == NULL) nptr = checkn(buf); 00042 if (nptr != NULL) *nptr = (int) (atoi(val)); 00043 if (nptr != NULL || fptr != NULL) cmd_ls2(pc, buf); 00044 if (nptr == NULL && fptr == NULL) pc->printf("%s\n", "No Such Parameter"); 00045 } 00046 00047 void cmd_flush(Serial *pc, PreferenceWriter *pref) { 00048 if (!pref->ready()) pref->open(); 00049 PREFS_VALID = 1; 00050 pref->flush(); 00051 } 00052 00053 void cmd_reload(Serial *pc, PreferenceWriter *pref) { 00054 pref->load(); 00055 if (PREFS_VALID) pc->printf("Flash Values Loaded\n"); 00056 } 00057 00058 void cmd_query(Serial *pc, char *buf) { 00059 if (strcmp(buf, "i") == 0) pc->printf("%f\n", current); 00060 else if (strcmp(buf, "cmd") == 0) pc->printf("%f\n", throttle); 00061 else if (strcmp(buf, "v") == 0) pc->printf("%f\n", vout); 00062 else pc->printf("%s\n", "No such parameter"); 00063 }
Generated on Tue Jul 12 2022 21:21:55 by
