Commit d6f7ef59 authored by 42loop's avatar 42loop

Merge branch '42loop-master-patch-20020' into 'master'

Update mirror.c

See merge request !1
parents 241b3913 bb96f768
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <time.h>
#include <stdbool.h>
#include <unistd.h>
#include <wchar.h>
#include <locale.h>
#include <math.h>
#include <termios.h>
#include <pthread.h>
#include <wiringPi.h>
#include <wiringPiSPI.h>
#include <mcp3004.h>
#include <linux/input.h>
#include <bcm_host.h>
#include "VG/openvg.h"
#include "VG/vgu.h"
#include "shapes.h"
#include "digital_signage.h"
#define csPin 0
#define sclkPin 1
#define mosiPin 2
#define misoPin 3
#define CUR_SIZ 16
#define DIAL 1
#define VSLIDER 2
#define HSLIDER 3
#define CHECKBOX 4
#define BUTTON 5
#define AREA 6
#define LAREA 7
#define GREEN 0
#define ORANGE 1
#define GREY 2
#define RED 3
#define NONE 4
int count=12;
int seconds=3;
typedef struct
{
int x;
int y;
} point_t;
point_t mp;
point_t handle;
typedef struct
{
int x;
int y;
int w;
int h;
//int isactive;
//bool is_on;
} rectangle_t;
// visual controls structure:
typedef struct
{
char name[30];
int ctrltype;
rectangle_t coords;
int id;
bool isactive;
int color;
float value;
int r;
bool visible;
VGPath path;
int groupid;
} control_t;
// Mouse state structure
typedef struct {
int fd;
struct input_event ev;
VGfloat x, y;
int left, middle, right;
int max_x, max_y;
} mouse_t;
// BEGIN data structs
struct NEWS_TICKER nt = {
.pos_x = 220,
.pos_y = 20,
.screen_width = 400,
.font = &SansTypeface,
.font_size = 20,
.scroll_speed = 3, // 3 is the best balance between smoothness and readability
.fade_speed = 0.05,
.display_time = 4.0,
.cur_pos_x = 0,
.cur_msg_index = 0,
.fades_in = true,
.fades_out = false,
.scrolls = true,
.current_alpha = 0.5,
.msg_count = 6,
.content = {
L"Der Wahnsinn ist eine Reise zur Hoelle.",
L"Das Gehirn erkrankt und schwankt in immer neue Dimensionen, da, wo die boesen Maechte wohnen" ,
L"There is class warfare, all right, but it is my class, the rich class, that is making war, and we are winning.",
L"Krieg ist Frieden",
L"Freiheit ist Sklaverei",
L"Unwissenheit ist Staerke"
}
};
//dispmanx for additional layers, eg backdrop
DISPMANX_DISPLAY_HANDLE_T display;
DISPMANX_UPDATE_HANDLE_T update;
DISPMANX_RESOURCE_HANDLE_T resource;
DISPMANX_ELEMENT_HANDLE_T element;
VC_RECT_T dst_rect, src_rect;
VGImage heart;
point_t lastmouse;
mouse_t mouse; // global mouse state
int left_count = 0;
int quitState = 0;
bool mousechanged=false;
bool isresizerx=false;
bool isresizery=false;
int bcount=0;
control_t controls[100];
int currentactive=-1;
int currentover=-1;
bool doexit=false;
bool global_hide=false;
bool blank_bg=true;
int bg_layer=3;
char ltype[50];
char lcol[10];
char lvis[10];
int adcval[8];
int adcctrlid[8];
int adc_hist[8][10];
int adc_hist_index[8];
static void blank_background(int layer,bool enable)
{
// int ret;
if (enable)
{
update = vc_dispmanx_update_start(0);
element = vc_dispmanx_element_add(update, display, layer, &dst_rect, resource, &src_rect,
DISPMANX_PROTECTION_NONE, NULL, NULL, DISPMANX_NO_ROTATE); //DISPMANX_STEREOSCOPIC_MONO );
/*ret =*/ vc_dispmanx_update_submit_sync( update );
}
else
{
update = vc_dispmanx_update_start(0);
/*ret=*/vc_dispmanx_element_remove( update, element );
/*ret=*/vc_dispmanx_update_submit_sync( update );
}
}
// BEGIN non-blocking and utility functions
void changemode(int dir) {
static struct termios oldt, newt;
if (dir == 1) {
tcgetattr( STDIN_FILENO, &oldt);
newt = oldt;
newt.c_lflag &= ~( ICANON | ECHO );
tcsetattr( STDIN_FILENO, TCSANOW, &newt);
} else {
tcsetattr( STDIN_FILENO, TCSANOW, &oldt);
}
}
void *updaterThread(void *arg) {
//printf("key thread running\n");
while(1) {
sleep(1);
count+=1;
}
return 0;
}
double clamp(double d, double min, double max) {
const double t = d < min ? min : d;
return t > max ? max : t;
}
// END non-blocking and utility functions
// BEGIN common functions
double Fade(bool fades_in, bool fades_out, double current_alpha, double fade_speed) {
if (fades_in && current_alpha <= 1) {
return clamp(current_alpha + fade_speed, 0.0, 1.0);
} else if (fades_out && current_alpha >= 0) {
return clamp(current_alpha - fade_speed, 0.0, 1.0);
}
return 1.0;
}
// END common functions
// BEGIN newsticker specific functions
VGfloat MeasureCurText(struct NEWS_TICKER *nt) {
return WTextWidth(nt->content[nt->cur_msg_index], *nt->font, nt->font_size);
}
//thread for updating animated graphics, currently the ticker
int updaterinit() {
pthread_t updateThread;
return pthread_create(&updateThread, NULL, &updaterThread, NULL);
}
void setctrlcolor(int c, bool over, bool on)
{
if (c==NONE)
{Stroke(255, 255, 255, .5);
Fill(0, 0, 0, 0);
}
else if (c==GREEN)
{Stroke(0, 255, 0, 1);
if (!over)
{
if (!on) Fill(0, 255, 0, 0.1);
else Fill(0, 255, 0, 0.4);
}
else Fill(0, 255, 0, 0.4);
}
else if (c==ORANGE)
{Stroke(255, 128, 0, 1);
if (!over)
{ if (!on) Fill(255, 128,0, 0.1);
else Fill(255, 128,0, 0.4);
}
else Fill(255, 128,0, 0.6);
}
else if (c==GREY)
{Stroke(255, 255, 255, 1);
if (!over)
{ if (!on) Fill(192, 192,192, 0.1);
else Fill(192, 192,192, 0.4);
}
else Fill(192, 192,192, 0.6);
}
else if (c==RED)
{Stroke(255, 0, 0, 1);
if (!over)
{ if (!on) Fill(255, 0,0, 0.1);
else Fill(255,0,0, 0.4);
}
else Fill(255,0,0, 0.6);
}
}
///////////////////////////////////////////////////
//stolen from omxplayer.cpp:
//create additional dispmanx context
//and set up a resource 1 by 1
static void create_bglayer()
{
uint32_t vc_image_ptr;
VC_IMAGE_TYPE_T type = VC_IMAGE_RGB565;
uint16_t image = 0x0000; // black
display = vc_dispmanx_display_open(0); //m_config_video.display
// we create a 1x1 black pixel image that is added to display just behind video
resource = vc_dispmanx_resource_create( type, 1 /*width*/, 1 /*height*/, &vc_image_ptr );
vc_dispmanx_rect_set( &dst_rect, 0, 0, 1, 1);
vc_dispmanx_resource_write_data( resource, type, sizeof(image), &image, &dst_rect );
//assert(ret == 0);
vc_dispmanx_rect_set( &src_rect, 0, 0, 1<<16, 1<<16);
vc_dispmanx_rect_set( &dst_rect, 0, 0, 0, 0);
}
///////////////////////////////////////////////////
int main(int argc, char **argv) {
time_t rawtime;
struct tm *timeinfo;
char time_formatted[30];
char gefaellt[30];
char secondsago[30];
char number[4];
char times[4];
char msg[30];
char tempinfo[1035];
int width = 1024;
int height = 600;
int yval1=0;
int yval2=0;
float angle1=0.0f;
int min=0;
int lastmin=0;
int xoff=-30;
int yoff=70;
handle.x=0;
handle.y=0;
char line[255];
printf("hello master\n");
///init openvg
init(&width, &height);
// mcp3004Setup (100, 0); //MCP3004/MCP3008
create_bglayer();
blank_background(bg_layer,true);
updaterinit();
heart=createImageFromJpeg("heart.jpg");
///go!
Start(width, height);
// changemode(1);
//blank_background(12,true);
//main loop:
while (!doexit) {
// doexit=kbhit();
Clear(width, height);
//values for testing
yval1+=2;
if (yval1>360) yval1=0;
yval2+=2;
if (yval2>580) yval2=0;
angle1-=0.01f;
if (angle1<-1.0f) angle1=0.0f;
//checkadc();
float val=0.0;
float outval=0.0;
//time display
time(&rawtime);
timeinfo = localtime(&rawtime);
min=timeinfo->tm_min;
//strings for graphics:
strftime(time_formatted, 30, "%d.%m.%Y @ %H:%M:%S", timeinfo);
strcpy(gefaellt,"Gefaellt");
strcpy(times,"Mal");
sprintf(secondsago,"vor %ld Sekunden", seconds);
sprintf(number,"%ld", count);
float tw=TextWidth(number, SansTypeface, 140);
if (!global_hide)
{
vgSetPixels(0, 150, heart, 0, 0, 150, 150);
Fill(255, 255, 255, 1);
Text(100, 85, gefaellt, SansTypeface, 14);
Text(20, 45, secondsago, SansTypeface, 14);
Text(200, 45, number, SansTypeface, 140);
Text(230+tw, 45, times, SansTypeface, 14);
Text(200, 465, time_formatted, SansTypeface, 14);
for (int i=0;i<5;i++)
{
Fill(255,128,0,.5); Roundrect(1000, 1080-90-i*80,900-yval2,70,10,10);
Fill(0,0,0,1); Text(1000+20, 1080-90-i*80+20, gefaellt, SansTypeface, 18);
}
// WText(nt.cur_pos_x, 20, nt.content[nt.cur_msg_index], *nt.font, nt.font_size);
}
End(width, height);
}
//END of MAIN loop
//printf("gui exiting\n");
changemode(0);
finish();
int c=0;
for (c=0;c<bcount;c++)
{
vgDestroyPath(controls[c].path);
}
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment