Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove all exit calls #121

Open
whaleygeek opened this issue Feb 6, 2020 · 2 comments
Open

Remove all exit calls #121

whaleygeek opened this issue Feb 6, 2020 · 2 comments

Comments

@whaleygeek
Copy link
Owner

See: Achronite/energenie-ener314rt#8

@Achronite thanks for raising this, added it to my list.

@whaleygeek
Copy link
Owner Author

ANALYSIS:

This appears in 2 places in gpio_rpi.c, both in gpio_init()

gpio_rpi.c: 85 exit(-1); //TODO return a result code
https://github.com/whaleygeek/pyenergenie/blob/master/src/energenie/drv/gpio_rpi.c#L85

gpio_rpi.c: 104 exit(-1); //TODO return a result code
https://github.com/whaleygeek/pyenergenie/blob/master/src/energenie/drv/gpio_rpi.c#L104

The gpio_init() function should be changed to return a GPIO_RESULT that is 0 if ok, and non zero on fail. This can then be checked in the caller (and presumably propagated out in the same way by spi_init() using SPI_RESULT, then radio_init() can return a RADIO_RESULT.

radio.py init() must then check the return result, and raise an exception presumably if it is non zero.

This will then cause init.py init() to throw the exception, then calls to energenie.init() will propagate the exception into the main program. The main programs in all demos should then catch this exception and fail with a message and then hit a finally block, that tries to clean up the GPIO state so it is in a sensible default OFF state (thus allowing another run of the code to succeed if the hardware problem is now fixed);

@Achronite
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants