Transistor Gijutsu, October 2014, Special Features Chapter 8,Software of the thermistor thermometer of 0.001 ° resolution, トランジスタ技術2014年10月号 特集第8章のソフトウェア 0.001℃分解能で気配もキャッチ「超敏感肌温度計」

Dependencies:   USBDevice mbed

Information

tg_201410s8_AD7714 トランジスタ技術 2014年 10月号 第8章のソフトウェア

Program for Section 8 in October. 2014 issue of the Transistor Gijutsu
(Japanese electronics magazine)

概要

このプログラムは、サーミスタの抵抗値変化をAD7714(24bitADC)で測定し、抵抗値を温度値に変換することで、0.001℃程度の分解能で温度変化を測定します。

ファイル

このソフトウエアは、次のファイルから構成されています。

  • AD7714.cpp - AD7714の内部レジスタを設定
  • Thermistor.cpp - サーミスタの抵抗値から温度値に変換
  • ExpAvr.cpp - 指数平均によるソフトウエアLPF
  • main.cpp - main()関数

詳細については、10月号の記事および上記ファイル中のコメントを参照してください。

Committer:
Dance
Date:
Fri Aug 29 08:38:36 2014 +0000
Revision:
0:de885a6da962
Transistor Gijutsu, October 2014, Special Features Chapter 8; ????????2014?10??????8????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Dance 0:de885a6da962 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
Dance 0:de885a6da962 2 *
Dance 0:de885a6da962 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
Dance 0:de885a6da962 4 * and associated documentation files (the "Software"), to deal in the Software without
Dance 0:de885a6da962 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
Dance 0:de885a6da962 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
Dance 0:de885a6da962 7 * Software is furnished to do so, subject to the following conditions:
Dance 0:de885a6da962 8 *
Dance 0:de885a6da962 9 * The above copyright notice and this permission notice shall be included in all copies or
Dance 0:de885a6da962 10 * substantial portions of the Software.
Dance 0:de885a6da962 11 *
Dance 0:de885a6da962 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
Dance 0:de885a6da962 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Dance 0:de885a6da962 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
Dance 0:de885a6da962 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Dance 0:de885a6da962 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Dance 0:de885a6da962 17 */
Dance 0:de885a6da962 18
Dance 0:de885a6da962 19 #ifndef USBMOUSEKEYBOARD_H
Dance 0:de885a6da962 20 #define USBMOUSEKEYBOARD_H
Dance 0:de885a6da962 21
Dance 0:de885a6da962 22 #define REPORT_ID_KEYBOARD 1
Dance 0:de885a6da962 23 #define REPORT_ID_MOUSE 2
Dance 0:de885a6da962 24 #define REPORT_ID_VOLUME 3
Dance 0:de885a6da962 25
Dance 0:de885a6da962 26 #include "USBMouse.h"
Dance 0:de885a6da962 27 #include "USBKeyboard.h"
Dance 0:de885a6da962 28 #include "Stream.h"
Dance 0:de885a6da962 29 #include "USBHID.h"
Dance 0:de885a6da962 30
Dance 0:de885a6da962 31 /**
Dance 0:de885a6da962 32 * USBMouseKeyboard example
Dance 0:de885a6da962 33 * @code
Dance 0:de885a6da962 34 *
Dance 0:de885a6da962 35 * #include "mbed.h"
Dance 0:de885a6da962 36 * #include "USBMouseKeyboard.h"
Dance 0:de885a6da962 37 *
Dance 0:de885a6da962 38 * USBMouseKeyboard key_mouse;
Dance 0:de885a6da962 39 *
Dance 0:de885a6da962 40 * int main(void)
Dance 0:de885a6da962 41 * {
Dance 0:de885a6da962 42 * while(1)
Dance 0:de885a6da962 43 * {
Dance 0:de885a6da962 44 * key_mouse.move(20, 0);
Dance 0:de885a6da962 45 * key_mouse.printf("Hello From MBED\r\n");
Dance 0:de885a6da962 46 * wait(1);
Dance 0:de885a6da962 47 * }
Dance 0:de885a6da962 48 * }
Dance 0:de885a6da962 49 * @endcode
Dance 0:de885a6da962 50 *
Dance 0:de885a6da962 51 *
Dance 0:de885a6da962 52 * @code
Dance 0:de885a6da962 53 *
Dance 0:de885a6da962 54 * #include "mbed.h"
Dance 0:de885a6da962 55 * #include "USBMouseKeyboard.h"
Dance 0:de885a6da962 56 *
Dance 0:de885a6da962 57 * USBMouseKeyboard key_mouse(ABS_MOUSE);
Dance 0:de885a6da962 58 *
Dance 0:de885a6da962 59 * int main(void)
Dance 0:de885a6da962 60 * {
Dance 0:de885a6da962 61 * while(1)
Dance 0:de885a6da962 62 * {
Dance 0:de885a6da962 63 * key_mouse.move(X_MAX_ABS/2, Y_MAX_ABS/2);
Dance 0:de885a6da962 64 * key_mouse.printf("Hello from MBED\r\n");
Dance 0:de885a6da962 65 * wait(1);
Dance 0:de885a6da962 66 * }
Dance 0:de885a6da962 67 * }
Dance 0:de885a6da962 68 * @endcode
Dance 0:de885a6da962 69 */
Dance 0:de885a6da962 70 class USBMouseKeyboard: public USBHID, public Stream
Dance 0:de885a6da962 71 {
Dance 0:de885a6da962 72 public:
Dance 0:de885a6da962 73
Dance 0:de885a6da962 74 /**
Dance 0:de885a6da962 75 * Constructor
Dance 0:de885a6da962 76 *
Dance 0:de885a6da962 77 * @param mouse_type Mouse type: ABS_MOUSE (absolute mouse) or REL_MOUSE (relative mouse) (default: REL_MOUSE)
Dance 0:de885a6da962 78 * @param leds Leds bus: first: NUM_LOCK, second: CAPS_LOCK, third: SCROLL_LOCK
Dance 0:de885a6da962 79 * @param vendor_id Your vendor_id (default: 0x1234)
Dance 0:de885a6da962 80 * @param product_id Your product_id (default: 0x0001)
Dance 0:de885a6da962 81 * @param product_release Your preoduct_release (default: 0x0001)
Dance 0:de885a6da962 82 *
Dance 0:de885a6da962 83 */
Dance 0:de885a6da962 84 USBMouseKeyboard(MOUSE_TYPE mouse_type = REL_MOUSE, uint16_t vendor_id = 0x0021, uint16_t product_id = 0x0011, uint16_t product_release = 0x0001):
Dance 0:de885a6da962 85 USBHID(0, 0, vendor_id, product_id, product_release, false)
Dance 0:de885a6da962 86 {
Dance 0:de885a6da962 87 lock_status = 0;
Dance 0:de885a6da962 88 button = 0;
Dance 0:de885a6da962 89 this->mouse_type = mouse_type;
Dance 0:de885a6da962 90 connect();
Dance 0:de885a6da962 91 };
Dance 0:de885a6da962 92
Dance 0:de885a6da962 93 /**
Dance 0:de885a6da962 94 * Write a state of the mouse
Dance 0:de885a6da962 95 *
Dance 0:de885a6da962 96 * @param x x-axis position
Dance 0:de885a6da962 97 * @param y y-axis position
Dance 0:de885a6da962 98 * @param buttons buttons state (first bit represents MOUSE_LEFT, second bit MOUSE_RIGHT and third bit MOUSE_MIDDLE)
Dance 0:de885a6da962 99 * @param z wheel state (>0 to scroll down, <0 to scroll up)
Dance 0:de885a6da962 100 * @returns true if there is no error, false otherwise
Dance 0:de885a6da962 101 */
Dance 0:de885a6da962 102 bool update(int16_t x, int16_t y, uint8_t buttons, int8_t z);
Dance 0:de885a6da962 103
Dance 0:de885a6da962 104
Dance 0:de885a6da962 105 /**
Dance 0:de885a6da962 106 * Move the cursor to (x, y)
Dance 0:de885a6da962 107 *
Dance 0:de885a6da962 108 * @param x x-axis position
Dance 0:de885a6da962 109 * @param y y-axis position
Dance 0:de885a6da962 110 * @returns true if there is no error, false otherwise
Dance 0:de885a6da962 111 */
Dance 0:de885a6da962 112 bool move(int16_t x, int16_t y);
Dance 0:de885a6da962 113
Dance 0:de885a6da962 114 /**
Dance 0:de885a6da962 115 * Press one or several buttons
Dance 0:de885a6da962 116 *
Dance 0:de885a6da962 117 * @param button button state (ex: press(MOUSE_LEFT))
Dance 0:de885a6da962 118 * @returns true if there is no error, false otherwise
Dance 0:de885a6da962 119 */
Dance 0:de885a6da962 120 bool press(uint8_t button);
Dance 0:de885a6da962 121
Dance 0:de885a6da962 122 /**
Dance 0:de885a6da962 123 * Release one or several buttons
Dance 0:de885a6da962 124 *
Dance 0:de885a6da962 125 * @param button button state (ex: release(MOUSE_LEFT))
Dance 0:de885a6da962 126 * @returns true if there is no error, false otherwise
Dance 0:de885a6da962 127 */
Dance 0:de885a6da962 128 bool release(uint8_t button);
Dance 0:de885a6da962 129
Dance 0:de885a6da962 130 /**
Dance 0:de885a6da962 131 * Double click (MOUSE_LEFT)
Dance 0:de885a6da962 132 *
Dance 0:de885a6da962 133 * @returns true if there is no error, false otherwise
Dance 0:de885a6da962 134 */
Dance 0:de885a6da962 135 bool doubleClick();
Dance 0:de885a6da962 136
Dance 0:de885a6da962 137 /**
Dance 0:de885a6da962 138 * Click
Dance 0:de885a6da962 139 *
Dance 0:de885a6da962 140 * @param button state of the buttons ( ex: clic(MOUSE_LEFT))
Dance 0:de885a6da962 141 * @returns true if there is no error, false otherwise
Dance 0:de885a6da962 142 */
Dance 0:de885a6da962 143 bool click(uint8_t button);
Dance 0:de885a6da962 144
Dance 0:de885a6da962 145 /**
Dance 0:de885a6da962 146 * Scrolling
Dance 0:de885a6da962 147 *
Dance 0:de885a6da962 148 * @param z value of the wheel (>0 to go down, <0 to go up)
Dance 0:de885a6da962 149 * @returns true if there is no error, false otherwise
Dance 0:de885a6da962 150 */
Dance 0:de885a6da962 151 bool scroll(int8_t z);
Dance 0:de885a6da962 152
Dance 0:de885a6da962 153 /**
Dance 0:de885a6da962 154 * To send a character defined by a modifier(CTRL, SHIFT, ALT) and the key
Dance 0:de885a6da962 155 *
Dance 0:de885a6da962 156 * @code
Dance 0:de885a6da962 157 * //To send CTRL + s (save)
Dance 0:de885a6da962 158 * keyboard.keyCode('s', KEY_CTRL);
Dance 0:de885a6da962 159 * @endcode
Dance 0:de885a6da962 160 *
Dance 0:de885a6da962 161 * @param modifier bit 0: KEY_CTRL, bit 1: KEY_SHIFT, bit 2: KEY_ALT (default: 0)
Dance 0:de885a6da962 162 * @param key character to send
Dance 0:de885a6da962 163 * @returns true if there is no error, false otherwise
Dance 0:de885a6da962 164 */
Dance 0:de885a6da962 165 bool keyCode(uint8_t key, uint8_t modifier = 0);
Dance 0:de885a6da962 166
Dance 0:de885a6da962 167 /**
Dance 0:de885a6da962 168 * Send a character
Dance 0:de885a6da962 169 *
Dance 0:de885a6da962 170 * @param c character to be sent
Dance 0:de885a6da962 171 * @returns true if there is no error, false otherwise
Dance 0:de885a6da962 172 */
Dance 0:de885a6da962 173 virtual int _putc(int c);
Dance 0:de885a6da962 174
Dance 0:de885a6da962 175 /**
Dance 0:de885a6da962 176 * Control media keys
Dance 0:de885a6da962 177 *
Dance 0:de885a6da962 178 * @param key media key pressed (KEY_NEXT_TRACK, KEY_PREVIOUS_TRACK, KEY_STOP, KEY_PLAY_PAUSE, KEY_MUTE, KEY_VOLUME_UP, KEY_VOLUME_DOWN)
Dance 0:de885a6da962 179 * @returns true if there is no error, false otherwise
Dance 0:de885a6da962 180 */
Dance 0:de885a6da962 181 bool mediaControl(MEDIA_KEY key);
Dance 0:de885a6da962 182
Dance 0:de885a6da962 183 /**
Dance 0:de885a6da962 184 * Read status of lock keys. Useful to switch-on/off leds according to key pressed. Only the first three bits of the result is important:
Dance 0:de885a6da962 185 * - First bit: NUM_LOCK
Dance 0:de885a6da962 186 * - Second bit: CAPS_LOCK
Dance 0:de885a6da962 187 * - Third bit: SCROLL_LOCK
Dance 0:de885a6da962 188 *
Dance 0:de885a6da962 189 * @returns status of lock keys
Dance 0:de885a6da962 190 */
Dance 0:de885a6da962 191 uint8_t lockStatus();
Dance 0:de885a6da962 192
Dance 0:de885a6da962 193 /*
Dance 0:de885a6da962 194 * To define the report descriptor. Warning: this method has to store the length of the report descriptor in reportLength.
Dance 0:de885a6da962 195 *
Dance 0:de885a6da962 196 * @returns pointer to the report descriptor
Dance 0:de885a6da962 197 */
Dance 0:de885a6da962 198 virtual uint8_t * reportDesc();
Dance 0:de885a6da962 199
Dance 0:de885a6da962 200 /*
Dance 0:de885a6da962 201 * Called when a data is received on the OUT endpoint. Useful to switch on LED of LOCK keys
Dance 0:de885a6da962 202 *
Dance 0:de885a6da962 203 * @returns if handle by subclass, return true
Dance 0:de885a6da962 204 */
Dance 0:de885a6da962 205 virtual bool EP1_OUT_callback();
Dance 0:de885a6da962 206
Dance 0:de885a6da962 207
Dance 0:de885a6da962 208 private:
Dance 0:de885a6da962 209 bool mouseWrite(int8_t x, int8_t y, uint8_t buttons, int8_t z);
Dance 0:de885a6da962 210 MOUSE_TYPE mouse_type;
Dance 0:de885a6da962 211 uint8_t button;
Dance 0:de885a6da962 212 bool mouseSend(int8_t x, int8_t y, uint8_t buttons, int8_t z);
Dance 0:de885a6da962 213
Dance 0:de885a6da962 214 uint8_t lock_status;
Dance 0:de885a6da962 215
Dance 0:de885a6da962 216 //dummy otherwise it doesn't compile (we must define all methods of an abstract class)
Dance 0:de885a6da962 217 virtual int _getc() { return -1;}
Dance 0:de885a6da962 218 };
Dance 0:de885a6da962 219
Dance 0:de885a6da962 220 #endif