Complete sensor demo.

Dependencies:   modem_ref_helper X_NUCLEO_IKS01A1 DebouncedInterrupt

Committer:
Jeej
Date:
Thu Oct 11 15:15:30 2018 +0000
Revision:
14:8fd5405f7ab2
Parent:
0:87c57e1b1e1c
Relaxed modem version check.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jeej 0:87c57e1b1e1c 1 #include "mbed.h"
Jeej 0:87c57e1b1e1c 2 #include "simul.h"
Jeej 0:87c57e1b1e1c 3 #include "WizziDebug.h"
Jeej 0:87c57e1b1e1c 4
Jeej 0:87c57e1b1e1c 5
Jeej 0:87c57e1b1e1c 6 unsigned int m_z=12434,m_w=33254;
Jeej 0:87c57e1b1e1c 7
Jeej 0:87c57e1b1e1c 8 unsigned int rnd() {
Jeej 0:87c57e1b1e1c 9 m_z = 36969 * (m_z & 65535) + (m_z >>16);
Jeej 0:87c57e1b1e1c 10 m_w = 18000 * (m_w & 65535) + (m_w >>16);
Jeej 0:87c57e1b1e1c 11 return ((m_z <<16) + m_w);
Jeej 0:87c57e1b1e1c 12 }
Jeej 0:87c57e1b1e1c 13
Jeej 0:87c57e1b1e1c 14 uint32_t g_simul_divider = 500;
Jeej 0:87c57e1b1e1c 15
Jeej 0:87c57e1b1e1c 16 void simul_update_param(uint32_t value)
Jeej 0:87c57e1b1e1c 17 {
Jeej 0:87c57e1b1e1c 18 g_simul_divider = value;
Jeej 0:87c57e1b1e1c 19 }
Jeej 0:87c57e1b1e1c 20
Jeej 0:87c57e1b1e1c 21 bool simul_sensor_value(int32_t* buf, uint32_t nb_values, int32_t min, int32_t max)
Jeej 0:87c57e1b1e1c 22 {
Jeej 0:87c57e1b1e1c 23 for (uint8_t i = 0; i < nb_values; i++)
Jeej 0:87c57e1b1e1c 24 {
Jeej 0:87c57e1b1e1c 25 int32_t new_value;
Jeej 0:87c57e1b1e1c 26
Jeej 0:87c57e1b1e1c 27 uint32_t r = rnd()%g_simul_divider;
Jeej 0:87c57e1b1e1c 28
Jeej 0:87c57e1b1e1c 29 if (r)
Jeej 0:87c57e1b1e1c 30 {
Jeej 0:87c57e1b1e1c 31 if (r%2)
Jeej 0:87c57e1b1e1c 32 {
Jeej 0:87c57e1b1e1c 33 new_value = buf[i] + 1;
Jeej 0:87c57e1b1e1c 34 }
Jeej 0:87c57e1b1e1c 35 else
Jeej 0:87c57e1b1e1c 36 {
Jeej 0:87c57e1b1e1c 37 new_value = buf[i] - 1;
Jeej 0:87c57e1b1e1c 38 }
Jeej 0:87c57e1b1e1c 39
Jeej 0:87c57e1b1e1c 40 if (new_value > max)
Jeej 0:87c57e1b1e1c 41 {
Jeej 0:87c57e1b1e1c 42 new_value = max;
Jeej 0:87c57e1b1e1c 43 }
Jeej 0:87c57e1b1e1c 44
Jeej 0:87c57e1b1e1c 45 if (new_value < min)
Jeej 0:87c57e1b1e1c 46 {
Jeej 0:87c57e1b1e1c 47 new_value = min;
Jeej 0:87c57e1b1e1c 48 }
Jeej 0:87c57e1b1e1c 49 }
Jeej 0:87c57e1b1e1c 50 else
Jeej 0:87c57e1b1e1c 51 {
Jeej 0:87c57e1b1e1c 52 new_value = (rnd()%(max - min)) + min;
Jeej 0:87c57e1b1e1c 53 }
Jeej 0:87c57e1b1e1c 54
Jeej 0:87c57e1b1e1c 55 buf[i] = new_value;
Jeej 0:87c57e1b1e1c 56 }
Jeej 0:87c57e1b1e1c 57
Jeej 0:87c57e1b1e1c 58 return false;
Jeej 0:87c57e1b1e1c 59 }
Jeej 0:87c57e1b1e1c 60