![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Description dans le rapport.
LED_Bar.cpp@0:34945468db9f, 2017-04-02 (annotated)
- Committer:
- Damien75
- Date:
- Sun Apr 02 09:48:30 2017 +0000
- Revision:
- 0:34945468db9f
Projet C++ embarqu? MBED; Damien et Nicolas
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Damien75 | 0:34945468db9f | 1 | /* |
Damien75 | 0:34945468db9f | 2 | LED bar library V1.0 |
Damien75 | 0:34945468db9f | 3 | 2010 Copyright (c) Seeed Technology Inc. All right reserved. |
Damien75 | 0:34945468db9f | 4 | |
Damien75 | 0:34945468db9f | 5 | Original Author: LG |
Damien75 | 0:34945468db9f | 6 | |
Damien75 | 0:34945468db9f | 7 | Modify: Mihail Stoyanov (mihail.stoyanov@arm.com) for ARM mbed, 2014-07-30 |
Damien75 | 0:34945468db9f | 8 | User can choose which Io to be used. |
Damien75 | 0:34945468db9f | 9 | This library is free software; you can redistribute it and/or |
Damien75 | 0:34945468db9f | 10 | modify it under the terms of the GNU Lesser General Public |
Damien75 | 0:34945468db9f | 11 | License as published by the Free Software Foundation; either |
Damien75 | 0:34945468db9f | 12 | version 2.1 of the License, or (at your option) any later version. |
Damien75 | 0:34945468db9f | 13 | |
Damien75 | 0:34945468db9f | 14 | This library is distributed in the hope that it will be useful, |
Damien75 | 0:34945468db9f | 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
Damien75 | 0:34945468db9f | 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
Damien75 | 0:34945468db9f | 17 | Lesser General Public License for more details. |
Damien75 | 0:34945468db9f | 18 | |
Damien75 | 0:34945468db9f | 19 | You should have received a copy of the GNU Lesser General Public |
Damien75 | 0:34945468db9f | 20 | License along with this library; if not, write to the Free Software |
Damien75 | 0:34945468db9f | 21 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Damien75 | 0:34945468db9f | 22 | */ |
Damien75 | 0:34945468db9f | 23 | |
Damien75 | 0:34945468db9f | 24 | #include "LED_Bar.h" |
Damien75 | 0:34945468db9f | 25 | |
Damien75 | 0:34945468db9f | 26 | LED_Bar::LED_Bar(PinName pinClk, PinName pinDta) : __pinClk(pinClk), __pinDta(pinDta) |
Damien75 | 0:34945468db9f | 27 | { |
Damien75 | 0:34945468db9f | 28 | __led_state = 0x00; |
Damien75 | 0:34945468db9f | 29 | } |
Damien75 | 0:34945468db9f | 30 | |
Damien75 | 0:34945468db9f | 31 | void LED_Bar::latchData() |
Damien75 | 0:34945468db9f | 32 | { |
Damien75 | 0:34945468db9f | 33 | __pinDta = 0; |
Damien75 | 0:34945468db9f | 34 | wait_us(10); |
Damien75 | 0:34945468db9f | 35 | |
Damien75 | 0:34945468db9f | 36 | for(int i=0; i<4; i++) { |
Damien75 | 0:34945468db9f | 37 | __pinDta = 1; |
Damien75 | 0:34945468db9f | 38 | __pinDta = 0; |
Damien75 | 0:34945468db9f | 39 | } |
Damien75 | 0:34945468db9f | 40 | |
Damien75 | 0:34945468db9f | 41 | } |
Damien75 | 0:34945468db9f | 42 | |
Damien75 | 0:34945468db9f | 43 | void LED_Bar::send16bitData(unsigned int data) |
Damien75 | 0:34945468db9f | 44 | { |
Damien75 | 0:34945468db9f | 45 | for(int i=0; i<16; i++) { |
Damien75 | 0:34945468db9f | 46 | unsigned int state = data & 0x8000 ? 1 : 0; |
Damien75 | 0:34945468db9f | 47 | __pinDta = state; |
Damien75 | 0:34945468db9f | 48 | |
Damien75 | 0:34945468db9f | 49 | state = __pinClk ? 0 : 1; |
Damien75 | 0:34945468db9f | 50 | __pinClk = state; |
Damien75 | 0:34945468db9f | 51 | |
Damien75 | 0:34945468db9f | 52 | data <<= 1; |
Damien75 | 0:34945468db9f | 53 | } |
Damien75 | 0:34945468db9f | 54 | } |
Damien75 | 0:34945468db9f | 55 | |
Damien75 | 0:34945468db9f | 56 | void LED_Bar::ledIndexBit(unsigned int index_bits) |
Damien75 | 0:34945468db9f | 57 | { |
Damien75 | 0:34945468db9f | 58 | |
Damien75 | 0:34945468db9f | 59 | send16bitData(CMDMODE); |
Damien75 | 0:34945468db9f | 60 | |
Damien75 | 0:34945468db9f | 61 | for (int i=0; i<12; i++) { |
Damien75 | 0:34945468db9f | 62 | unsigned int state = (index_bits&0x0001) ? ON : SHUT; |
Damien75 | 0:34945468db9f | 63 | send16bitData(state); |
Damien75 | 0:34945468db9f | 64 | |
Damien75 | 0:34945468db9f | 65 | index_bits = index_bits>>1; |
Damien75 | 0:34945468db9f | 66 | } |
Damien75 | 0:34945468db9f | 67 | |
Damien75 | 0:34945468db9f | 68 | latchData(); |
Damien75 | 0:34945468db9f | 69 | } |
Damien75 | 0:34945468db9f | 70 | |
Damien75 | 0:34945468db9f | 71 | void LED_Bar::setLevel(int level) |
Damien75 | 0:34945468db9f | 72 | { |
Damien75 | 0:34945468db9f | 73 | |
Damien75 | 0:34945468db9f | 74 | if(level>10)return; |
Damien75 | 0:34945468db9f | 75 | |
Damien75 | 0:34945468db9f | 76 | send16bitData(CMDMODE); |
Damien75 | 0:34945468db9f | 77 | |
Damien75 | 0:34945468db9f | 78 | for(int i=0; i<12; i++) { |
Damien75 | 0:34945468db9f | 79 | unsigned int state1 = (i<level) ? ON : SHUT; |
Damien75 | 0:34945468db9f | 80 | |
Damien75 | 0:34945468db9f | 81 | send16bitData(state1); |
Damien75 | 0:34945468db9f | 82 | } |
Damien75 | 0:34945468db9f | 83 | |
Damien75 | 0:34945468db9f | 84 | latchData(); |
Damien75 | 0:34945468db9f | 85 | } |
Damien75 | 0:34945468db9f | 86 | |
Damien75 | 0:34945468db9f | 87 | void LED_Bar::setSingleLed(int num, int st) |
Damien75 | 0:34945468db9f | 88 | { |
Damien75 | 0:34945468db9f | 89 | if(num>10)return; |
Damien75 | 0:34945468db9f | 90 | __led_state = st ? (__led_state | (0x01<<num)) : (__led_state & ~(0x01<<num)); |
Damien75 | 0:34945468db9f | 91 | ledIndexBit(__led_state); |
Damien75 | 0:34945468db9f | 92 | |
Damien75 | 0:34945468db9f | 93 | } |