Application testing co-operation of X-NUCLEO boards IKS01A1 (sensors) and IDW01M1 (wifi)
Dependencies: X_NUCLEO_IDW01M1v2-lapi-1 X_NUCLEO_IKS01A1-lapi-1
Fork of x-nucleo-iks01a1-test by
Revision 4:bb94144b323f, committed 2017-01-24
- Comitter:
- aeg25
- Date:
- Tue Jan 24 12:17:13 2017 +0000
- Parent:
- 3:54f935a7d9c1
- Commit message:
- k?di
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 54f935a7d9c1 -r bb94144b323f main.cpp --- a/main.cpp Tue Jan 24 11:51:49 2017 +0000 +++ b/main.cpp Tue Jan 24 12:17:13 2017 +0000 @@ -15,43 +15,11 @@ // (note the calls to Thread::wait below for delays) -static char *printDouble(char* str, double v, int decimalDigits=2) -{ - int i = 1; - int intPart, fractPart; - int len; - char *ptr; - /* prepare decimal digits multiplicator */ - for (;decimalDigits!=0; i*=10, decimalDigits--); - - /* calculate integer & fractinal parts */ - intPart = (int)v; - fractPart = (int)((v-(double)(int)v)*i); - - /* fill in integer part */ - sprintf(str, "%i.", intPart); - - /* prepare fill in of fractional part */ - len = strlen(str); - ptr = &str[len]; - - /* fill in leading fractional zeros */ - for (i/=10;i>1; i/=10, ptr++) { - if(fractPart >= i) break; - *ptr = '0'; - } - - /* fill in (rest of) fractional part */ - sprintf(ptr, "%i", fractPart); - - return str; -} int main() { - uint8_t id; - float temp_val, hum_val, press_val; - char buffer1[32], buffer2[32]; + + char buffer2[32]; int32_t axes[3]; Serial pc(USBTX, USBRX); DevI2C i2c(D14, D15); @@ -91,9 +59,7 @@ Thread::wait(5000); pc.printf("Connecting...\n\r"); - - while (true) { - led1 = !led1; + led1 = !led1; float temperature = 0.0; status = htsensor.GetTemperature(&temperature); float humidity = 0.0; @@ -116,31 +82,34 @@ printf("LSM6DS0 [gyro/mdps]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]); printf("Starting again.."); - + + while (true) { + printf("Enter sensor name(1 for temperature, 2 for humidity, 3 for pressure ): \r\n"); - scanf("%c", &input); + Thread::wait(1500); // pc.printf("IP address %s\n", wifiIf.get_ip_address()); printf("Enter 1 for heat, humidity and pressure \n\r "); - printf("Enter b for acceleration, gyroscope, magnitude \n\r "); + printf("Enter 2 for acceleration, gyroscope, magnitude \n\r "); scanf("%i", &cinput); if((cinput==1)){ - printf("%f\n",temperature); + printf("[Temperature] %f\n\r",temperature); + printf("[Humidity] %f\n\r",humidity); + printf("[Pressure] %f\n\r",pressure); } - if(input == 2) - { - printf("[humidity] %s%%\r\n", printDouble(buffer2, hum_val)); - } - - - if(input == 3) - { - printf("[pressure] %smbar\r\n", printDouble(buffer2, press_val)); - } - + if((cinput==2)){ + magnetometer->Get_M_Axes(axes); + printf("[Magnetism] [mag/mgauss]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]); + + accelerometer->Get_X_Axes(axes); + printf("[Acceleration] [acc/mg]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]); + + gyroscope->Get_G_Axes(axes); + printf("[Gyroscope] [gyro/mdps]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]); + } } }