Git Product home page Git Product logo

Comments (6)

shahpiyushv avatar shahpiyushv commented on June 2, 2024

@weilie91 , please check this function in App.c which is the callback. You can add your hardware logic there. ESP32-DevKit-C, which is our most common boar,d does not have in-built user controllable LED, and so the example too does not have any hardware control.

from esp-apple-homekit-adk.

emanuelelaface avatar emanuelelaface commented on June 2, 2024

Is there a simple GPIO blinking led example? I am familiar with Arduino (and C) but I have no idea how to start to control the GPIOs for this board from the App.c function.
As far as I understood the callbacks are HandleLightBulbOnWrite to change status and HandleLightBulbOnRead to get the status, but how can I switch on and off a pin? Could you please point me to a documentation to understand what I am suppose to write there?
Many thanks and sorry for the dumb question.

from esp-apple-homekit-adk.

emanuelelaface avatar emanuelelaface commented on June 2, 2024

Ok I find what to add, I report here because it can be useful for other beginners with ESP32 like me. Maybe you could add this (commented?) in the App.c as example of how to turn on the GPIO.

Everything goes in App.c.
First thing is to include the header for GPIOs, I also added a define for the name of the GPIO to switch:

#include "driver/gpio.h"
#define LED_GPIO 2

then you need to setup at the startup the GPIO as output. I am not sure where is the better place to put this code, but I setup it in the AppAccessoryServerStart function that runs before starting the app, maybe it can be done in a better place. At the end of the function I added:

gpio_reset_pin(LED_GPIO);
gpio_set_direction(LED_GPIO, GPIO_MODE_OUTPUT);

finally the logic to turn it on on off stays in the HandleLightBulbOnWrite and has to change the value of the led as function of the value:

if (value) {
    gpio_set_level(LED_GPIO, 1);
} else {
    gpio_set_level(LED_GPIO, 0);
}

That's all. This will turn on and off the GPIO pin with the number 2 on the board (on some board where the red led is connected to number 2 you will see that one blinking as well, mine is not connected to any GPIO).

from esp-apple-homekit-adk.

AramVartanyan avatar AramVartanyan commented on June 2, 2024

@emanuelelaface it is better to use this example to setup the output:
https://github.com/espressif/esp-idf/tree/master/examples/peripherals/gpio/generic_gpio

In this way you can avoid possible unwanted behavior of the I/O peripherals.

from esp-apple-homekit-adk.

emanuelelaface avatar emanuelelaface commented on June 2, 2024

Thanks, I see that it may be safer to initialize it in the proper way. Where would you put the init part in the homekit example? I sued the AppAccessoryServerStart but it doesn't sound as the correct place (it should be used for the server) but on the other hand there is no initializer there for the peripherals.

from esp-apple-homekit-adk.

AramVartanyan avatar AramVartanyan commented on June 2, 2024

For me the proper place would be in the InitializePlatform function inside app_main.c

from esp-apple-homekit-adk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.