{"id":21166368,"url":"https://github.com/markamdev/cenvirolib","last_synced_at":"2025-03-14T16:46:43.820Z","repository":{"id":219813457,"uuid":"247500200","full_name":"markamdev/cenvirolib","owner":"markamdev","description":"C library for Enviro pHat (a Raspberry Pi shield with thermometer, barometer, leds and others)","archived":false,"fork":false,"pushed_at":"2020-10-20T16:12:45.000Z","size":55,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-21T10:11:34.894Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/markamdev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2020-03-15T16:01:00.000Z","updated_at":"2020-10-20T16:12:48.000Z","dependencies_parsed_at":"2024-01-29T22:59:20.389Z","dependency_job_id":null,"html_url":"https://github.com/markamdev/cenvirolib","commit_stats":null,"previous_names":["markamdev/cenvirolib"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markamdev%2Fcenvirolib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markamdev%2Fcenvirolib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markamdev%2Fcenvirolib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markamdev%2Fcenvirolib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/markamdev","download_url":"https://codeload.github.com/markamdev/cenvirolib/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243615556,"owners_count":20319728,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-20T14:49:37.179Z","updated_at":"2025-03-14T16:46:43.785Z","avatar_url":"https://github.com/markamdev.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CEnviroLib - C Enviro shield Library\n\nThis project provides simple C library for handling Enviro pHat shield on Raspberry Pi.\n\n[Enviro pHat](https://shop.pimoroni.com/products/enviro-phat) is a Rasperry Pi compatible shield (perfectly firs Pi Zero boards) with set of sensors: thermometer, barometer, light/color sensor and motion sensor. Producer provides only [Python library](https://github.com/pimoroni/enviro-phat) so it has been decided to prepare **CEnviroLib** project to support C application development.\n\n## Build and usage\n\n**CEnviroLib** is prepared as a simple Makefile-based project that builds static C library. To use it you own projects just download repository and run *make*:\n\n```bash\ngit clone https://github.com/markamdev/cenvirolib\nmake\n```\n\nIn case you're downloading the project to your PC but want to use in applications launched on Raspberry Pi please define which compiler should be used. Fo example it can be ***arm-linux-gnueabihf-gcc***:\n\n```bash\ngit clone https://github.com/markamdev/cenvirolib\ncd cenvirolib\nmake CC=arm-linux-gnueabihf-gcc\n```\n\nIn output directory (*./build*) you will find header file (*cenviro.h*) and library itself (*libcenviro.a*).\n\n### Thread unsafe version\n\nBy default library is compiled in thread-safe version with mutexes used to protect critical sections. Standard *pthread* library is used for this purpose.\n\nIf for some reason it is not desired to have mutex operations enabled (ex. pthread library is not available or application is using only single thread and mutexing is a CPU time wasting) code can be compiled in thread-unsafe version by defining *DISABLE_THREADSAFE*. This definition is added in *nothreadsafe* make target:\n\n```bash\nmake nothreadsafe\n```\n\n## Functionality\n\nThe goal of this project was to provide simple C library for Enviro pHat support. The intention was to make this shield easy to use - not to exhaust all possible configurations of the onboard chips. That's why only simple mode of operation is available for each of the sensors. Of course, as the full source code is available, developer can modify configuration flow to obtain desired results.\n\nLibrary has 4 logical modules with one header file each:\n\n* LED support - turning onboard white LEDs on and off (see [this chapter](#led-control))\n* \"Weather\" support - reading envirornment temperature and atmosspheric pressure (see [this chapter](#barometer-and-thermometer))\n* Light sensor support - reading lighting level and data from color sensor (see [this chapter](#light-sensor))\n* Motion sensor support - reading information about orientation (compass) and acceleration (see [this chapter](#motion-sensor))\n* ADC support - 4-channel analog-to-digital converter (see [this chapter](#ad-converter))\n\n## API\n\nTo use any API described in next chapters library has to be initialized first. Initialization is done using\n\n```c\nbool cenviro_init();\n```\n\nThis function returns *true* if initialization succeed, *false* otherwise. If library initialization failed then none of functions for getting/setting data can be used as it will return error or defaul value (\"0\" in most cases).\n\nWhen library is not needed or when application finishes, it is higly recommended to call:\n\n```c\nvoid cenviro_deinit();\n```\n\nto properly release all initialized resources (ex. unexport GPIO pin).\n\n### LED control\n\nAPI for this module contains one function:\n\n```C\nvoid cenviro_led_set(bool state);\n```\n\n#### cenviro_led_set()\n\nThis function sets onboard LED to **on** or **off** state depending on provided function parameter (**true** and **false** respectively).\n\n### Barometer and thermometer\n\nAPI for this module consist of following functions:\n\n```c\ndouble cenviro_weather_temperature();\n\ndouble cenviro_weather_pressure();\n\nuint8_t cenviro_weather_chip_id();\n```\n\n#### cenviro_weather_temperature()\n\nThis function returns current temperature value.\n\n#### cenviro_weather_pressure()\n\nThis function returns current pressure value.\n\n***WARNING*** Pressure data calibration function uses value computed by temperature data calibration function. If temperature has not been fetched and computed yet then first call to *cenviro_weather_pressure()* internaly invokes temperature data fetching and calibration computation. In case of long term pressure only monitoring (when significant temperature change can take place) it is highly recommended to periodically call *cenviro_weather_temperature()*.\n\n#### cenviro_weather_chip_id()\n\nThis function return \"weather\" sensor chip identifier (single byte, unsigned value).\n\n### Light sensor\n\nAPI for this module consist of following functions:\n\n```c\ncenviro_crgb_t cenviro_light_crgb_raw();\n\ncenviro_crgb_t cenviro_light_crgb_scaled();\n\nuint8_t cenviro_light_chip_id();\n\nconst char *cenviro_light_chip_name();\n```\n\nand one defined data type:\n\n```c\ntypedef struct\n{\n    uint16_t clear;\n    uint16_t red;\n    uint16_t green;\n    uint16_t blue;\n} cenviro_crgb_t;\n```\n\n#### cenviro_light_crgb_scaled()\n\nThis function returns *cenviro_crgb_t* structure with raw data from light sensor.\n\n#### cenviro_light_crgb_raw()\n\nThis function returns *cenviro_crgb_t* structure with scaled RGB data (0-255) and raw C (light intensity) data.\n\n#### cenviro_light_chip_id()\n\nThis function return light sensor chip identifier (single byte, unsigned value).\n\n#### cenviro_light_chip_name()\n\nThis function reutrn light sensor chip name if supported by library, or *(uknown)* string otherwise.\n\n### Motion sensor\n\nSupport for this module is **not yet implemented**.\n\n### AD converter\n\nSupport for this module is **not yet implemented**.\n\n## Demo and sample applications\n\nThis project provides following sample applications that show possible library use:\n\n* cenvirodemo\n  * source code in *./apps/demo*\n  * shows basic usage of all implemented modules,\n  * launch with *-h* to see help message\n* meteo-app\n  * source code in *./apps/meteo*\n  * once a second, in infinite loop, reads current temperature and pressur\n  * prints temperature and pressure values in top left corner of the console\n* sos-blink\n  * source in *./apps/sos-blink*\n  * application blinks S.O.S. signal (once or infinitely)\n* auto-light\n  * source in *./apps/auto-light*\n  * application simulates light controler - switches LED on and off based on current light intensity\n  * light switching theshold can be configured by command line param\n  * WARNING: onboad LEDs are detected by onboard sensor so to use this app one has to isolate sensor and LEDs\n\n## License\n\nCode is published under [MIT License](https://opensource.org/licenses/MIT) as it seems to be the most permissive license. If for some reason you need to have this code published with other license (ex. to reuse the code in your project) please contact [author](#author-/-contact) directly.\n\n## Author / contact\n\nIf you need to contact me feel free to write me an email:\n[markamdev.84#dontwantSPAM#gmail.com](maitlo:)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkamdev%2Fcenvirolib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarkamdev%2Fcenvirolib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkamdev%2Fcenvirolib/lists"}