Oleksii Kutuzov пре 3 година
родитељ
комит
64a2813d7d
3 измењених фајлова са 53 додато и 27 уклоњено
  1. 1 0
      .gitattributes
  2. 2 27
      BH1750.c
  3. 50 0
      BH1750.h

+ 1 - 0
.gitattributes

@@ -0,0 +1 @@
+* text=auto

+ 2 - 27
BH1750.c

@@ -14,20 +14,15 @@
 BH1750_mode bh1750_mode = BH1750_DEFAULT_MODE; // Current sensor mode
 uint8_t bh1750_mt_reg = BH1750_DEFAULT_MTREG; // Current MT register value
 
-//
-//	Initialization.
-//
 BH1750_STATUS bh1750_init() {
     if(BH1750_OK == bh1750_reset()) {
-        if(BH1750_OK == bh1750_set_mt_reg(BH1750_DEFAULT_MTREG)) // Set default value;
+        if(BH1750_OK == bh1750_set_mt_reg(BH1750_DEFAULT_MTREG)) {
             return BH1750_OK;
+        }
     }
     return BH1750_ERROR;
 }
 
-//
-//	Reset all registers to default value.
-//
 BH1750_STATUS bh1750_reset() {
     uint8_t command = 0x07;
     bool status;
@@ -43,11 +38,6 @@ BH1750_STATUS bh1750_reset() {
     return BH1750_ERROR;
 }
 
-//
-//	Set the power state.
-//	0 - sleep, low power.
-//	1 - running.
-//
 BH1750_STATUS bh1750_set_power_state(uint8_t PowerOn) {
     PowerOn = (PowerOn ? 1 : 0);
     bool status;
@@ -63,9 +53,6 @@ BH1750_STATUS bh1750_set_power_state(uint8_t PowerOn) {
     return BH1750_ERROR;
 }
 
-//
-//	Set the mode of converting. Look into bh1750_mode enum.
-//
 BH1750_STATUS bh1750_set_mode(BH1750_mode mode) {
     if(!((mode >> 4) || (mode >> 5))) {
         return BH1750_ERROR;
@@ -90,9 +77,6 @@ BH1750_STATUS bh1750_set_mode(BH1750_mode mode) {
     return BH1750_ERROR;
 }
 
-//
-//	Set the Measurement Time register. It allows to increase or decrease the sensitivity.
-//
 BH1750_STATUS bh1750_set_mt_reg(uint8_t mt_reg) {
     if(mt_reg < 31 || mt_reg > 254) {
         return BH1750_ERROR;
@@ -123,12 +107,6 @@ BH1750_STATUS bh1750_set_mt_reg(uint8_t mt_reg) {
     return BH1750_ERROR;
 }
 
-//
-//	Trigger the conversion in manual modes.
-//	For low resolution conversion time is typical 16 ms,
-//	for high resolution 120 ms. You need to wait until read the measurement value.
-//	There is no need to exit low power mode for manual conversion. It makes automatically.
-//
 BH1750_STATUS bh1750_trigger_manual_conversion() {
     if(BH1750_OK == bh1750_set_mode(bh1750_mode)) {
         return BH1750_OK;
@@ -136,9 +114,6 @@ BH1750_STATUS bh1750_trigger_manual_conversion() {
     return BH1750_ERROR;
 }
 
-//
-//	Read the converted value and calculate the result.
-//
 BH1750_STATUS bh1750_read_light(float* result) {
     float result_tmp;
     uint8_t rcv[2];

+ 50 - 0
BH1750.h

@@ -40,12 +40,62 @@ typedef enum {
     ONETIME_LOW_RES_MODE = 0x23
 } BH1750_mode;
 
+/**
+ * @brief Initialize the sensor. Sends the reset command and sets the measurement register to the default value.
+ * 
+ * @return BH1750_STATUS
+ */
 BH1750_STATUS bh1750_init();
+
+/**
+ * @brief Reset all registers to the default value.
+ * 
+ * @return BH1750_STATUS 
+ */
 BH1750_STATUS bh1750_reset();
+
+/**
+ * @brief Sets the power state. 1 - running; 0 - sleep, low power. 
+ * 
+ * @param PowerOn sensor state.
+ * @return BH1750_STATUS 
+ */
 BH1750_STATUS bh1750_set_power_state(uint8_t PowerOn);
+
+/**
+ * @brief Set the Measurement Time register. It allows to increase or decrease the sensitivity.
+ * 
+ * @param MTreg value from 31 to 254, defaults to 69.
+ * 
+ * @return BH1750_STATUS 
+ */
 BH1750_STATUS bh1750_set_mt_reg(uint8_t MTreg);
+
+/**
+ * @brief Set the mode of converting. Look into the bh1750_mode enum.
+ * 
+ * @param Mode mode enumerator
+ * @return BH1750_STATUS 
+ */
 BH1750_STATUS bh1750_set_mode(BH1750_mode Mode);
+
+/**
+ * @brief Trigger the conversion in manual modes. 
+ * 
+ * For a low-resolution mode, the conversion time is typically 16 ms, and for a high-resolution 
+ * mode is 120 ms. You need to wait until reading the measurement value. There is no need 
+ * to exit low-power mode for manual conversion. It makes automatically.
+ * 
+ * @return BH1750_STATUS 
+ */
 BH1750_STATUS bh1750_trigger_manual_conversion();
+
+/**
+ * @brief Read the converted value and calculate the result.
+ * 
+ * @param Result stores received value to this variable.
+ * @return BH1750_STATUS 
+ */
 BH1750_STATUS bh1750_read_light(float* Result);
 
 #endif /* BH1750_H_ */