mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +03:00
Examples: Added C Examples
Added examples for: mq303a m24lr64e mpr121 servo a110x gp2y0a ttp223 loudness tsl2561 Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
This commit is contained in:
parent
373a79fb91
commit
d548fc62ab
@ -104,6 +104,15 @@ add_example (ldt0028)
|
||||
add_example (joystick12)
|
||||
add_example (flex)
|
||||
add_example (slide)
|
||||
add_example (mq303a)
|
||||
add_example (m24lr64e)
|
||||
add_example (mpr121)
|
||||
add_example (servo)
|
||||
add_example (a110x)
|
||||
add_example (gp2y0a)
|
||||
add_example (ttp223)
|
||||
add_example (loudness)
|
||||
add_example (tsl2561)
|
||||
|
||||
# Custom examples
|
||||
add_custom_example (nmea_gps_i2c-example-c nmea_gps_i2c.c nmea_gps)
|
||||
|
23
examples/c/a110x.c
Normal file
23
examples/c/a110x.c
Normal file
@ -0,0 +1,23 @@
|
||||
//Modified: Abhishek Malik <abhishek.malik@intel.com>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "a110x.h"
|
||||
|
||||
void main(void)
|
||||
{
|
||||
a110x_context dev = a110x_init(2);
|
||||
bool abc = 0;
|
||||
while(1){
|
||||
if(a110x_magnet_detected(dev, &abc) != UPM_SUCCESS){
|
||||
printf("an error has occured\n");
|
||||
}
|
||||
upm_delay(1);
|
||||
printf("value retrieved: %d\n", abc);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
25
examples/c/gp2y0a.c
Normal file
25
examples/c/gp2y0a.c
Normal file
@ -0,0 +1,25 @@
|
||||
//Modified: Abhishek Malik <abhishek.malik@intel.com>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "gp2y0a.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
gp2y0a_context dev = gp2y0a_init(14, 5.0);
|
||||
float val;
|
||||
while(1){
|
||||
if(gp2y0a_get_value(dev, 5.0, 20, &val) != UPM_SUCCESS){
|
||||
printf("Failed to get any values from the sensor\n");
|
||||
}
|
||||
printf("Moisture Value: %f\n", val);
|
||||
upm_delay(1);
|
||||
}
|
||||
gp2y0a_close(dev);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
25
examples/c/grovemoisture.c
Normal file
25
examples/c/grovemoisture.c
Normal file
@ -0,0 +1,25 @@
|
||||
//Modified: Abhishek Malik <abhishek.malik@intel.com>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "grovemoisture.h"
|
||||
|
||||
void main(void)
|
||||
{
|
||||
grovemoisture_context dev = grovemoisture_init(14);
|
||||
int val;
|
||||
while(1){
|
||||
if(grovemoisture_get_moisture(dev, &val) != UPM_SUCCESS){
|
||||
printf("Failed to get any values from the sensor\n");
|
||||
}
|
||||
printf("Moisture Value: %d\n", val);
|
||||
upm_delay(1);
|
||||
}
|
||||
grovemoisture_close(dev);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
25
examples/c/loudness.c
Normal file
25
examples/c/loudness.c
Normal file
@ -0,0 +1,25 @@
|
||||
//Modified: Abhishek Malik <abhishek.malik@intel.com>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "loudness.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
loudness_context dev = loudness_init(14);
|
||||
int val;
|
||||
while(1){
|
||||
if(loudness_get_value(dev, &val) != UPM_SUCCESS){
|
||||
printf("Failed to get any values from the sensor\n");
|
||||
}
|
||||
printf("Loudness Value: %d\n", val);
|
||||
upm_delay(1);
|
||||
}
|
||||
loudness_close(dev);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
29
examples/c/m24lr64e.c
Normal file
29
examples/c/m24lr64e.c
Normal file
@ -0,0 +1,29 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "m24lr64e.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
m24lr64e_context dev = m24lr64e_init(0, M24LR64E_USER_MODE);
|
||||
int addr = M24LR64E_EEPROM_I2C_LENGTH-1;
|
||||
printf("address being accessed: %d\n", addr);
|
||||
uint8_t byte;
|
||||
if(m24lr64e_read_byte(dev, addr, &byte) != UPM_SUCCESS)
|
||||
printf("error while reading value\n");
|
||||
printf("value read from the device: %d\n", byte);
|
||||
byte = ~byte;
|
||||
printf("byte to be written: %d\n", byte);
|
||||
if(m24lr64e_write_byte(dev, addr, byte) != UPM_SUCCESS)
|
||||
printf("error while writing byte to the device\n");
|
||||
uint8_t var;
|
||||
if(m24lr64e_read_byte(dev, addr, &var) != UPM_SUCCESS)
|
||||
printf("error while reading value back\n");
|
||||
printf("new value at %d: %d\n", addr, var);
|
||||
m24lr64e_close(dev);
|
||||
printf("all done!!\n");
|
||||
|
||||
return 0;
|
||||
}
|
30
examples/c/mpr121.c
Normal file
30
examples/c/mpr121.c
Normal file
@ -0,0 +1,30 @@
|
||||
//Modified: Abhishek Malik <abhishek.malik@intel.com>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "mpr121.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
mpr121_context dev = mpr121_init(MPR121_I2C_BUS, MPR121_DEFAULT_I2C_ADDR);
|
||||
|
||||
if(mpr121_config_an3944(dev) != UPM_SUCCESS){
|
||||
printf("unable to configure device\n");
|
||||
}
|
||||
uint32_t states;
|
||||
while(1){
|
||||
if(mpr121_read_buttons(dev, &states, 0) != UPM_SUCCESS){
|
||||
printf("Error while reading button values\n");
|
||||
}
|
||||
printf("retrieved button states: %d\n", states);
|
||||
upm_delay(1);
|
||||
}
|
||||
|
||||
mpr121_close(dev);
|
||||
printf("all done!!\n");
|
||||
|
||||
return 0;
|
||||
}
|
26
examples/c/mq303a.c
Normal file
26
examples/c/mq303a.c
Normal file
@ -0,0 +1,26 @@
|
||||
//Modified: Abhishek Malik <abhishek.malik@intel.com>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "mq303a.h"
|
||||
|
||||
int main() {
|
||||
|
||||
/* --------- MQ303A EXAMPLE -------- */
|
||||
mq303a_context dev = mq303a_init(0, 15);
|
||||
printf("init done for mq303a\n");
|
||||
int value;
|
||||
mq303a_heater_enable(dev, true);
|
||||
upm_delay(12);
|
||||
while(1){
|
||||
mq303a_get_value(dev, &value);
|
||||
printf("returned value: %d\n", value);
|
||||
upm_delay(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
35
examples/c/servo.c
Normal file
35
examples/c/servo.c
Normal file
@ -0,0 +1,35 @@
|
||||
//Modified: Abhishek Malik <abhishek.malik@intel.com>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "es08a.c"
|
||||
|
||||
int main()
|
||||
{
|
||||
es08a_context dev = es08a_init(3, ES08A_MIN_PULSE_WIDTH, ES08A_MAX_PULSE_WIDTH);
|
||||
if(dev == NULL){
|
||||
printf("unable to initialize the servo context\n");
|
||||
}
|
||||
|
||||
if(es08a_set_angle(dev, 90) != UPM_SUCCESS){
|
||||
printf("unable to set angle to 90 degrees\n");
|
||||
}
|
||||
upm_delay(1);
|
||||
|
||||
if(es08a_set_angle(dev, 180) != UPM_SUCCESS){
|
||||
printf("unable to set angle to 180 degrees\n");
|
||||
}
|
||||
upm_delay(1);
|
||||
|
||||
if(es08a_set_angle(dev, 90) != UPM_SUCCESS){
|
||||
printf("unable to set angle to 90 degrees\n");
|
||||
}
|
||||
upm_delay(1);
|
||||
|
||||
es08a_halt(dev);
|
||||
|
||||
return 0;
|
||||
}
|
20
examples/c/tsl2561.c
Normal file
20
examples/c/tsl2561.c
Normal file
@ -0,0 +1,20 @@
|
||||
//Modified: Abhishek Malik <abhishek.malik@intel.com>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "tsl2561.h"
|
||||
|
||||
void main(void)
|
||||
{
|
||||
tsl2561_context dev = tsl2561_init(0, TSL2561_Address, GAIN_0X, INTEGRATION_TIME1_101MS);
|
||||
float abc = 0;
|
||||
if(tsl2561_get_lux(dev, &abc) != UPM_SUCCESS){
|
||||
printf("ERROR !! ERROR !! ERROR!!");
|
||||
}
|
||||
printf("value retrieved: %f\n", abc);
|
||||
|
||||
return 0;
|
||||
}
|
23
examples/c/ttp223.c
Normal file
23
examples/c/ttp223.c
Normal file
@ -0,0 +1,23 @@
|
||||
//Modified: Abhishek Malik <abhishek.malik@intel.com>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "ttp223.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
ttp223_context dev = ttp223_init(2);
|
||||
bool abc = 0;
|
||||
while(1){
|
||||
if(ttp223_is_pressed(dev, &abc) != UPM_SUCCESS){
|
||||
printf("an error has occured\n");
|
||||
}
|
||||
upm_delay(1);
|
||||
printf("value retrieved: %d\n", abc);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user