formatting
This commit is contained in:
@ -21,24 +21,27 @@ int main(void)
|
|||||||
int ret;
|
int ret;
|
||||||
unsigned int period_ms = BLINK_PERIOD_MS_MAX;
|
unsigned int period_ms = BLINK_PERIOD_MS_MAX;
|
||||||
const struct device *sensor, *blink;
|
const struct device *sensor, *blink;
|
||||||
struct sensor_value last_val = { 0 }, val;
|
struct sensor_value last_val = {0}, val;
|
||||||
|
|
||||||
printk("Zephyr Example Application %s\n", APP_VERSION_STRING);
|
printk("Zephyr Example Application %s\n", APP_VERSION_STRING);
|
||||||
|
|
||||||
sensor = DEVICE_DT_GET(DT_NODELABEL(example_sensor));
|
sensor = DEVICE_DT_GET(DT_NODELABEL(example_sensor));
|
||||||
if (!device_is_ready(sensor)) {
|
if (!device_is_ready(sensor))
|
||||||
|
{
|
||||||
LOG_ERR("Sensor not ready");
|
LOG_ERR("Sensor not ready");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
blink = DEVICE_DT_GET(DT_NODELABEL(blink_led));
|
blink = DEVICE_DT_GET(DT_NODELABEL(blink_led));
|
||||||
if (!device_is_ready(blink)) {
|
if (!device_is_ready(blink))
|
||||||
|
{
|
||||||
LOG_ERR("Blink LED not ready");
|
LOG_ERR("Blink LED not ready");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = blink_off(blink);
|
ret = blink_off(blink);
|
||||||
if (ret < 0) {
|
if (ret < 0)
|
||||||
|
{
|
||||||
LOG_ERR("Could not turn off LED (%d)", ret);
|
LOG_ERR("Could not turn off LED (%d)", ret);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -47,23 +50,30 @@ int main(void)
|
|||||||
|
|
||||||
printk("Use the sensor to change LED blinking period\n");
|
printk("Use the sensor to change LED blinking period\n");
|
||||||
|
|
||||||
while (1) {
|
while (1)
|
||||||
|
{
|
||||||
ret = sensor_sample_fetch(sensor);
|
ret = sensor_sample_fetch(sensor);
|
||||||
if (ret < 0) {
|
if (ret < 0)
|
||||||
|
{
|
||||||
LOG_ERR("Could not fetch sample (%d)", ret);
|
LOG_ERR("Could not fetch sample (%d)", ret);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = sensor_channel_get(sensor, SENSOR_CHAN_PROX, &val);
|
ret = sensor_channel_get(sensor, SENSOR_CHAN_PROX, &val);
|
||||||
if (ret < 0) {
|
if (ret < 0)
|
||||||
|
{
|
||||||
LOG_ERR("Could not get sample (%d)", ret);
|
LOG_ERR("Could not get sample (%d)", ret);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((last_val.val1 == 0) && (val.val1 == 1)) {
|
if ((last_val.val1 == 0) && (val.val1 == 1))
|
||||||
if (period_ms == 0U) {
|
{
|
||||||
|
if (period_ms == 0U)
|
||||||
|
{
|
||||||
period_ms = BLINK_PERIOD_MS_MAX;
|
period_ms = BLINK_PERIOD_MS_MAX;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
period_ms -= BLINK_PERIOD_MS_STEP;
|
period_ms -= BLINK_PERIOD_MS_STEP;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,4 +89,3 @@ int main(void)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user