lib_Mbed_LPS

Committer:
YSI
Date:
Wed May 04 10:46:46 2016 +0000
Revision:
4:5e21f6f2e1f6
Parent:
3:660de8a5eff2
change exemple

Who changed what in which revision?

UserRevisionLine numberNew contents of line
YSI 0:a217c0617441 1 /** Lib Mbed LPS
YSI 0:a217c0617441 2 *
YSI 0:a217c0617441 3 * Copyright (c) 2014, cstyles (http://mbed.org)
YSI 0:a217c0617441 4 *
YSI 0:a217c0617441 5 * Exemple:
YSI 0:a217c0617441 6 * @code
YSI 0:a217c0617441 7 * #include "mbed.h"
YSI 0:a217c0617441 8 * #include "lib_Mbed_LPS.h"
YSI 0:a217c0617441 9 *
YSI 0:a217c0617441 10 *
YSI 0:a217c0617441 11 * Serial pc(USBTX,USBRX);
YSI 3:660de8a5eff2 12 * DigitalOut led(LED1);
YSI 0:a217c0617441 13 *
YSI 0:a217c0617441 14 * void interruption_serie(void);
YSI 0:a217c0617441 15 *
YSI 0:a217c0617441 16 *
YSI 0:a217c0617441 17 * int main()
YSI 0:a217c0617441 18 * {
YSI 3:660de8a5eff2 19 * if(!checkIDs()) return 0;
YSI 0:a217c0617441 20 * pc.attach(&interruption_serie);
YSI 0:a217c0617441 21 *
YSI 0:a217c0617441 22 * while(1)
YSI 0:a217c0617441 23 * {
YSI 3:660de8a5eff2 24 * led = !led;
YSI 0:a217c0617441 25 * wait(0.25);
YSI 0:a217c0617441 26 * }
YSI 0:a217c0617441 27 * }
YSI 0:a217c0617441 28 *
YSI 0:a217c0617441 29 * void interruption_serie(void)
YSI 0:a217c0617441 30 * {
YSI 0:a217c0617441 31 * char caractere = pc.getc();
YSI 0:a217c0617441 32 * switch(caractere)
YSI 0:a217c0617441 33 * {
YSI 0:a217c0617441 34 * case '?':
YSI 0:a217c0617441 35 * pc.printf("%s\r\n",getLastMbedFileName());
YSI 0:a217c0617441 36 * break;
YSI 0:a217c0617441 37 * }
YSI 0:a217c0617441 38 * }
YSI 0:a217c0617441 39 * @endcode
YSI 0:a217c0617441 40 * @file lib_Mbed_LPS.h
YSI 0:a217c0617441 41 * @purpose library for Mbed LPS
YSI 0:a217c0617441 42 * @date 2015
YSI 0:a217c0617441 43 * @author Yannic Simon
YSI 0:a217c0617441 44 */
YSI 0:a217c0617441 45
YSI 0:a217c0617441 46 #include "lib_Mbed_LPS.h"
YSI 0:a217c0617441 47
YSI 3:660de8a5eff2 48 /** Permet d'obtenir l'ID unique du Mbed
YSI 2:4c1d5218328e 49 *
YSI 2:4c1d5218328e 50 * @param ID pointeur sur une chaine de caractere contenant l'ID unique du Mbed
YSI 2:4c1d5218328e 51 */
YSI 0:a217c0617441 52 void getMbedID(char *ID)
YSI 0:a217c0617441 53 {
YSI 0:a217c0617441 54 LocalFileSystem local("mbed");
YSI 0:a217c0617441 55 FILE *fp = NULL;
YSI 0:a217c0617441 56 char * chp;
YSI 0:a217c0617441 57
YSI 0:a217c0617441 58 fp = fopen("/mbed/MBED.htm", "r");
YSI 3:660de8a5eff2 59 if(!fp) printf("Could not open directory!\r\n");
YSI 0:a217c0617441 60 else
YSI 0:a217c0617441 61 {
YSI 0:a217c0617441 62 fscanf(fp, "%*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s url=http://mbed.org/start?auth=%s", ID);
YSI 0:a217c0617441 63 chp = strchr(ID,'&');
YSI 0:a217c0617441 64 *chp = '\0';
YSI 0:a217c0617441 65 fclose(fp);
YSI 0:a217c0617441 66 }
YSI 0:a217c0617441 67 }
YSI 0:a217c0617441 68
YSI 2:4c1d5218328e 69 /** Renvoie true si l'ID unique du Mbed correspond à celui attendu
YSI 2:4c1d5218328e 70 *
YSI 2:4c1d5218328e 71 */
YSI 0:a217c0617441 72 bool checkIDs(void)
YSI 0:a217c0617441 73 {
YSI 0:a217c0617441 74 char ID[100];
YSI 0:a217c0617441 75 getMbedID(&ID[0]);
YSI 0:a217c0617441 76 if(strncmp(ID, MBED_ID, strlen(MBED_ID)) != 0)
YSI 0:a217c0617441 77 {
YSI 0:a217c0617441 78 printf("unknown Mbed\r\n");
YSI 3:660de8a5eff2 79 return false;
YSI 0:a217c0617441 80 }
YSI 3:660de8a5eff2 81 return true;
YSI 0:a217c0617441 82 }
YSI 0:a217c0617441 83
YSI 2:4c1d5218328e 84 /** Renvoie une chaine de caractere contenant le nom du dernier fichier cree sur le Mbed
YSI 2:4c1d5218328e 85 *
YSI 2:4c1d5218328e 86 */
YSI 0:a217c0617441 87 char * getLastMbedFileName(void)
YSI 0:a217c0617441 88 {
YSI 0:a217c0617441 89 LocalFileSystem local("mbed");
YSI 0:a217c0617441 90 DIR *d;
YSI 0:a217c0617441 91 struct dirent *p;
YSI 0:a217c0617441 92 static char file_name[20];
YSI 0:a217c0617441 93
YSI 0:a217c0617441 94 d = opendir("/mbed");
YSI 0:a217c0617441 95 if (d != NULL)
YSI 0:a217c0617441 96 {
YSI 0:a217c0617441 97 while((p = readdir(d)) != NULL) sprintf(file_name,"%s", p->d_name);
YSI 0:a217c0617441 98 }
YSI 0:a217c0617441 99 else
YSI 0:a217c0617441 100 {
YSI 3:660de8a5eff2 101 printf("Could not open directory!\r\n");
YSI 0:a217c0617441 102 }
YSI 0:a217c0617441 103 closedir(d);
YSI 0:a217c0617441 104 return file_name;
YSI 0:a217c0617441 105 }