Skip to content

Commit

Permalink
Tachometer Gauge Split to it's own file
Browse files Browse the repository at this point in the history
  • Loading branch information
dowster committed Dec 6, 2019
1 parent 4f6b1c6 commit f6a7d31
Show file tree
Hide file tree
Showing 8 changed files with 312 additions and 247 deletions.
10 changes: 5 additions & 5 deletions code/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The following lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
# The following lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(e28-cluster)
18 changes: 9 additions & 9 deletions code/Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
# project subdirectory.
#

PROJECT_NAME := e28-cluster

include $(IDF_PATH)/make/project.mk

#
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
# project subdirectory.
#

PROJECT_NAME := e28-cluster

include $(IDF_PATH)/make/project.mk

11 changes: 6 additions & 5 deletions code/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
idf_component_register(SRCS "main.c"
"fuel_gauge.c"
"temp_gauge.c"
"speedometer_gauge.c"
INCLUDE_DIRS ".")
idf_component_register(SRCS "main.c"
"fuel_gauge.c"
"temp_gauge.c"
"speedometer_gauge.c"
"tachometer_gauge.c"
INCLUDE_DIRS ".")
10 changes: 5 additions & 5 deletions code/main/component.mk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# "main" pseudo-component makefile.
#
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)

#
# "main" pseudo-component makefile.
#
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)

158 changes: 79 additions & 79 deletions code/main/fuel_gauge.c
Original file line number Diff line number Diff line change
@@ -1,80 +1,80 @@
#include "esp_err.h"
#include "esp_log.h"

#include <driver/gpio.h>
#include <driver/dac.h>

static dac_channel_t fuel_gauge_channel = -1;
static gpio_num_t low_fuel_indicator_pin = -1;

/**
* Setup the temperature gauge output.
*
* @param gauge dac output pin
* @param low_fuel_indicator output pin
*/
void setup_fuel_gauge(dac_channel_t gauge, gpio_num_t low_fuel_indicator) {
if(gauge != -1) {
esp_err_t error = dac_output_enable(gauge);
if(error == ESP_OK) {
fuel_gauge_channel = gauge;
}
}

if(low_fuel_indicator != -1 &&
(
low_fuel_indicator < GPIO_NUM_34 || // pins 34 - 39 on esp32 are
low_fuel_indicator > GPIO_NUM_39 // input only
)) {
gpio_config_t config = {
.pin_bit_mask = low_fuel_indicator,
.mode = GPIO_MODE_OUTPUT,
.pull_up_en = GPIO_PULLUP_DISABLE,
.pull_down_en = GPIO_PULLDOWN_ENABLE,
.intr_type = GPIO_INTR_DISABLE
};
esp_err_t error = gpio_config(&config);
if(error == ESP_OK) {
low_fuel_indicator_pin = low_fuel_indicator;
}

}
}

/**
* Set the position of the fuel gauge in terms of % full
*
* @param percent_full for the gauge to point to
*/
void write_to_fuel_gauge(int percent_full) {
if(fuel_gauge_channel == -1) {
ESP_LOGE("write_to_fuel_gauge", "Fuel gauge not yet initialized, please call setup_fuel_gauge first.");
} else {
int voltage = 70 + ((percent_full * 80) / 100);
voltage &= 255;
ESP_LOGI("FUEL VOLTAGE", "[V: %d, F: %d]", voltage, percent_full);
dac_output_voltage(fuel_gauge_channel, voltage);
}
}

/**
* Turns the low fuel indicator light on if it's hooked up.
*/
void enable_low_fuel_indicator() {
if(low_fuel_indicator_pin == -1) {
ESP_LOGE("enable_low_fuel_indicator", "low fuel indicator not yet initialized, please call setup_fuel_gauge first.");
} else {
gpio_set_level(low_fuel_indicator_pin, 1);
}
}

/**
* Turns the low fuel indicator light off if it's hooked up.
*/
void disable_low_fuel_indicator() {
if(low_fuel_indicator_pin == -1) {
ESP_LOGE("enable_low_fuel_indicator", "low fuel indicator not yet initialized, please call setup_fuel_gauge first.");
} else {
gpio_set_level(low_fuel_indicator_pin, 0);
}
#include "esp_err.h"
#include "esp_log.h"

#include <driver/gpio.h>
#include <driver/dac.h>

static dac_channel_t fuel_gauge_channel = -1;
static gpio_num_t low_fuel_indicator_pin = -1;

/**
* Setup the temperature gauge output.
*
* @param gauge dac output pin
* @param low_fuel_indicator output pin
*/
void setup_fuel_gauge(dac_channel_t gauge, gpio_num_t low_fuel_indicator) {
if(gauge != -1) {
esp_err_t error = dac_output_enable(gauge);
if(error == ESP_OK) {
fuel_gauge_channel = gauge;
}
}

if(low_fuel_indicator != -1 &&
(
low_fuel_indicator < GPIO_NUM_34 || // pins 34 - 39 on esp32 are
low_fuel_indicator > GPIO_NUM_39 // input only
)) {
gpio_config_t config = {
.pin_bit_mask = low_fuel_indicator,
.mode = GPIO_MODE_OUTPUT,
.pull_up_en = GPIO_PULLUP_DISABLE,
.pull_down_en = GPIO_PULLDOWN_ENABLE,
.intr_type = GPIO_INTR_DISABLE
};
esp_err_t error = gpio_config(&config);
if(error == ESP_OK) {
low_fuel_indicator_pin = low_fuel_indicator;
}

}
}

/**
* Set the position of the fuel gauge in terms of % full
*
* @param percent_full for the gauge to point to
*/
void write_to_fuel_gauge(int percent_full) {
if(fuel_gauge_channel == -1) {
ESP_LOGE("write_to_fuel_gauge", "Fuel gauge not yet initialized, please call setup_fuel_gauge first.");
} else {
int voltage = 70 + ((percent_full * 80) / 100);
voltage &= 255;
ESP_LOGI("FUEL VOLTAGE", "[V: %d, F: %d]", voltage, percent_full);
dac_output_voltage(fuel_gauge_channel, voltage);
}
}

/**
* Turns the low fuel indicator light on if it's hooked up.
*/
void enable_low_fuel_indicator() {
if(low_fuel_indicator_pin == -1) {
ESP_LOGE("enable_low_fuel_indicator", "low fuel indicator not yet initialized, please call setup_fuel_gauge first.");
} else {
gpio_set_level(low_fuel_indicator_pin, 1);
}
}

/**
* Turns the low fuel indicator light off if it's hooked up.
*/
void disable_low_fuel_indicator() {
if(low_fuel_indicator_pin == -1) {
ESP_LOGE("enable_low_fuel_indicator", "low fuel indicator not yet initialized, please call setup_fuel_gauge first.");
} else {
gpio_set_level(low_fuel_indicator_pin, 0);
}
}
Loading

0 comments on commit f6a7d31

Please sign in to comment.