From 5d5e402bec95e09cd990cb58760140cced6ae20f Mon Sep 17 00:00:00 2001 From: "odri@aconno.de" Date: Wed, 13 Mar 2019 15:39:47 +0100 Subject: [PATCH] Infrared task --- aconnoHelpers/menuStates.cpp | 26 +++++++++++++++++++++++++- aconnoHelpers/menuStates.h | 10 ++++++++++ source/main.cpp | 4 +++- tasks/aconnoTasks.cpp | 30 ++++++++++++++++++++++++++++++ tasks/aconnoTasks.h | 7 +++++++ 5 files changed, 75 insertions(+), 2 deletions(-) diff --git a/aconnoHelpers/menuStates.cpp b/aconnoHelpers/menuStates.cpp index 2172803..55e81b7 100644 --- a/aconnoHelpers/menuStates.cpp +++ b/aconnoHelpers/menuStates.cpp @@ -18,8 +18,11 @@ extern TaskHandle_t potTask; extern TaskHandle_t tempTask; extern TaskHandle_t gyroTask; extern TaskHandle_t bleTask; +extern TaskHandle_t irTask; +extern AconnoGPIO irLed; extern GDEP015OC1 epd; + State::~State(){} @@ -369,7 +372,7 @@ State *InfraredMenuState::handleEvent(IOEXP_INT_SOURCE intSource) return new GyroMenuState(); case IOEXP_INT_SOURCE::JOY_CENTER: - return new UnimplementedState(); + return new InfraredExampleState(); default: return new InfraredMenuState(); @@ -382,6 +385,27 @@ void InfraredMenuState::displayOnEpd() epd.write(); } +State *InfraredExampleState::handleEvent(IOEXP_INT_SOURCE intSource) +{ + if(intSource == IOEXP_INT_SOURCE::JOY_CENTER) + { + vTaskDelete(irTask); + irLed.write(GPIO_STATE::LOW); + return new InfraredMenuState(); + } + else + { + return new InfraredExampleState(); + } +} + +void InfraredExampleState::displayOnEpd() +{ + epd.drawImage(ir1); + epd.write(); + xTaskCreate(infraredFunction, "INFRARED", 256, NULL, 1, &irTask); +} + State *GyroMenuState::handleEvent(IOEXP_INT_SOURCE intSource) { diff --git a/aconnoHelpers/menuStates.h b/aconnoHelpers/menuStates.h index 6d0fe73..7bef12d 100644 --- a/aconnoHelpers/menuStates.h +++ b/aconnoHelpers/menuStates.h @@ -197,6 +197,16 @@ class InfraredMenuState : public State }; +class InfraredExampleState : public State +{ + public: + + + State *handleEvent(IOEXP_INT_SOURCE intSource); + void displayOnEpd(); + +}; + class GyroMenuState : public State { public: diff --git a/source/main.cpp b/source/main.cpp index 8275eff..de766ba 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -52,6 +52,7 @@ TaskHandle_t potTask; TaskHandle_t tempTask; TaskHandle_t gyroTask; TaskHandle_t bleTask; +TaskHandle_t irTask; AconnoI2C i2c (PIN_EXP_SDA, PIN_EXP_SCL); AconnoSPI spi(PIN_EPD_MISO, PIN_EPD_MOSI, PIN_EPD_SCK); @@ -60,6 +61,7 @@ AconnoSAADC adc; AconnoGPIO ledRed(PIN_LED_RED,GPIO_DIR::GPIO_OUTPUT); AconnoGPIO ledBlue(PIN_LED_BLUE,GPIO_DIR::GPIO_OUTPUT); AconnoGPIO ledGreen(PIN_LED_GREEN,GPIO_DIR::GPIO_OUTPUT); +AconnoGPIO irLed(PIN_IRLED,GPIO_DIR::GPIO_OUTPUT); AconnoGPIO sw1 (PIN_BUTTON, GPIO_DIR::GPIO_INPUT); GDEP015OC1 epd(spi, PIN_EPD_CS, PIN_EPD_DC, PIN_EPD_RST, PIN_EPD_BUSY); @@ -96,7 +98,7 @@ int main(void) xTaskCreate(potentiometerFunction, "POT", 256, NULL, 1, &potTask); xTaskCreate(temperatureFunction, "TEMP", 256, NULL, 1, &tempTask); xTaskCreate(gyroFunction, "GYRO", 256, NULL, 1, &gyroTask); - xTaskCreate(bleBeaconFunction, "GYRO", 256, NULL, 1, &bleTask); + xTaskCreate(bleBeaconFunction, "BEACON", 256, NULL, 1, &bleTask); // Activate deep sleep mode. SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; diff --git a/tasks/aconnoTasks.cpp b/tasks/aconnoTasks.cpp index 7862032..0f5ae23 100644 --- a/tasks/aconnoTasks.cpp +++ b/tasks/aconnoTasks.cpp @@ -23,6 +23,7 @@ extern AconnoSAADC adc; extern AconnoGPIO ledRed; extern AconnoGPIO ledBlue; extern AconnoGPIO ledGreen; +extern AconnoGPIO irLed; extern AconnoGPIO sw1; extern GDEP015OC1 epd; @@ -493,3 +494,32 @@ void bleBeaconFunction(void *arg) } } + +void infraredFunction(void *arg) +{ + //vTaskSuspend(NULL); + + uint8_t SOS[] = { + 0, 1, 0, 1, 0, 1, //S + 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, //O + 0, 1, 0, 1, 0, 1, //S + 0, 0, 0, 0, 0, 0, 0, 0, 0 //Short pause + }; + uint8_t sosSize = sizeof(SOS); + uint8_t irIndex = 0; + + while(1) + { + if(SOS[irIndex]==0) + { + irLed.write(GPIO_STATE::LOW); + } + else + { + irLed.write(GPIO_STATE::HIGH); + } + vTaskDelay(INFRARED_DELAY_MS); + irIndex = (irIndex+1)%sosSize; + } + +} diff --git a/tasks/aconnoTasks.h b/tasks/aconnoTasks.h index ba6cf0f..40c2f06 100644 --- a/tasks/aconnoTasks.h +++ b/tasks/aconnoTasks.h @@ -28,6 +28,7 @@ #define EXAMPLE_DELAY_MS (501) #define BEACON_DELAY_MS (1001) +#define INFRARED_DELAY_MS (150) /** * @brief Function logger @@ -105,6 +106,12 @@ void gyroFunction(void *arg); */ void bleBeaconFunction(void *arg); +/** + * @brief Infrared xxample function + * + */ +void infraredFunction(void *arg); + void testCallback();