desu
Dependencies: RemoteIR TextLCD
main.cpp@0:0d0037aabe41, 2020-07-14 (annotated)
- Committer:
- yangtzuli
- Date:
- Tue Jul 14 01:20:09 2020 +0000
- Revision:
- 0:0d0037aabe41
- Child:
- 1:5bb497a38344
mode-rimokon
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yangtzuli | 0:0d0037aabe41 | 1 | /* mbed Microcontroller Library |
yangtzuli | 0:0d0037aabe41 | 2 | * Copyright (c) 2019 ARM Limited |
yangtzuli | 0:0d0037aabe41 | 3 | * SPDX-License-Identifier: Apache-2.0 |
yangtzuli | 0:0d0037aabe41 | 4 | */ |
yangtzuli | 0:0d0037aabe41 | 5 | |
yangtzuli | 0:0d0037aabe41 | 6 | #include "mbed.h" |
yangtzuli | 0:0d0037aabe41 | 7 | #include "ReceiverIR.h" |
yangtzuli | 0:0d0037aabe41 | 8 | #include "rtos.h" |
yangtzuli | 0:0d0037aabe41 | 9 | #include <stdint.h> |
yangtzuli | 0:0d0037aabe41 | 10 | #include "platform/mbed_thread.h" |
yangtzuli | 0:0d0037aabe41 | 11 | |
yangtzuli | 0:0d0037aabe41 | 12 | Serial pc(USBTX, USBRX); |
yangtzuli | 0:0d0037aabe41 | 13 | |
yangtzuli | 0:0d0037aabe41 | 14 | |
yangtzuli | 0:0d0037aabe41 | 15 | DigitalIn button(p15); |
yangtzuli | 0:0d0037aabe41 | 16 | // ポートp15を赤外線受信モジュールの接続先に指定 |
yangtzuli | 0:0d0037aabe41 | 17 | ReceiverIR ir_rx(p15); |
yangtzuli | 0:0d0037aabe41 | 18 | RemoteIR::Format format; |
yangtzuli | 0:0d0037aabe41 | 19 | uint8_t buf[32]; |
yangtzuli | 0:0d0037aabe41 | 20 | uint32_t bitcount; |
yangtzuli | 0:0d0037aabe41 | 21 | uint8_t code; |
yangtzuli | 0:0d0037aabe41 | 22 | char mode[20]; |
yangtzuli | 0:0d0037aabe41 | 23 | |
yangtzuli | 0:0d0037aabe41 | 24 | void rimokon(); |
yangtzuli | 0:0d0037aabe41 | 25 | |
yangtzuli | 0:0d0037aabe41 | 26 | void rimokon(/*void const *argument*/){ |
yangtzuli | 0:0d0037aabe41 | 27 | |
yangtzuli | 0:0d0037aabe41 | 28 | |
yangtzuli | 0:0d0037aabe41 | 29 | // 受信待ち |
yangtzuli | 0:0d0037aabe41 | 30 | if (ir_rx.getState() == ReceiverIR::Received) { |
yangtzuli | 0:0d0037aabe41 | 31 | // コード受信 |
yangtzuli | 0:0d0037aabe41 | 32 | bitcount = ir_rx.getData(&format, buf, sizeof(buf) * 8); |
yangtzuli | 0:0d0037aabe41 | 33 | if(bitcount > 1){ |
yangtzuli | 0:0d0037aabe41 | 34 | // 受信成功 |
yangtzuli | 0:0d0037aabe41 | 35 | code = buf[2]; |
yangtzuli | 0:0d0037aabe41 | 36 | pc.printf("%x\r\n",code); |
yangtzuli | 0:0d0037aabe41 | 37 | switch(code){ |
yangtzuli | 0:0d0037aabe41 | 38 | case 0x40://ok |
yangtzuli | 0:0d0037aabe41 | 39 | strcpy(mode,"Default"); |
yangtzuli | 0:0d0037aabe41 | 40 | pc.printf("%s\r\n",mode); |
yangtzuli | 0:0d0037aabe41 | 41 | break; |
yangtzuli | 0:0d0037aabe41 | 42 | case 0x42://* |
yangtzuli | 0:0d0037aabe41 | 43 | strcpy(mode,"Avoidance"); |
yangtzuli | 0:0d0037aabe41 | 44 | pc.printf("%s\r\n",mode); |
yangtzuli | 0:0d0037aabe41 | 45 | break; |
yangtzuli | 0:0d0037aabe41 | 46 | case 0x4a://# |
yangtzuli | 0:0d0037aabe41 | 47 | strcpy(mode,"Line_Trace"); |
yangtzuli | 0:0d0037aabe41 | 48 | pc.printf("%s\r\n",mode); |
yangtzuli | 0:0d0037aabe41 | 49 | break; |
yangtzuli | 0:0d0037aabe41 | 50 | default: |
yangtzuli | 0:0d0037aabe41 | 51 | ; |
yangtzuli | 0:0d0037aabe41 | 52 | } |
yangtzuli | 0:0d0037aabe41 | 53 | } |
yangtzuli | 0:0d0037aabe41 | 54 | } |
yangtzuli | 0:0d0037aabe41 | 55 | |
yangtzuli | 0:0d0037aabe41 | 56 | } |
yangtzuli | 0:0d0037aabe41 | 57 | |
yangtzuli | 0:0d0037aabe41 | 58 | int main() { |
yangtzuli | 0:0d0037aabe41 | 59 | |
yangtzuli | 0:0d0037aabe41 | 60 | //RtosTimer rimokon_timer(rimokon, osTimerPeriodic, (void *)0); // set RTOS timer for sensor |
yangtzuli | 0:0d0037aabe41 | 61 | //rimokon_timer.start(10); |
yangtzuli | 0:0d0037aabe41 | 62 | //Thread thread1(rimokon , NULL , osPriorityHigh); |
yangtzuli | 0:0d0037aabe41 | 63 | while(1){ |
yangtzuli | 0:0d0037aabe41 | 64 | if(button.read()==0){ |
yangtzuli | 0:0d0037aabe41 | 65 | rimokon(); |
yangtzuli | 0:0d0037aabe41 | 66 | } |
yangtzuli | 0:0d0037aabe41 | 67 | } |
yangtzuli | 0:0d0037aabe41 | 68 | } |