Initial Commit

This commit is contained in:
Tyler Perkins 2021-08-23 14:39:09 -04:00
commit e85f0730a5
7 changed files with 353 additions and 0 deletions

12
.gitignore vendored Normal file
View File

@ -0,0 +1,12 @@
#ignore all .o files
src/**/*.o
#ignore all swp files
**/*.swp
#ignore all executables, but still keep the bin folder
bin/*
!bin/.gitkeep
#ignore config file
src/config.hpp

74
Makefile Normal file
View File

@ -0,0 +1,74 @@
###############################################################################
# Tyler Perkins
# 7-21-21
# Makefile
#
CC = g++
FLAGS = -pipe
CFLAGS = -Wall
CFLAGS += -Ofast
CFLAGS += -std=c++17
#CFLAGS += -g
#CFLAGS += -pg
#required for rss-cli
LIBRARIES = -lcurl
#required for sdl2
LIBRARIES += `pkg-config --cflags --libs sdl2`
LIBRARIES += `sdl2-config --libs --cflags` -lSDL2_image -lSDL2_ttf
SRC = $(shell find ./src -name '*.cpp')
OBJ = $(subst .cpp,.o,$(SRC))
BIN = ./bin
PREFIX = /usr/local
MANPREFIX = $(PREFIX)/share/man
DATA = /usr/share/dashboard
DATA_IMG = $(DATA)/img
DATA_FONT = $(DATA)/font
TARGET = dashboard.out
MAKEFLAGS += --jobs=4
DEFINITIONS = -DDATA='"$(DATA)"'
DEFINITIONS += -DDATA_IMG='"$(DATA_IMG)"'
DEFINITIONS += -DDATA_FONT='"$(DATA_FONT)"'
all : $(OBJ)
@echo LD $@
@$(CC) $(FLAGS) $(CFLAGS) -o $(BIN)/$(TARGET) $(OBJ) $(LIBRARIES)
.cpp.o :
@echo CC $<
@$(CC) $(FLAGS) $(CFLAGS) $(LIBRARIES) $(DEFINITIONS) -c $< -o $@
src/config.hpp :
cp src/config.def.hpp src/config.hpp
$(OBJ): src/config.hpp
install : all
mkdir -p $(PREFIX)/bin
cp -f $(BIN)/$(TARGET) $(PREFIX)/bin
chmod 755 $(PREFIX)/bin/$(TARGET)
#install resources
mkdir -p $(DATA) $(DATA_IMG) $(DATA_FONT)
cp -fr ./img $(DATA)
cp -fr ./font $(DATA)
chmod -R 745 $(DATA)
uninstall :
rm -rf $(PREFIX)/bin/$(TARGET)
rm -rf $(DATA)
clean :
find . -type f -name '*.o' -delete
rm -rf $(BIN)/*
clean-config :
rm -rf src/config.hpp

62
README.md Normal file
View File

@ -0,0 +1,62 @@
dashboard
=========
My dashboard, for my house. Display RSS feeds and other custom bits of info via
html. This isnt pretty, its just meant to work
Features/TODO
=============
- Write straight to framebuffer (sdl2)
- Display Weather rss feed
- Display camera feed
- Display who is home
- Display network speed
- Display plex currently playing
Depends on
==========
- sdl2
- stdlib
optional dependencies
---------------------
- rapidxml
- libcurl
Building sdl2 on rpi
--------------------
Run in this order
```
sudo apt-get install libdrm-dev libgdm-dev
```
Next downlad the SDL source tarball
```
cd sdl-src
./configure --enable-video-kmsdrm
make -j4
sudo make install
```
compile the test.cpp file provided in ./tests . There should be output on the
screen as flashing. Feel free to change the desired graphics driver in the
raspberry pi config
Usage
=====
To compile:
`make all`
To install:
`make install`
To uninstall:
`make uninstall`

93
src/config.def.hpp Normal file
View File

@ -0,0 +1,93 @@
///////////////////////////////////////////////////////////////////////////////
// Tyler Perkins
// 8-23-21
// Configuration file
//
#pragma once
#include <stdint.h>
#include <SDL2/SDL_image.h>
//SCREEN_{WIDTH, HEIGHT}
// Width and height of the screen/window
constexpr int SCREEN_WIDTH = 1920;
constexpr int SCREEN_HEIHGT = 1080;
// MAX_FRAMERATE
// The aprox framerate at runtime
constexpr int MAX_FRAMERATE = 60;
// WINDOW_TITLE
// Title of the default window. Does not matter if not using X11
constexpr char WINDOW_TITLE[] = "Dashboard";
// BOARD_{RED, GREEN, BLUE}
// Default color used
constexpr uint8_t BOARD_RED = 0xFF;
constexpr uint8_t BOARD_GREEN = 0xFF;
constexpr uint8_t BOARD_BLUE = 0xFF;
// SDL_FLAGS
// SDL init() flags
constexpr uint32_t SDL_FLAGS = 0
| SDL_INIT_VIDEO
//| SDL_INIT_AUDIO
//| SDL_INIT_TIMER
//| SDL_INIT_EVENTS
;
// SDL_WINDOW_FLAGS
// SDL init window flags
constexpr uint32_t SDL_WINDOW_FLAGS = 0
//| SDL_WINDOW_FULLSCREEN
| SDL_WINDOW_FULLSCREEN_DESKTOP
| SDL_WINDOW_SHOWN
// | SDL_WINDOW_HIDDEN
| SDL_WINDOW_OPENGL
//| SDL_WINDOW_VULKAN
//| SDL_WINDOW_METAL
| SDL_WINDOW_BORDERLESS
//| SDL_WINDOW_RESIZEABLE
//| SDL_WINDOW_MINIMIZED
//| SDL_WINDOW_MAXIMIZED
;
// SDL_SHOW_CURSOR
// Toggle if the cursor is shown on screen
constexpr int SDL_SHOW_CURSOR = 0
| SDL_ENABLE
// | SDL_DISABLE
;
// IMG_FLAGS
// Enable support for different image formats
constexpr int IMG_FLAGS = 0
| IMG_INIT_JPG
| IMG_INIT_PNG
//| IMG_INIT_TIF
;
// DATA_DIR
// Where all resources will be
// Keep this as DATA to use the install dir set in the makefile
constexpr char DATA_DIR[] = DATA;
// IMAGE_DIR
// Where all images will be
// Keep this as DATA_IMG to use img dir set in the makefile
constexpr char IMAGE_DIR[] = DATA_IMG;
// FONT_DIR
// Where all fonts will be
// Keep this as DATA_FONT to use font dir set in the makefile
constexpr char FONT_DIR[] = DATA_FONT;
// IMAGE_LOCATIONS
// Locations of all static images used
static const char* IMAGE_LOCATIONS[] = {
};

15
src/main.cpp Normal file
View File

@ -0,0 +1,15 @@
///////////////////////////////////////////////////////////////////////////////
// Tyler Perkins
// 8-23-21
// Entry point
//
#include "config.hpp"
int main(int argc, char** argv){
return 0;
}

2
tests/Makefile Normal file
View File

@ -0,0 +1,2 @@
all :
g++ `pkg-config --cflags --libs sdl2` *.cpp

View File

@ -0,0 +1,95 @@
#include <SDL.h>
#include <iostream>
#include <vector>
int main( int argc, char** argv )
{
SDL_Init( 0 );
std::cout << "Testing video drivers..." << '\n';
std::vector< bool > drivers( SDL_GetNumVideoDrivers() );
for( int i = 0; i < drivers.size(); ++i )
{
drivers[ i ] = ( 0 == SDL_VideoInit( SDL_GetVideoDriver( i ) ) );
SDL_VideoQuit();
}
std::cout << "SDL_VIDEODRIVER available:";
for( int i = 0; i < drivers.size(); ++i )
{
std::cout << " " << SDL_GetVideoDriver( i );
}
std::cout << '\n';
std::cout << "SDL_VIDEODRIVER usable :";
for( int i = 0; i < drivers.size(); ++i )
{
if( !drivers[ i ] ) continue;
std::cout << " " << SDL_GetVideoDriver( i );
}
std::cout << '\n';
if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
std::cerr << "SDL_Init(): " << SDL_GetError() << '\n';
return EXIT_FAILURE;
}
std::cout << "SDL_VIDEODRIVER selected : " << SDL_GetCurrentVideoDriver() << '\n';
SDL_Window* window = SDL_CreateWindow
(
"SDL2",
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
640, 480,
SDL_WINDOW_SHOWN
);
if( nullptr == window )
{
std::cerr << "SDL_CreateWindow(): " << SDL_GetError() << '\n';
return EXIT_FAILURE;
}
std::cout << "SDL_RENDER_DRIVER available:";
for( int i = 0; i < SDL_GetNumRenderDrivers(); ++i )
{
SDL_RendererInfo info;
SDL_GetRenderDriverInfo( i, &info );
std::cout << " " << info.name;
}
std::cout << '\n';
SDL_Renderer* renderer = SDL_CreateRenderer( window, -1, SDL_RENDERER_ACCELERATED );
if( nullptr == renderer )
{
std::cerr << "SDL_CreateRenderer(): " << SDL_GetError() << '\n';
return EXIT_FAILURE;
}
SDL_RendererInfo info;
SDL_GetRendererInfo( renderer, &info );
std::cout << "SDL_RENDER_DRIVER selected : " << info.name << '\n';
bool running = true;
unsigned char i = 0;
while( running )
{
SDL_Event ev;
while( SDL_PollEvent( &ev ) )
{
if( ( ev.type == SDL_QUIT ) ||
( ev.type == SDL_KEYDOWN && ev.key.keysym.sym == SDLK_ESCAPE ) )
{
running = false;
}
}
SDL_SetRenderDrawColor( renderer, i, i, i, SDL_ALPHA_OPAQUE );
SDL_RenderClear( renderer );
SDL_RenderPresent( renderer );
i++;
}
SDL_DestroyRenderer( renderer );
SDL_DestroyWindow( window );
SDL_Quit();
return 0;
}