MIDAS
Loading...
Searching...
No Matches
rpi_led.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <stdint.h>
#include <string.h>
#include <linux/fb.h>
#include <sys/ioctl.h>
#include "midas.h"
Include dependency graph for rpi_led.c:

Go to the source code of this file.

Classes

struct  RPI_LED_INFO
 

Macros

#define FILESIZE   (64 * sizeof(uint16_t))
 

Functions

INT rpi_led_init (HNDLE hkey, void **pinfo)
 
INT rpi_led_exit (RPI_LED_INFO *info)
 
INT rpi_led_set (RPI_LED_INFO *info, INT channel, double value)
 
INT rpi_led_get (RPI_LED_INFO *info, INT channel, float *pvalue)
 
INT rpi_led (INT cmd,...)
 

Macro Definition Documentation

◆ FILESIZE

#define FILESIZE   (64 * sizeof(uint16_t))

Definition at line 37 of file rpi_led.c.

Function Documentation

◆ rpi_led()

INT rpi_led ( INT  cmd,
  ... 
)

Definition at line 143 of file rpi_led.c.

144{
146 HNDLE hKey;
148 float *pvalue;
149 double value;
150 void *info;
151
152 va_start(argptr, cmd);
154
155 switch (cmd) {
156 case CMD_INIT:
158 info = va_arg(argptr, void *);
160 break;
161
162 case CMD_EXIT:
163 info = va_arg(argptr, void *);
165 break;
166
167 case CMD_SET:
168 info = va_arg(argptr, void *);
170 value = va_arg(argptr, double);
172 break;
173
174 case CMD_GET:
175 info = va_arg(argptr, void *);
177 pvalue = va_arg(argptr, float *);
179 break;
180
181 default:
182 break;
183 }
184
185 va_end(argptr);
186
187 return status;
188}
#define FE_SUCCESS
Definition midas.h:717
#define CMD_INIT
Definition midas.h:762
#define CMD_GET
Definition midas.h:787
#define CMD_SET
Definition midas.h:777
#define CMD_EXIT
Definition midas.h:763
void ** info
Definition fesimdaq.cxx:41
INT channel
HNDLE hKey
INT HNDLE
Definition midas.h:132
int INT
Definition midas.h:129
double value[100]
Definition odbhist.cxx:42
DWORD status
Definition odbhist.cxx:39
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition rmidas.h:24
INT rpi_led_init(HNDLE hkey, void **pinfo)
Definition rpi_led.c:44
INT rpi_led_exit(RPI_LED_INFO *info)
Definition rpi_led.c:90
INT rpi_led_set(RPI_LED_INFO *info, INT channel, double value)
Definition rpi_led.c:106
INT rpi_led_get(RPI_LED_INFO *info, INT channel, float *pvalue)
Definition rpi_led.c:124
Here is the call graph for this function:

◆ rpi_led_exit()

INT rpi_led_exit ( RPI_LED_INFO info)

Definition at line 90 of file rpi_led.c.

91{
92 /* un-map and close */
93 if (munmap(info->map, FILESIZE) == -1) {
94 perror("Error un-mmapping the file");
95 }
96 close(info->fbfd);
97
98 /* free local variables */
99 free(info);
100
101 return FE_SUCCESS;
102}
#define FILESIZE
Definition rpi_led.c:37
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rpi_led_get()

INT rpi_led_get ( RPI_LED_INFO info,
INT  channel,
float pvalue 
)

Definition at line 124 of file rpi_led.c.

125{
126 uint16_t r, g, b, rgb;
128
129 /* read value from channel */
130 rgb = info->map[channel];
131 r = (rgb >> 11) & 0x1F;
132 g = (rgb >> 6) & 0x1F;
133 b = (rgb >> 1) & 0x1F;
134
135 col = (r << 16) | (g << 8) | b;
136 *pvalue = (float) col;
137
138 return FE_SUCCESS;
139}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rpi_led_init()

INT rpi_led_init ( HNDLE  hkey,
void **  pinfo 
)

Definition at line 44 of file rpi_led.c.

45{
48
49 /* allocate info structure */
50 info = calloc(1, sizeof(RPI_LED_INFO));
51 *pinfo = info;
52
53 /* open the led frame buffer device */
54 info->fbfd = open("/dev/fb1", O_RDWR);
55 if (info->fbfd == -1) {
56 perror("Error (call to 'open')");
57 exit(EXIT_FAILURE);
58 }
59
60 /* read fixed screen info for the open device */
61 if (ioctl(info->fbfd, FBIOGET_FSCREENINFO, &fix_info) == -1) {
62 perror("Error (call to 'ioctl')");
63 close(info->fbfd);
64 exit(EXIT_FAILURE);
65 }
66
67 /* now check the correct device has been found */
68 if (strcmp(fix_info.id, "RPi-Sense FB") != 0) {
69 printf("Error: RPi-Sense FB not found\n");
70 close(info->fbfd);
71 exit(EXIT_FAILURE);
72 }
73
74 /* map the led frame buffer device into memory */
76 if (info->map == MAP_FAILED) {
77 close(info->fbfd);
78 perror("Error mmapping the file");
79 exit(EXIT_FAILURE);
80 }
81
82 /* clear the led matrix */
83 memset(info->map, 0, FILESIZE);
84
85 return FE_SUCCESS;
86}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rpi_led_set()

INT rpi_led_set ( RPI_LED_INFO info,
INT  channel,
double  value 
)

Definition at line 106 of file rpi_led.c.

107{
108 uint16_t r, g, b, rgb;
110
111 col = (uint32_t)value;
112
113 r = ((col >> 16) & 0xFF) >> 3;
114 g = ((col >> 8) & 0xFF) >> 3;
115 b = ((col >> 0) & 0xFF) >> 3;
116 rgb = (r << 11) | (g << 6) | (b << 1);
117 info->map[channel] = rgb;
118
119 return FE_SUCCESS;
120}
Here is the call graph for this function:
Here is the caller graph for this function: