PAW_Sensor: This library control the PAW sensor. This library get sensor values from the PAW sensor, and send these values to PC through serial-communication. And you need to convert these values to delta h using some module on PC. I create sample python module for this library. If you want to get this module, please access below page, https://github.com/HiroakiMatsuda/PAW-Sensor The PAW Sensor is developed by RT. If you need to get information about this sensors, please access below page. http://www.rt-shop.jp/index.php?main_page=product_info&cPath=42&products_id=1303

Dependents:   PAW_Sensor_HelloWorld

Committer:
matsu
Date:
Sun Nov 09 08:13:22 2014 +0000
Revision:
0:ebd7c54059ae
Child:
1:6ec3794072de
Fist upload.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
matsu 0:ebd7c54059ae 1 /* mbed PAW_Sensor Library
matsu 0:ebd7c54059ae 2 *
matsu 0:ebd7c54059ae 3 * paw.cpp
matsu 0:ebd7c54059ae 4 *
matsu 0:ebd7c54059ae 5 * Copyright (c) 2014 Hiroaki Matsuda
matsu 0:ebd7c54059ae 6 *
matsu 0:ebd7c54059ae 7 * Permission is hereby granted, free of charge, to any person obtaining a copy
matsu 0:ebd7c54059ae 8 * of this software and associated documentation files (the "Software"), to deal
matsu 0:ebd7c54059ae 9 * in the Software without restriction, including without limitation the rights
matsu 0:ebd7c54059ae 10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
matsu 0:ebd7c54059ae 11 * copies of the Software, and to permit persons to whom the Software is
matsu 0:ebd7c54059ae 12 * furnished to do so, subject to the following conditions:
matsu 0:ebd7c54059ae 13 *
matsu 0:ebd7c54059ae 14 * The above copyright notice and this permission notice shall be included in
matsu 0:ebd7c54059ae 15 * all copies or substantial portions of the Software.
matsu 0:ebd7c54059ae 16 *
matsu 0:ebd7c54059ae 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
matsu 0:ebd7c54059ae 18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
matsu 0:ebd7c54059ae 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
matsu 0:ebd7c54059ae 20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
matsu 0:ebd7c54059ae 21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
matsu 0:ebd7c54059ae 22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
matsu 0:ebd7c54059ae 23 * THE SOFTWARE.
matsu 0:ebd7c54059ae 24 */
matsu 0:ebd7c54059ae 25
matsu 0:ebd7c54059ae 26 #include "paw.h"
matsu 0:ebd7c54059ae 27
matsu 0:ebd7c54059ae 28 PAW::PAW( PinName led_1, PinName led_2, PinName photo_1, PinName photo_2 ):
matsu 0:ebd7c54059ae 29 _led_1( led_1 ), _led_2( led_2 ), _photo_1( photo_1 ), _photo_2( photo_2 ){
matsu 0:ebd7c54059ae 30
matsu 0:ebd7c54059ae 31 _led_1 = 0;
matsu 0:ebd7c54059ae 32 _led_2 = 0;
matsu 0:ebd7c54059ae 33 _state = STATE_1;
matsu 0:ebd7c54059ae 34 }
matsu 0:ebd7c54059ae 35
matsu 0:ebd7c54059ae 36 unsigned char PAW::process_paw()
matsu 0:ebd7c54059ae 37 {
matsu 0:ebd7c54059ae 38 switch( _state )
matsu 0:ebd7c54059ae 39 {
matsu 0:ebd7c54059ae 40 case STATE_1:
matsu 0:ebd7c54059ae 41 _value.initial_photo_1 = _photo_1.read_u16();
matsu 0:ebd7c54059ae 42 _value.initial_photo_2 = _photo_2.read_u16();
matsu 0:ebd7c54059ae 43 _led_1 = 1;
matsu 0:ebd7c54059ae 44
matsu 0:ebd7c54059ae 45 _state = STATE_2;
matsu 0:ebd7c54059ae 46 break;
matsu 0:ebd7c54059ae 47
matsu 0:ebd7c54059ae 48 case STATE_2:
matsu 0:ebd7c54059ae 49 _value.ch_3 = ( _photo_1.read_u16() - _value.initial_photo_1 ) >> 4;
matsu 0:ebd7c54059ae 50 _value.ch_4 = ( _photo_2.read_u16() - _value.initial_photo_2 ) >> 4;
matsu 0:ebd7c54059ae 51 _led_1 = 0;
matsu 0:ebd7c54059ae 52
matsu 0:ebd7c54059ae 53 _state = STATE_3;
matsu 0:ebd7c54059ae 54 break;
matsu 0:ebd7c54059ae 55
matsu 0:ebd7c54059ae 56 case STATE_3:
matsu 0:ebd7c54059ae 57 _value.initial_photo_1 = _photo_1.read_u16();
matsu 0:ebd7c54059ae 58 _value.initial_photo_2 = _photo_2.read_u16();
matsu 0:ebd7c54059ae 59 _led_2 = 1;
matsu 0:ebd7c54059ae 60
matsu 0:ebd7c54059ae 61 _state = STATE_4;
matsu 0:ebd7c54059ae 62 break;
matsu 0:ebd7c54059ae 63
matsu 0:ebd7c54059ae 64 case STATE_4:
matsu 0:ebd7c54059ae 65 _value.ch_2 = ( _photo_1.read_u16() - _value.initial_photo_2 ) >> 4;
matsu 0:ebd7c54059ae 66 _value.ch_1 = ( _photo_2.read_u16() - _value.initial_photo_1 ) >> 4;
matsu 0:ebd7c54059ae 67 _led_2 = 0;
matsu 0:ebd7c54059ae 68
matsu 0:ebd7c54059ae 69 _state = STATE_1;
matsu 0:ebd7c54059ae 70 break;
matsu 0:ebd7c54059ae 71 }
matsu 0:ebd7c54059ae 72
matsu 0:ebd7c54059ae 73 return _state;
matsu 0:ebd7c54059ae 74 }
matsu 0:ebd7c54059ae 75
matsu 0:ebd7c54059ae 76 paw_value PAW::get_value()
matsu 0:ebd7c54059ae 77 {
matsu 0:ebd7c54059ae 78 return _value;
matsu 0:ebd7c54059ae 79 }
matsu 0:ebd7c54059ae 80
matsu 0:ebd7c54059ae 81 bool PAW::get_state()
matsu 0:ebd7c54059ae 82 {
matsu 0:ebd7c54059ae 83 return _state;
matsu 0:ebd7c54059ae 84 }
matsu 0:ebd7c54059ae 85
matsu 0:ebd7c54059ae 86 void PAW::print( Serial* pc )
matsu 0:ebd7c54059ae 87 {
matsu 0:ebd7c54059ae 88 pc->printf("%c%c%c%c%c%c%c%c%c%c", 0xFA, 0xAF,
matsu 0:ebd7c54059ae 89 _value.ch_1 & 0x00FF, ( _value.ch_1 & 0xFF00 ) >> 8,
matsu 0:ebd7c54059ae 90 _value.ch_2 & 0x00FF, ( _value.ch_2 & 0xFF00 ) >> 8,
matsu 0:ebd7c54059ae 91 _value.ch_3 & 0x00FF, ( _value.ch_3 & 0xFF00 ) >> 8,
matsu 0:ebd7c54059ae 92 _value.ch_4 & 0x00FF, ( _value.ch_4 & 0xFF00 ) >> 8);
matsu 0:ebd7c54059ae 93 }
matsu 0:ebd7c54059ae 94