Handle LoRa Basic Function

Dependents:   lora_example_miun

Committer:
biwa1400
Date:
Wed Mar 08 18:54:32 2017 +0000
Revision:
0:f8af47d9f0cd
20170308

Who changed what in which revision?

UserRevisionLine numberNew contents of line
biwa1400 0:f8af47d9f0cd 1 #include "mbed.h"
biwa1400 0:f8af47d9f0cd 2 #include "ADC.h"
biwa1400 0:f8af47d9f0cd 3 #include "MTSLog.h"
biwa1400 0:f8af47d9f0cd 4
biwa1400 0:f8af47d9f0cd 5
biwa1400 0:f8af47d9f0cd 6 const int ADC_TOTAL_BITS = 16;
biwa1400 0:f8af47d9f0cd 7 const int ADC_bits = 8;
biwa1400 0:f8af47d9f0cd 8 const int ADC_period=50;
biwa1400 0:f8af47d9f0cd 9 const int ADC_sample_times = 64;
biwa1400 0:f8af47d9f0cd 10 const int ADC_average_move = 6;
biwa1400 0:f8af47d9f0cd 11
biwa1400 0:f8af47d9f0cd 12 AnalogIn Distance(PB_1);
biwa1400 0:f8af47d9f0cd 13
biwa1400 0:f8af47d9f0cd 14 bool ADC_class::init()
biwa1400 0:f8af47d9f0cd 15 {
biwa1400 0:f8af47d9f0cd 16 movBits = ADC_TOTAL_BITS-ADC_bits;
biwa1400 0:f8af47d9f0cd 17 return true;
biwa1400 0:f8af47d9f0cd 18 }
biwa1400 0:f8af47d9f0cd 19
biwa1400 0:f8af47d9f0cd 20 unsigned short ADC_class::sample()
biwa1400 0:f8af47d9f0cd 21 {
biwa1400 0:f8af47d9f0cd 22 DigitalOut SensorPower(PA_0);
biwa1400 0:f8af47d9f0cd 23 SensorPower = 0;
biwa1400 0:f8af47d9f0cd 24 adcDistance = 0;
biwa1400 0:f8af47d9f0cd 25 for (int i=0;i<ADC_sample_times;i++)
biwa1400 0:f8af47d9f0cd 26 {
biwa1400 0:f8af47d9f0cd 27 wait_ms(ADC_period);
biwa1400 0:f8af47d9f0cd 28 adcDistance += (Distance.read_u16()>>movBits);
biwa1400 0:f8af47d9f0cd 29 }
biwa1400 0:f8af47d9f0cd 30 // wait_ms(8000);
biwa1400 0:f8af47d9f0cd 31 SensorPower = 1;
biwa1400 0:f8af47d9f0cd 32
biwa1400 0:f8af47d9f0cd 33 return adcDistance>>ADC_average_move;
biwa1400 0:f8af47d9f0cd 34 }
biwa1400 0:f8af47d9f0cd 35
biwa1400 0:f8af47d9f0cd 36 bool ADC_class::sample_and_judge_result(unsigned short threshold)
biwa1400 0:f8af47d9f0cd 37 {
biwa1400 0:f8af47d9f0cd 38 if(sample()>threshold)
biwa1400 0:f8af47d9f0cd 39 return true;
biwa1400 0:f8af47d9f0cd 40 else
biwa1400 0:f8af47d9f0cd 41 return false;
biwa1400 0:f8af47d9f0cd 42 }