123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479 |
- /**
- ******************************************************************************
- * @file dio.c
- * @author hskim
- * @version v0.7
- * @date 2019-06-07
- * @brief This file provides Digital Input and Output's fuction.
- ******************************************************************************
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <stdarg.h>
- #include "pca10040.h"
- #include "dio.h"
- #include "nrf_log.h"
- #include "nrf_log_ctrl.h"
- #include "nrf_log_default_backends.h"
- #include "sysmgr.h"
- #include "main.h"
- uint8_t BT5ButtonList[2] = BUTTONS_LIST;
- stHSDOut HSDOut[3];
- stHSDIOTask HSDIOTask;
- uint32_t TimeSlice[10];
- static int TS = 0;
- stHSDIn DIn[2];
- void DioTask()
- {
- DITask();
- }
- int DITask()
- {
- int i;
- uint16_t readDI;
- if( HSDIOTask.DIRunFlag < HSDIOTask.DIRunPeriodTime )
- return 0;
- HSDIOTask.DIRunFlag = 0;
- for( i=0; i<1; i++)
- {
- //DInput[i].in = (uint8_t)HAL_GPIO_ReadPin(DIPinMap[i].Port, DIPinMap[i].Pin);
- //if( DIPinMap[i].HighActive == LowActive )
- // DInput[i].in = ~DInput[i].in&0x01;
- }
- return 0;
- }
- int DOTask()
- {
- #if 0
- int i;
- int DoIndex;
- if( !HSDIOTask.RunFlag )
- return 0;
- HSDIOTask.RunFlag = 0;
- HSDOutProcess(DOut, DOPinMap, 21 );
- #endif
- return 0;
- }
- void HSDInInit()
- {
- uint32_t i;
- for (i = 0; i < BUTTONS_NUMBER; ++i)
- {
- nrf_gpio_cfg_input(BT5ButtonList[i], BUTTON_PULL);
- }
- HSDIOTask.DIRunPeriodTime = 25;
- HSDIOTask.DISecCount =1000/HSDIOTask.DIRunPeriodTime;
- DIn[0].Pressed = Key_0_Pressed;
- DIn[0].Released = Key_0_Released;
- DIn[1].Pressed = Key_1_Pressed;
- DIn[1].Released = Key_1_Released;
- DIn[0].longPressTimeOne = 5; //jakuja
- DIn[0].LongPressedOne = DevRegLongPressedOne;
- #if 0
- DIn[2].Pressed = Key_2_Pressed;
- DIn[2].Released = Key_2_Released;
- DIn[3].Pressed = Key_3_Pressed;
- DIn[3].Released = Key_3_Released;
- DIn[4].Pressed = Key_4_Pressed;
- DIn[4].Released = Key_4_Released;
- #endif
- }
- void HSDInRun()
- {
-
- int Len;
- int DiIndex;
- for( DiIndex=0; DiIndex<BUTTONS_NUMBER; DiIndex++)
- {
- if( nrf_gpio_pin_read(BT5ButtonList[DiIndex]) == false) // BUTTON PUSH
- {
- DIn[DiIndex].in = 1;
-
- if( DIn[DiIndex].softRelease == 1 )
- {
- return;
- }
- if( DIn[DiIndex].onFlag == 0 )
- {
- DIn[DiIndex].pressCount++;
- DIn[DiIndex].Pressed(&DIn[DiIndex]);
-
- NRF_LOG_INFO("==> Key_%d Pressed", BT5ButtonList[DiIndex]);
-
- }else{
- if( DIn[DiIndex].longPressTimeKeep != 0 )
- {
- if( DIn[DiIndex].pressedSec >= DIn[DiIndex].longPressTimeKeep )
- {
- DIn[DiIndex].LongPressedKeep(&DIn[DiIndex]);
- }
- }
- if( DIn[1].pressTime == 20 ) //pressTime 25ms Tick
- {
- if( DIn[0].onFlag == 0 )
- Trigger_Emg();
- else{
- Trigger_DUF();
- }
- }
- if( DIn[DiIndex].pressTime % HSDIOTask.DISecCount == 0 ) // count up 0.5 sec
- {
- DIn[DiIndex].pressedSec++;
- if( DIn[0].onFlag == 1 && DIn[1].pressedSec == 2 )
- {
- //SystemTimer.SEND_TIMER = 0;
- //SystemManager.FWUpdate = 1;
- //Buzzer_Select(4);
- }
- if( DIn[0].pressedSec >= 1 && DIn[0].pressedSec <= 5 ) //pressTime 25ms Tick
- {
- SystemTimer.SEND_TIMER = 0;
- }
- if( DIn[0].pressedSec == 5 )
- {
- Trigger_RegDev();
- }
- if( DIn[DiIndex].longPressTimeOne != 0 )
- {
- if( DIn[DiIndex].pressedSec >= DIn[DiIndex].longPressTimeOne )
- {
- DIn[DiIndex].longPressCount++;
- DIn[DiIndex].softRelease = 1;
- DIn[DiIndex].LongPressedOne(&DIn[DiIndex]);
-
- NRF_LOG_INFO("==> Key_%d LongPressedOne", BT5ButtonList[DiIndex]);
- }
- }
- }
- }
-
- DIn[DiIndex].onFlag = 1;
- DIn[DiIndex].pressTime++;
- }else{
- if( DIn[DiIndex].onFlag == 1 )
- {
- if( DiIndex == 0 ) // TEST BUTTON
- {
- //if( DIn[0].pressedSec >= 1 && DIn[0].pressedSec <5 )
- if( DIn[0].pressTime >= 2 && DIn[0].pressTime < 100 ){
- if( SystemManager.FWUpdate == 0 )
- Trigger_LineTest();
- }else{
- NRF_LOG_INFO("$$$ Key_%d Released", BT5ButtonList[DiIndex]);
- DIn[DiIndex].in = 0;
- DIn[DiIndex].pressTime = 0;
- DIn[DiIndex].onFlag = 0;
- DIn[DiIndex].pressedSec = 0;
- DIn[DiIndex].softRelease = 0;
- DIn[DiIndex].prevTime = 0;
-
-
- }
- }
- if( DiIndex == 1 ) // EMG BUTTON
- {
- //if( DIn[0].pressedSec >= 1 && DIn[0].pressedSec <5 )
- if( DIn[1].pressTime < 25 ){
- NRF_LOG_INFO("$$$ Key_%d Released", BT5ButtonList[DiIndex]);
- DIn[DiIndex].in = 0;
- DIn[DiIndex].pressTime = 0;
- DIn[DiIndex].onFlag = 0;
- DIn[DiIndex].pressedSec = 0;
- DIn[DiIndex].softRelease = 0;
- DIn[DiIndex].prevTime = 0;
-
-
- }
- }
- DIn[DiIndex].Released(&DIn[DiIndex]);
- NRF_LOG_INFO("==> Key_%d Released", BT5ButtonList[DiIndex]);
- }
-
- DIn[DiIndex].in = 0;
- DIn[DiIndex].pressTime = 0;
- DIn[DiIndex].onFlag = 0;
- DIn[DiIndex].pressedSec = 0;
- DIn[DiIndex].softRelease = 0;
- DIn[DiIndex].prevTime = 0;
- }
- }
- }
- void Trigger_Emg()
- {
- NRF_LOG_INFO("# EMG Pressed");
- SystemManager.EmgSendButton = BUTTON_EMG;
- SystemTimer.EMG_SEND_RUN = 1;
- SystemTimer.SEND_TIMER = 0;
- if(!advertising_flag)
- advertising_start();
-
- Buzzer_Select(BUZZER_EMG);
- }
- void Trigger_LineTest()
- {
- NRF_LOG_INFO("# Test Pressed");
- SystemManager.EmgSendButton = BUTTON_TEST;
- SystemTimer.EMG_SEND_RUN = 1;
- SystemTimer.SEND_TIMER = 0;
- if(!advertising_flag)
- advertising_start();
- Buzzer_Select(BUZZER_TEST);
- }
- void Trigger_RegDev()
- {
- NRF_LOG_INFO("# DevReg Pressed");
- SystemManager.EmgSendButton = BUTTON_REG;
- SystemTimer.EMG_SEND_RUN = 1;
- SystemTimer.SEND_TIMER = 0;
- if(!advertising_flag)
- advertising_start();
- Buzzer_Select(BUZZER_REG);
- }
- void Trigger_DUF()
- {
- NRF_LOG_INFO("# DevReg Pressed");
- SystemTimer.SEND_TIMER = 0;
- SystemManager.FWUpdate = 1;
- Buzzer_Select(BUZZER_BOOT_LOADER);
- }
- char Key1Flag = 0;
- void Key_0_Pressed(stHSDIn* pDin)
- {
- Key1Flag = 0;
-
- }
- void Key_0_Released(stHSDIn* pDin)
- {
- if( DIn[0].pressedSec < 1 )//jakuja
- return;
-
-
- if( Key1Flag == 1 )
- return;
- #if 0
- SystemManager.EmgSendButton = BUTTON_TEST;
- NRF_LOG_INFO("@@@@@@@ Test Pressed");
- SystemTimer.SEND_RUN = 1;
- SystemTimer.SEND_TIMER = 0;
- #endif
- }
- void DevRegLongPressedOne(stHSDIn* pDin)
- {
- Key1Flag = 1;
- #if 0
- SystemManager.EmgSendButton = BUTTON_REG;
-
- NRF_LOG_INFO("@@@@@@@ DevReg Pressed");
-
- SystemTimer.SEND_RUN = 1;
- SystemTimer.SEND_TIMER = 0;
- #endif
- }
- void Key_1_Pressed(stHSDIn* pDin)
- {
- if( DIn[0].onFlag == 1 )
- {
- SystemManager.FWUpdate = 1;
- Buzzer_Select(BUZZER_BOOT_LOADER);
- }
-
- }
- void Key_1_Released(stHSDIn* pDin)
- {
- if( DIn[1].pressedSec < 1 )//jakuja
- return;
-
- #if 0
- NRF_LOG_INFO("@@@@@@@ EMG Pressed");
- SystemManager.EmgSendButton = BUTTON_EMG;
- SystemTimer.SEND_RUN = 1;
- SystemTimer.SEND_TIMER = 0;
- #endif
- }
- #if 0
- void Key_2_Pressed(stHSDIn* pDin)
- {
- uint8_t sendKey[2];
- sendKey[0] = 0x51;
- keys_send(1, &sendKey[0]);
-
- }
- void Key_2_Released(stHSDIn* pDin)
- {
- //NRF_LOG_INFO("Key_2_Released");
- }
- void Key_3_Pressed(stHSDIn* pDin)
- {
- //NRF_LOG_INFO("Key_3_Pressed");
- }
- void Key_3_Released(stHSDIn* pDin)
- {
- //NRF_LOG_INFO("Key_3_Released");
- }
- void Key_4_Pressed(stHSDIn* pDin)
- {
- //NRF_LOG_INFO("Key_4_Pressed");
- }//
- void Key_4_Released(stHSDIn* pDin)
- {
- //NRF_LOG_INFO("Key_4_Released");
- }
- #endif
|