From d31761a4b3c2995cd3f2ed90e80c2da6d38cd92e Mon Sep 17 00:00:00 2001 From: "Pawel Spychalski (DzikuVx)" Date: Mon, 14 May 2018 20:08:45 +0200 Subject: [PATCH] Basic init page --- crossbow/config.h | 3 +- crossbow/crossbow.ino | 76 ++++++++++++++++++++------------------------------- crossbow/tx_oled.cpp | 39 ++++++++++++++++++++++++++ crossbow/tx_oled.h | 28 +++++++++++++++++++ 4 files changed, 97 insertions(+), 49 deletions(-) create mode 100644 crossbow/tx_oled.cpp create mode 100644 crossbow/tx_oled.h diff --git a/crossbow/config.h b/crossbow/config.h index cfb4482..44c13d4 100644 --- a/crossbow/config.h +++ b/crossbow/config.h @@ -18,7 +18,7 @@ #define DEVICE_MODE_TX // #define DEVICE_MODE_RX -// #define FEATURE_TX_OLED +#define FEATURE_TX_OLED // #define FORCE_TX_WITHOUT_INPUT /* @@ -32,6 +32,5 @@ #define DEBUG_SERIAL // #define DEBUG_PING_PONG // #define DEBUG_LED -// #define DEBUG_TX_INPUT_ON_OLED #endif diff --git a/crossbow/crossbow.ino b/crossbow/crossbow.ino index aae77ff..df4d768 100644 --- a/crossbow/crossbow.ino +++ b/crossbow/crossbow.ino @@ -57,13 +57,8 @@ volatile int16_t TxInput::channels[TX_INPUT_CHANNEL_COUNT]; BuzzerState_t buzzer; #ifdef FEATURE_TX_OLED -#include "Wire.h" - -#define OLED_RESET -1 -#include -Adafruit_SSD1306 display(OLED_RESET); -uint32_t lastOledTaskTime = 0; - +#include "tx_oled.h" +TxOled oled; #endif #include "tactile.h" @@ -71,11 +66,6 @@ uint32_t lastOledTaskTime = 0; Tactile button0(BUTTON_0_PIN); Tactile button1(BUTTON_1_PIN); - // uint8_t buttonStates[2] = {HIGH, HIGH}; - // uint8_t previousButtonStates[2] = {HIGH, HIGH}; - // uint32_t buttonPressMillis[2] = {0, 0}; - // uint8_t buttonAction[2] = {BUTTON_ACTION_NONE, BUTTON_ACTION_NONE}; - #endif /* @@ -252,13 +242,8 @@ void setup(void) #ifdef DEVICE_MODE_TX #ifdef FEATURE_TX_OLED - Wire.setClock(400000); - - display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32) - display.setTextSize(1); - display.setTextColor(WHITE); - display.clearDisplay(); - display.display(); + oled.init(&radioState); + oled.page(TX_PAGE_INIT); #endif /* @@ -625,41 +610,38 @@ void loop(void) } #ifdef FEATURE_TX_OLED - if ( - currentMillis - lastOledTaskTime > OLED_UPDATE_RATE - ) { - lastOledTaskTime = currentMillis; - display.clearDisplay(); + // if ( + // currentMillis - lastOledTaskTime > OLED_UPDATE_RATE + // ) { + // lastOledTaskTime = millis(); - display.setTextColor(WHITE, BLACK); - display.setCursor(0, 0); - display.setTextSize(3); - display.print(radioState.rssi); + - display.setCursor(18, 28); - display.setTextSize(2); - display.print(radioState.snr); + // display.setTextColor(WHITE, BLACK); + // display.setCursor(0, 0); + // display.setTextSize(3); + // display.print(radioState.rssi); - display.setCursor(74, 0); - display.setTextSize(3); - display.print(rxDeviceState.rssi); + // display.setCursor(18, 28); + // display.setTextSize(2); + // display.print(radioState.snr); - display.setCursor(92, 28); - display.setTextSize(2); - display.print(rxDeviceState.snr); + // display.setCursor(74, 0); + // display.setTextSize(3); + // display.print(rxDeviceState.rssi); - #ifdef DEBUG_TX_INPUT_ON_OLED - display.setCursor(0, 48); - display.setTextSize(2); - display.print(txInput.channels[0]); - #endif + // display.setCursor(92, 28); + // display.setTextSize(2); + // display.print(rxDeviceState.snr); - display.setCursor(54, 48); - display.setTextSize(2); - display.print(txDeviceState.roundtrip); + // display.setCursor(54, 48); + // display.setTextSize(2); + // display.print(txDeviceState.roundtrip); + + // display.display(); - display.display(); - } + // Serial.println(millis() - lastOledTaskTime); + // } #endif /* diff --git a/crossbow/tx_oled.cpp b/crossbow/tx_oled.cpp new file mode 100644 index 0000000..4d78dac --- /dev/null +++ b/crossbow/tx_oled.cpp @@ -0,0 +1,39 @@ +#include "tx_oled.h" + +TxOled::TxOled(void) { + Adafruit_SSD1306 _display(-1); +} + +void TxOled::init(volatile RadioState_t *radioState) { + _display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32) + _display.setTextSize(1); + _display.setTextColor(WHITE); + _display.clearDisplay(); + _display.display(); + + _radioState = radioState; +} + +void TxOled::page(int page) { + switch (page) { + + case TX_PAGE_INIT: + pageInit(); + break; + + } +} + +void TxOled::pageInit(void) { + _display.clearDisplay(); + + _display.setTextColor(WHITE, BLACK); + _display.setCursor(0, 0); + _display.setTextSize(2); + _display.print("Rdy "); + _display.print(_radioState->loraTxPower); + _display.print("dBm"); +} + + + diff --git a/crossbow/tx_oled.h b/crossbow/tx_oled.h new file mode 100644 index 0000000..2a22f49 --- /dev/null +++ b/crossbow/tx_oled.h @@ -0,0 +1,28 @@ +#pragma once + +#ifndef TX_OLED_H +#define TX_OLED_H + +#include +#include "Wire.h" +#include "variables.h" + +#define OLED_RESET -1 + +enum txOledPages { + TX_PAGE_NONE, + TX_PAGE_INIT, +}; + +class TxOled { + public: + TxOled(void); + void init(volatile RadioState_t *radioState); + void page(int page); + private: + volatile RadioState_t *_radioState; + Adafruit_SSD1306 _display; + void pageInit(void); +}; + +#endif \ No newline at end of file