Merge pull request #262 from grcasanova/graphics

Graphics
1.2-legacy
Kevin Hester 2020-07-07 15:08:24 -07:00 zatwierdzone przez GitHub
commit c3f7829255
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
12 zmienionych plików z 75 dodań i 57 usunięć

Wyświetl plik

@ -5,7 +5,7 @@
#include "NodeDB.h"
#include "configuration.h"
#include "main.h"
#include "screen.h"
#include "graphics/Screen.h"
#include "sleep.h"
#include "target_specific.h"
#include "timing.h"

15
src/commands.h 100644
Wyświetl plik

@ -0,0 +1,15 @@
/**
* @brief This class enables on the fly software and hardware setup.
* It will contain all command messages to change internal settings.
*/
enum class Cmd {
INVALID,
SET_ON,
SET_OFF,
ON_PRESS,
START_BLUETOOTH_PIN_SCREEN,
STOP_BLUETOOTH_PIN_SCREEN,
STOP_BOOT_SCREEN,
PRINT,
};

Wyświetl plik

@ -26,25 +26,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "MeshService.h"
#include "NodeDB.h"
#include "configuration.h"
#include "fonts.h"
#include "images.h"
#include "graphics/images.h"
#include "main.h"
#include "mesh-pb-constants.h"
#include "screen.h"
#include "Screen.h"
#include "utils.h"
#include "configs.h"
#define FONT_HEIGHT 14 // actually 13 for "ariel 10" but want a little extra space
#define FONT_HEIGHT_16 (ArialMT_Plain_16[1] + 1)
// This means the *visible* area (sh1106 can address 132, but shows 128 for example)
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define TRANSITION_FRAMERATE 30 // fps
#define IDLE_FRAMERATE 1 // in fps
#define COMPASS_DIAM 44
using namespace meshtastic; /** @todo remove */
#define NUM_EXTRA_FRAMES 2 // text message and debug frame
namespace meshtastic
namespace graphics
{
// A text message frame + debug frame + all the node infos
@ -57,8 +48,6 @@ uint8_t imgSatellite[8] = { 0x70, 0x71, 0x22, 0xFA, 0xFA, 0x22, 0x71, 0x70 };
uint32_t dopThresholds[5] = { 2000, 1000, 500, 200, 100 };
// if defined a pixel will blink to show redraws
// #define SHOW_REDRAWS
#ifdef SHOW_REDRAWS
static bool heartbeat = false;
#endif
@ -629,7 +618,7 @@ void Screen::doTask()
// Process incoming commands.
for (;;) {
CmdItem cmd;
ScreenCmd cmd;
if (!cmdQueue.dequeue(&cmd, 0)) {
break;
}
@ -821,7 +810,7 @@ void Screen::adjustBrightness()
dispdev.setBrightness(brightness);
}
int Screen::handleStatusUpdate(const Status *arg)
int Screen::handleStatusUpdate(const meshtastic::Status *arg)
{
//DEBUG_MSG("Screen got status update %d\n", arg->getStatusType());
switch(arg->getStatusType())
@ -837,4 +826,4 @@ int Screen::handleStatusUpdate(const Status *arg)
setPeriod(1); // Update the screen right away
return 0;
}
} // namespace meshtastic
} // namespace graphics

Wyświetl plik

@ -14,9 +14,10 @@
#include "TypedQueue.h"
#include "concurrency/LockGuard.h"
#include "power.h"
#include "commands.h"
#include <string>
namespace meshtastic
namespace graphics
{
// Forward declarations
@ -50,18 +51,18 @@ class DebugInfo
concurrency::Lock lock;
};
/// Deals with showing things on the screen of the device.
//
// Other than setup(), this class is thread-safe. All state-changing calls are
// queued and executed when the main loop calls us.
//
// This class is thread-safe (as long as drawFrame is not called multiple times
// simultaneously).
/**
* @brief This class deals with showing things on the screen of the device.
*
* @details Other than setup(), this class is thread-safe as long as drawFrame is not called
* multiple times simultaneously. All state-changing calls are queued and executed
* when the main loop calls us.
*/
class Screen : public concurrency::PeriodicTask
{
CallbackObserver<Screen, const Status *> powerStatusObserver = CallbackObserver<Screen, const Status *>(this, &Screen::handleStatusUpdate);
CallbackObserver<Screen, const Status *> gpsStatusObserver = CallbackObserver<Screen, const Status *>(this, &Screen::handleStatusUpdate);
CallbackObserver<Screen, const Status *> nodeStatusObserver = CallbackObserver<Screen, const Status *>(this, &Screen::handleStatusUpdate);
CallbackObserver<Screen, const meshtastic::Status *> powerStatusObserver = CallbackObserver<Screen, const meshtastic::Status *>(this, &Screen::handleStatusUpdate);
CallbackObserver<Screen, const meshtastic::Status *> gpsStatusObserver = CallbackObserver<Screen, const meshtastic::Status *>(this, &Screen::handleStatusUpdate);
CallbackObserver<Screen, const meshtastic::Status *> nodeStatusObserver = CallbackObserver<Screen, const meshtastic::Status *>(this, &Screen::handleStatusUpdate);
public:
Screen(uint8_t address, int sda = -1, int scl = -1);
@ -81,11 +82,11 @@ class Screen : public concurrency::PeriodicTask
handleSetOn(
false); // We handle off commands immediately, because they might be called because the CPU is shutting down
else
enqueueCmd(CmdItem{.cmd = on ? Cmd::SET_ON : Cmd::SET_OFF});
enqueueCmd(ScreenCmd{.cmd = on ? Cmd::SET_ON : Cmd::SET_OFF});
}
/// Handles a button press.
void onPress() { enqueueCmd(CmdItem{.cmd = Cmd::ON_PRESS}); }
void onPress() { enqueueCmd(ScreenCmd{.cmd = Cmd::ON_PRESS}); }
// Implementation to Adjust Brightness
void adjustBrightness();
@ -97,22 +98,22 @@ class Screen : public concurrency::PeriodicTask
// with the PIN.
void startBluetoothPinScreen(uint32_t pin)
{
CmdItem cmd;
ScreenCmd cmd;
cmd.cmd = Cmd::START_BLUETOOTH_PIN_SCREEN;
cmd.bluetooth_pin = pin;
enqueueCmd(cmd);
}
/// Stops showing the bluetooth PIN screen.
void stopBluetoothPinScreen() { enqueueCmd(CmdItem{.cmd = Cmd::STOP_BLUETOOTH_PIN_SCREEN}); }
void stopBluetoothPinScreen() { enqueueCmd(ScreenCmd{.cmd = Cmd::STOP_BLUETOOTH_PIN_SCREEN}); }
/// Stops showing the boot screen.
void stopBootScreen() { enqueueCmd(CmdItem{.cmd = Cmd::STOP_BOOT_SCREEN}); }
void stopBootScreen() { enqueueCmd(ScreenCmd{.cmd = Cmd::STOP_BOOT_SCREEN}); }
/// Writes a string to the screen.
void print(const char *text)
{
CmdItem cmd;
ScreenCmd cmd;
cmd.cmd = Cmd::PRINT;
// TODO(girts): strdup() here is scary, but we can't use std::string as
// FreeRTOS queue is just dumbly copying memory contents. It would be
@ -168,17 +169,7 @@ class Screen : public concurrency::PeriodicTask
void doTask() final;
private:
enum class Cmd {
INVALID,
SET_ON,
SET_OFF,
ON_PRESS,
START_BLUETOOTH_PIN_SCREEN,
STOP_BLUETOOTH_PIN_SCREEN,
STOP_BOOT_SCREEN,
PRINT,
};
struct CmdItem {
struct ScreenCmd {
Cmd cmd;
union {
uint32_t bluetooth_pin;
@ -187,7 +178,7 @@ class Screen : public concurrency::PeriodicTask
};
/// Enques given command item to be processed by main loop().
bool enqueueCmd(const CmdItem &cmd)
bool enqueueCmd(const ScreenCmd &cmd)
{
if (!useDisplay)
return true; // claim success if our display is not in use
@ -211,7 +202,7 @@ class Screen : public concurrency::PeriodicTask
static void drawDebugInfoTrampoline(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y);
/// Queue of commands to execute in doTask.
TypedQueue<CmdItem> cmdQueue;
TypedQueue<ScreenCmd> cmdQueue;
/// Whether we are using a display
bool useDisplay = false;
/// Whether the display is currently powered
@ -222,7 +213,9 @@ class Screen : public concurrency::PeriodicTask
/// Holds state for debug information
DebugInfo debugInfo;
/// Display device
/** @todo display abstraction */
#ifdef USE_SH1106
SH1106Wire dispdev;
#else
@ -232,4 +225,4 @@ class Screen : public concurrency::PeriodicTask
OLEDDisplayUi ui;
};
} // namespace meshtastic
} // namespace graphics

Wyświetl plik

@ -0,0 +1,17 @@
#pragma once
#include "fonts.h"
#define FONT_HEIGHT 14 // actually 13 for "Arial 10" but want a little extra space
#define FONT_HEIGHT_16 (ArialMT_Plain_16[1] + 1)
// This means the *visible* area (sh1106 can address 132, but shows 128 for example)
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define TRANSITION_FRAMERATE 30 // fps
#define IDLE_FRAMERATE 1 // in fps
#define COMPASS_DIAM 44
// DEBUG
#define NUM_EXTRA_FRAMES 2 // text message and debug frame
// if defined a pixel will blink to show redraws
// #define SHOW_REDRAWS

Wyświetl plik

@ -1,3 +1,5 @@
#pragma once
const uint8_t Custom_ArialMT_Plain_10[] PROGMEM = {
0x0A, // Width: 10
0x0A, // Height: 10

Wyświetl plik

@ -1,3 +1,5 @@
#pragma once
#define SATELLITE_IMAGE_WIDTH 16
#define SATELLITE_IMAGE_HEIGHT 15
const uint8_t SATELLITE_IMAGE[] PROGMEM = {0x00, 0x08, 0x00, 0x1C, 0x00, 0x0E, 0x20, 0x07, 0x70, 0x02,
@ -10,12 +12,12 @@ const uint8_t imgUser[] PROGMEM = { 0x3C, 0x42, 0x99, 0xA5, 0xA5, 0x99
const uint8_t imgPositionEmpty[] PROGMEM = { 0x20, 0x30, 0x28, 0x24, 0x42, 0xFF };
const uint8_t imgPositionSolid[] PROGMEM = { 0x20, 0x30, 0x38, 0x3C, 0x7E, 0xFF };
#include "icon.xbm"
#include "img/icon.xbm"
// We now programmatically draw our compass
#if 0
const
#include "compass.xbm"
#include "img/compass.xbm"
#endif
#if 0

Wyświetl plik

@ -35,7 +35,7 @@
#include "DSRRouter.h"
#include "debug.h"
#include "main.h"
#include "screen.h"
#include "graphics/Screen.h"
#include "sleep.h"
#include "timing.h"
#include <OneButton.h>
@ -55,7 +55,7 @@
#endif
// We always create a screen object, but we only init it if we find the hardware
meshtastic::Screen screen(SSD1306_ADDRESS);
graphics::Screen screen(SSD1306_ADDRESS);
// Global power status
meshtastic::PowerStatus *powerStatus = new meshtastic::PowerStatus();

Wyświetl plik

@ -1,6 +1,6 @@
#pragma once
#include "screen.h"
#include "graphics/Screen.h"
#include "PowerStatus.h"
#include "GPSStatus.h"
#include "NodeStatus.h"
@ -11,7 +11,7 @@ extern bool isCharging;
extern bool isUSBPowered;
// Global Screen singleton.
extern meshtastic::Screen screen;
extern graphics::Screen screen;
//extern Observable<meshtastic::PowerStatus> newPowerStatus; //TODO: move this to main-esp32.cpp somehow or a helper class
//extern meshtastic::PowerStatus *powerStatus;