Skip to content

Commit

Permalink
reformatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Claypuppet committed Dec 24, 2019
1 parent c7789bf commit d939dfd
Show file tree
Hide file tree
Showing 16 changed files with 60 additions and 60 deletions.
4 changes: 2 additions & 2 deletions bgeigiecast/api_connector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ void ApiConnector::stop() {

bool ApiConnector::test() {
WiFiClient client;
bool success = client.connect(API_HOST, 80)!=0;
bool success = client.connect(API_HOST, 80) != 0;
client.stop();
return success;
}

bool ApiConnector::is_connected() {
return WiFi.status()==WL_CONNECTED;
return WiFi.status() == WL_CONNECTED;
}

bool ApiConnector::send_reading() {
Expand Down
2 changes: 1 addition & 1 deletion bgeigiecast/bgeigie_connector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ bool BGeigieConnector::get_reading(Reading& out) {
while(_serial_connection.available() > 0) {
char c = static_cast<char>(_serial_connection.read());
_buffer += c;
if(c=='\n') {
if(c == '\n') {
// DEBUG_PRINT("New reading: "); DEBUG_PRINT(_buffer);
out = _buffer.c_str();
_buffer = "";
Expand Down
4 changes: 2 additions & 2 deletions bgeigiecast/bgeigiecast.ino
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ HardwareSerial& bGeigieSerialConnection = Serial2;

void controller_sleep(uint32_t millis_to_sleep) {
esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_TIMER);
esp_sleep_enable_timer_wakeup(millis_to_sleep*1000);
esp_sleep_enable_timer_wakeup(millis_to_sleep * 1000);

DEBUG_PRINTLN("-----\nEntering sleep");
DEBUG_FLUSH();
Expand Down Expand Up @@ -87,7 +87,7 @@ void setup() {

// Set gpio pin configurations
gpio_config_t io_conf{
.pin_bit_mask = 1ULL << MODE_BUTTON_PIN,
.pin_bit_mask = 1ULL<<MODE_BUTTON_PIN,
.mode = GPIO_MODE_INPUT,
.pull_up_en = GPIO_PULLUP_ENABLE,
.pull_down_en = GPIO_PULLDOWN_DISABLE,
Expand Down
6 changes: 3 additions & 3 deletions bgeigiecast/bluetooth_connector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,12 @@ bool BluetoohConnector::send_reading(Reading& reading) {
const static uint8_t max_segment_size = 20; // Max that can be send over bluetooth
do {
++segment;
uint8_t segment_size = segment*max_segment_size > size ? size%max_segment_size : max_segment_size;
uint8_t segment_size = segment * max_segment_size > size ? size % max_segment_size : max_segment_size;
char to_send[segment_size];
strncpy(to_send, reading_str + ((segment - 1)*max_segment_size), segment_size);
strncpy(to_send, reading_str + ((segment - 1) * max_segment_size), segment_size);

pDataRXCharacteristic->setValue((uint8_t*) to_send, segment_size);
pDataRXCharacteristic->notify();
} while(segment*max_segment_size < size);
} while(segment * max_segment_size < size);
return true;
}
10 changes: 5 additions & 5 deletions bgeigiecast/button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void buttonTrigger(void* arg) {

Button::Button(uint8_t pin, uint8_t pull_type) :
_pin(pin),
_pull_type_mode(pull_type==PULLDOWN ? HIGH : LOW),
_pull_type_mode(pull_type == PULLDOWN ? HIGH : LOW),
_observer(nullptr),
_current_state(false),
_last_state_change(0),
Expand All @@ -28,7 +28,7 @@ Button::~Button() {
void Button::activate() {
gpio_set_intr_type((gpio_num_t) _pin, GPIO_INTR_ANYEDGE);
gpio_isr_handler_add((gpio_num_t) _pin, buttonTrigger, this);
_current_state = digitalRead(_pin)==_pull_type_mode;
_current_state = digitalRead(_pin) == _pull_type_mode;
}

void Button::set_observer(ButtonObserver* observer) {
Expand All @@ -40,8 +40,8 @@ bool Button::currently_pressed() const {
}

bool Button::state_changed(int state, uint32_t time) {
bool new_state = state==_pull_type_mode;
if(new_state==_current_state || _last_state_change + BUTTON_DEBOUNCE_TIME_MILLIS > time) {
bool new_state = state == _pull_type_mode;
if(new_state == _current_state || _last_state_change + BUTTON_DEBOUNCE_TIME_MILLIS > time) {
_current_state = new_state;
return false;
}
Expand All @@ -50,7 +50,7 @@ bool Button::state_changed(int state, uint32_t time) {
if(_current_state) {
if(_observer) { _observer->on_button_down(this); }
if(_on_button_down_fn) { _on_button_down_fn(this); }
} else if(_last_state_change!=0) { // Ignore initial presses at startups
} else if(_last_state_change != 0) { // Ignore initial presses at startups
if(_observer) { _observer->on_button_release(this); }
if(_on_button_release_fn) { _on_button_release_fn(this); }
if(_observer) { _observer->on_button_pressed(this, time - _last_state_change); }
Expand Down
4 changes: 2 additions & 2 deletions bgeigiecast/circular_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CircularBuffer {
* @param val
*/
void add(T val) {
buffer[(current + count)%max] = val;
buffer[(current + count) % max] = val;
if(count < max) {
++count;
} else {
Expand All @@ -45,7 +45,7 @@ class CircularBuffer {
* @return: true if buffer is empty
*/
bool empty() const {
return count==0;
return count == 0;
}

/**
Expand Down
12 changes: 6 additions & 6 deletions bgeigiecast/conf_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ bool ConfigWebServer::connect(bool try_wifi) {

auto time = millis();
while(millis() - time < 2000) {
if(WiFi.status()==WL_CONNECTED) {
if(WiFi.status() == WL_CONNECTED) {
DEBUG_PRINTF("Connected to %s, IP address: %s\n", _config.get_wifi_ssid(), WiFi.localIP().toString().c_str());
HttpPages::internet_access = true;
return true;
Expand Down Expand Up @@ -163,7 +163,7 @@ void ConfigWebServer::start_server() {
_server.on("/update", HTTP_POST, [this]() {
// Complete
_server.sendHeader("Connection", "close");
if(_server.upload().totalSize==0 || Update.hasError()) {
if(_server.upload().totalSize == 0 || Update.hasError()) {
_server.send(500, "text/plain", "FAIL");
} else {
_server.send(200, "text/plain", "OK");
Expand Down Expand Up @@ -211,16 +211,16 @@ void ConfigWebServer::handle_save() {
_config.set_api_key(_server.arg(FORM_NAME_API_KEY).c_str(), false);
}
if(_server.hasArg(FORM_NAME_USE_DEV)) {
_config.set_use_dev(_server.arg(FORM_NAME_USE_DEV)=="1", false);
_config.set_use_dev(_server.arg(FORM_NAME_USE_DEV) == "1", false);
}
if(_server.hasArg(FORM_NAME_LED_INTENSITY)) {
_config.set_led_color_intensity(clamp<uint8_t>(_server.arg(FORM_NAME_LED_INTENSITY).toInt(), 5, 100), false);
}
if(_server.hasArg(FORM_NAME_LED_COLOR)) {
_config.set_led_color_blind(strcmp(_server.arg(FORM_NAME_LED_COLOR).c_str(), "1")==0, false);
_config.set_led_color_blind(strcmp(_server.arg(FORM_NAME_LED_COLOR).c_str(), "1") == 0, false);
}
if(_server.hasArg(FORM_NAME_LOC_HOME)) {
_config.set_use_home_location(strcmp(_server.arg(FORM_NAME_LOC_HOME).c_str(), "1")==0, false);
_config.set_use_home_location(strcmp(_server.arg(FORM_NAME_LOC_HOME).c_str(), "1") == 0, false);
}
if(_server.hasArg(FORM_NAME_LOC_HOME_LAT)) {
_config.set_home_latitude(clamp<double>(_server.arg(FORM_NAME_LOC_HOME_LAT).toDouble(), -90.0, 90.0), false);
Expand Down Expand Up @@ -249,7 +249,7 @@ void ConfigWebServer::handle_update_uploading() {
case UPLOAD_FILE_WRITE: {
DEBUG_PRINTF(".");
auto write_size = Update.write(upload.buf, upload.currentSize);
if(write_size!=upload.currentSize) {
if(write_size != upload.currentSize) {
DEBUG_PRINTF("Something failed while uploading (wrote %d out of %d)\n", write_size, upload.currentSize);
Update.abort();
}
Expand Down
2 changes: 1 addition & 1 deletion bgeigiecast/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void Controller::initialize() {
}

void Controller::on_button_pressed(Button* button, uint32_t millis_pressed) {
if(button->get_pin()==MODE_BUTTON_PIN) {
if(button->get_pin() == MODE_BUTTON_PIN) {
if(millis_pressed > BUTTON_LONG_PRESSED_MILLIS_TRESHOLD) {
// DEBUG_PRINTLN("Button long pressed");
schedule_event(Event_enum::e_c_button_long_pressed);
Expand Down
28 changes: 14 additions & 14 deletions bgeigiecast/esp_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,16 @@ double EspConfig::get_last_latitude() const {
void EspConfig::set_all() {
_memory.begin(memory_name, true);
_device_id = _memory.getUShort(key_device_id, D_DEVICE_ID);
if(_memory.getString(key_ap_password, _ap_password, CONFIG_VAL_MAX)==0) {
if(_memory.getString(key_ap_password, _ap_password, CONFIG_VAL_MAX) == 0) {
strcpy(_ap_password, D_ACCESS_POINT_PASSWORD);
}
if(_memory.getString(key_wifi_ssid, _wifi_ssid, CONFIG_VAL_MAX)==0) {
if(_memory.getString(key_wifi_ssid, _wifi_ssid, CONFIG_VAL_MAX) == 0) {
strcpy(_wifi_ssid, D_WIFI_SSID);
}
if(_memory.getString(key_wifi_password, _wifi_password, CONFIG_VAL_MAX)==0) {
if(_memory.getString(key_wifi_password, _wifi_password, CONFIG_VAL_MAX) == 0) {
strcpy(_wifi_password, D_WIFI_PASSWORD);
}
if(_memory.getString(key_api_key, _api_key, CONFIG_VAL_MAX)==0) {
if(_memory.getString(key_api_key, _api_key, CONFIG_VAL_MAX) == 0) {
strcpy(_api_key, D_APIKEY);
}
_use_dev = _memory.getBool(key_use_dev, D_USE_DEV_SERVER);
Expand All @@ -152,7 +152,7 @@ bool EspConfig::clear() {
}

void EspConfig::set_device_id(uint16_t device_id, bool force) {
if(force || (device_id!=_device_id)) {
if(force || (device_id != _device_id)) {
if(_memory.begin(memory_name)) {
_device_id = device_id;
_memory.putUShort(key_device_id, _device_id);
Expand All @@ -164,7 +164,7 @@ void EspConfig::set_device_id(uint16_t device_id, bool force) {
}

void EspConfig::set_ap_password(const char* ap_password, bool force) {
if(force || (ap_password!=nullptr && strlen(ap_password) < CONFIG_VAL_MAX)) {
if(force || (ap_password != nullptr && strlen(ap_password) < CONFIG_VAL_MAX)) {
if(_memory.begin(memory_name)) {
strcpy(_ap_password, ap_password);
_memory.putString(key_ap_password, _ap_password);
Expand All @@ -176,7 +176,7 @@ void EspConfig::set_ap_password(const char* ap_password, bool force) {
}

void EspConfig::set_wifi_ssid(const char* wifi_ssid, bool force) {
if(force || (wifi_ssid!=nullptr && strlen(wifi_ssid) < CONFIG_VAL_MAX)) {
if(force || (wifi_ssid != nullptr && strlen(wifi_ssid) < CONFIG_VAL_MAX)) {
if(_memory.begin(memory_name)) {
strcpy(_wifi_ssid, wifi_ssid);
_memory.putString(key_wifi_ssid, _wifi_ssid);
Expand All @@ -188,7 +188,7 @@ void EspConfig::set_wifi_ssid(const char* wifi_ssid, bool force) {
}

void EspConfig::set_wifi_password(const char* wifi_password, bool force) {
if(force || (wifi_password!=nullptr && strlen(wifi_password) < CONFIG_VAL_MAX)) {
if(force || (wifi_password != nullptr && strlen(wifi_password) < CONFIG_VAL_MAX)) {
if(_memory.begin(memory_name)) {
strcpy(_wifi_password, wifi_password);
_memory.putString(key_wifi_password, _wifi_password);
Expand All @@ -200,7 +200,7 @@ void EspConfig::set_wifi_password(const char* wifi_password, bool force) {
}

void EspConfig::set_api_key(const char* api_key, bool force) {
if(force || (api_key!=nullptr && strlen(api_key) < CONFIG_VAL_MAX)) {
if(force || (api_key != nullptr && strlen(api_key) < CONFIG_VAL_MAX)) {
if(_memory.begin(memory_name)) {
strcpy(_api_key, api_key);
_memory.putString(key_api_key, _api_key);
Expand All @@ -212,7 +212,7 @@ void EspConfig::set_api_key(const char* api_key, bool force) {
}

void EspConfig::set_use_dev(bool use_dev, bool force) {
if(force || (use_dev!=_use_dev)) {
if(force || (use_dev != _use_dev)) {
if(_memory.begin(memory_name)) {
_use_dev = use_dev;
_memory.putBool(key_use_dev, use_dev);
Expand All @@ -224,7 +224,7 @@ void EspConfig::set_use_dev(bool use_dev, bool force) {
}

void EspConfig::set_led_color_blind(bool led_color_blind, bool force) {
if(force || (led_color_blind!=_led_color_blind)) {
if(force || (led_color_blind != _led_color_blind)) {
if(_memory.begin(memory_name)) {
_led_color_blind = led_color_blind;
_memory.putBool(key_led_color_blind, led_color_blind);
Expand All @@ -236,7 +236,7 @@ void EspConfig::set_led_color_blind(bool led_color_blind, bool force) {
}

void EspConfig::set_led_color_intensity(uint8_t led_color_intensity, bool force) {
if(force || (led_color_intensity!=_led_color_intensity)) {
if(force || (led_color_intensity != _led_color_intensity)) {
if(_memory.begin(memory_name)) {
_led_color_intensity = led_color_intensity;
_memory.putUChar(key_led_color_intensity, led_color_intensity);
Expand All @@ -249,7 +249,7 @@ void EspConfig::set_led_color_intensity(uint8_t led_color_intensity, bool force)
}

void EspConfig::set_saved_state(uint8_t saved_state, bool force) {
if(force || (saved_state!=_saved_state)) {
if(force || (saved_state != _saved_state)) {
if(_memory.begin(memory_name)) {
_saved_state = saved_state;
_memory.putUChar(key_saved_state, saved_state);
Expand All @@ -261,7 +261,7 @@ void EspConfig::set_saved_state(uint8_t saved_state, bool force) {
}

void EspConfig::set_use_home_location(bool use_home_location, bool force) {
if(force || (use_home_location!=_use_home_location)) {
if(force || (use_home_location != _use_home_location)) {
if(_memory.begin(memory_name)) {
_use_home_location = use_home_location;
_memory.putBool(key_led_color_blind, use_home_location);
Expand Down
6 changes: 3 additions & 3 deletions bgeigiecast/mode_led.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ void ModeLED::set_color(ModeLED::ModeColor color) {

void ModeLED::blink(ModeLED::ModeColor color, double frequency, double percentage_on) {
// Blink LED
double blink_millis = 1000/frequency;
uint32_t cycle_now = millis()%static_cast<uint32_t>(blink_millis);
uint32_t threshold = static_cast<uint32_t>(blink_millis*(percentage_on/100));
double blink_millis = 1000 / frequency;
uint32_t cycle_now = millis() % static_cast<uint32_t>(blink_millis);
uint32_t threshold = static_cast<uint32_t>(blink_millis * (percentage_on / 100));
if(cycle_now < threshold && !_blink_state) {
set_color(color);
_blink_state = true;
Expand Down
26 changes: 13 additions & 13 deletions bgeigiecast/reading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
#define LONG_LAT_PRECISION 0.001

double dm_to_dd(double dm) {
double degree = static_cast<int>(dm/100);
double minutes = dm - (degree*100);
return degree + minutes/60;
double degree = static_cast<int>(dm / 100);
double minutes = dm - (degree * 100);
return degree + minutes / 60;
}

Reading::Reading() :
Expand Down Expand Up @@ -76,7 +76,7 @@ Reading& Reading::operator=(const char* reading_str) {
}

Reading& Reading::operator=(const Reading& other) {
if(&other!=this) {
if(&other != this) {
_status = other._status;
_average_of = other._average_of;
_device_id = other._device_id;
Expand All @@ -95,11 +95,11 @@ Reading& Reading::operator=(const Reading& other) {
}

Reading& Reading::operator+=(const Reading& o) {
if(!(o._status & k_reading_valid) || o._average_of==0) {
if(!(o._status & k_reading_valid) || o._average_of == 0) {
// Do nothing with the other, not valid or empty
return *this;
}
if(_average_of==0) {
if(_average_of == 0) {
// Assign other to this
return operator=(o);
}
Expand All @@ -124,8 +124,8 @@ Reading& Reading::operator+=(const Reading& o) {
}

// Sensor data
_cpm = ((_cpm*_average_of) + (o_cpm*o._average_of))/(_average_of + o._average_of);
_cpb = ((_cpb*_average_of) + (o_cpb*o._average_of))/(_average_of + o._average_of);
_cpm = ((_cpm * _average_of) + (o_cpm * o._average_of)) / (_average_of + o._average_of);
_cpb = ((_cpb * _average_of) + (o_cpb * o._average_of)) / (_average_of + o._average_of);

// Use latest gps location
if(o._status & k_reading_gps_ok) {
Expand Down Expand Up @@ -206,7 +206,7 @@ void Reading::parse_values() {
&checksum
);

if(parse_result==EXPECTED_PARSE_RESULT_COUNT && VALID_BGEIGIE_ID(_device_id)) { // 15 values to be parsed
if(parse_result == EXPECTED_PARSE_RESULT_COUNT && VALID_BGEIGIE_ID(_device_id)) { // 15 values to be parsed
_status |= k_reading_parsed;

// TODO Validate checksum?
Expand All @@ -215,17 +215,17 @@ void Reading::parse_values() {
_status |= k_reading_valid;
}

if(sensor_status=='A') {
if(sensor_status == 'A') {
_status |= k_reading_sensor_ok;
}
if(gps_status=='A') {
if(gps_status == 'A') {
_status |= k_reading_gps_ok;

_latitude = dm_to_dd(lat_dm);
_longitude = dm_to_dd(long_dm);

if(n_or_s=='S') { _latitude *= -1; }
if(w_or_e=='W') { _longitude *= -1; }
if(n_or_s == 'S') { _latitude *= -1; }
if(w_or_e == 'W') { _longitude *= -1; }
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions bgeigiecast/reading.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

#define READING_STR_MAX 100

constexpr uint8_t k_reading_parsed = 0x1u << 0u;
constexpr uint8_t k_reading_sensor_ok = 0x1u << 1u;
constexpr uint8_t k_reading_gps_ok = 0x1u << 2u;
constexpr uint8_t k_reading_valid = 0x1u << 3u;
constexpr uint8_t k_reading_parsed = 0x1u<<0u;
constexpr uint8_t k_reading_sensor_ok = 0x1u<<1u;
constexpr uint8_t k_reading_gps_ok = 0x1u<<2u;
constexpr uint8_t k_reading_valid = 0x1u<<3u;

/**
* Container for a reading from the bGeigie, with some extra functions
Expand Down
2 changes: 1 addition & 1 deletion bgeigiecast/reporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void Reporter::set_report_output(bool bt, bool api) {
}

uint32_t Reporter::time_till_next_reading(uint32_t current) const {
return _last_reading_moment!=0 && current - _last_reading_moment < READING_DELAY ? READING_DELAY
return _last_reading_moment != 0 && current - _last_reading_moment < READING_DELAY ? READING_DELAY
- (current - _last_reading_moment) : 0;
}

Expand Down
Loading

0 comments on commit d939dfd

Please sign in to comment.