source: npl/mediabox/lcdproc_edwin/src/server/client_functions.c @ c5c522c

gcc484ntopperl-5.22
Last change on this file since c5c522c was c5c522c, checked in by Edwin Eefting <edwin@datux.nl>, 8 years ago

initial commit, transferred from cleaned syn3 svn tree

  • Property mode set to 100644
File size: 22.3 KB
Line 
1/*
2  client_functions.c
3 
4  This contains definitions for all the functions which clients can run.
5  The functions here are to be called only from parse.c's interpreter.
6 
7  The client's available function set is defined here, as is the syntax
8  for each command.
9 
10*/
11
12
13#include <stdlib.h>
14#include <stdio.h>
15#include <string.h>
16#include <ctype.h>
17
18#include "../shared/debug.h"
19#include "../shared/sockets.h"
20
21#include "drivers/lcd.h"
22
23#include "main.h"
24#include "render.h"
25#include "clients.h"
26#include "parse.h"
27#include "screen.h"
28#include "widget.h"
29#include "client_functions.h"
30
31
32client_function commands[] = {
33   {"test_func", test_func_func },
34   {"hello", hello_func},
35   {"client_set", client_set_func},
36   {"client_add_key", client_add_key_func},
37   {"client_del_key", client_del_key_func},
38   {"screen_add", screen_add_func},
39   {"screen_del", screen_del_func},
40   {"screen_set", screen_set_func},
41   {"widget_add", widget_add_func},
42   {"widget_del", widget_del_func},
43   {"widget_set", widget_set_func},
44   {"menu_add", menu_add_func},
45   {"menu_del", menu_del_func},
46   {"menu_set", menu_set_func},
47   // TODO:  Adhere these to the naming convention?
48   {"menu_item_add", menu_item_add_func},
49   {"menu_item_del", menu_item_del_func},
50   {"menu_item_set", menu_item_set_func},
51   // Misc stuff...
52   {"backlight", backlight_func},
53   {"output", output_func},
54   {NULL, NULL },
55};
56
57
58// TODO:  Maybe more error-checking for "->"'s?
59
60
61///////////////////////////////////////////////////////////////////////////
62// Debugging only..  prints out a list of arguments it receives
63//
64int test_func_func(client *c, int argc, char **argv)
65{
66   int i;
67   char str[256];
68   
69   for(i=0; i<argc; i++)
70   {
71      sprintf(str, "test_func_func:  %i -> %s\n", i, argv[i]);
72      printf(str);
73      sock_send_string(c->sock, str);
74   }
75   return 0;
76}
77
78
79///////////////////////////////////////////////////////////////////////////
80// The client must say "hello" before doing anything else.
81//
82// It returns a string of info about the server to the client
83//
84int hello_func(client *c, int argc, char **argv)
85{
86   char str[256];
87
88   // TODO:  Give *real* info about the server/lcd...
89   
90   debug("Hello!\n");
91
92   sprintf(str,
93           "connect LCDproc %s lcd wid %i hgt %i cellwid %i cellhgt %i\n",
94           version, lcd.wid, lcd.hgt, lcd.cellwid, lcd.cellhgt);
95   sock_send_string(c->sock, str);
96
97   if(c->data)
98      c->data->ack = 1;
99   
100   return 0;
101}
102
103///////////////////////////////////////////////////////////////////////////
104// sets info about the client, such as its name
105//
106int client_set_func(client *c, int argc, char **argv)
107{
108   int i;
109
110   if(!c->data->ack) return 1;
111   
112   for(i=1; i<argc; i++)
113   {
114      // Handle the "name" parameter
115      if(0 == strcmp(argv[i], "name"))
116      {
117         if(argc > i+1)
118         {
119            i++;
120            debug("client_set: name=\"%s\"\n", argv[i]);
121
122            // set the name...
123            if(c->data->name)
124               free(c->data->name);
125            c->data->name = strdup(argv[i]);
126         }
127         else
128         {
129            sock_send_string(c->sock, "huh? name requires a parameter\n");
130         }
131      }
132      else
133      {
134         sock_send_string(c->sock, "huh? invalid parameter\n");
135      }
136   }
137
138   // If there were no parameters...
139   if(argc == 1)
140      sock_send_string(c->sock, "huh? What do you want to set?\n");
141   
142   return 0;
143}
144
145///////////////////////////////////////////////////////////////////////////
146// Tells the server the client would like to accept keypresses
147// of a particular type
148//
149int client_add_key_func(client *c, int argc, char **argv)
150{
151   
152   
153   if(!c->data->ack) return 1;
154
155   sock_send_string(c->sock, "huh?  Not implemented yet.\n");
156   
157   return 0;
158}
159
160///////////////////////////////////////////////////////////////////////////
161// Tells the server the client would NOT like to accept keypresses
162// of a particular type
163//
164int client_del_key_func(client *c, int argc, char **argv)
165{
166   
167   
168   if(!c->data->ack) return 1;
169   
170   sock_send_string(c->sock, "huh?  Not implemented yet.\n");
171   
172   return 0;
173}
174
175///////////////////////////////////////////////////////////////////////////
176// Tells the server the client has another screen to offer
177//
178int screen_add_func(client *c, int argc, char **argv)
179{
180   int err=0;
181   
182   if(!c->data->ack) return 1;
183   
184   if(argc < 2)
185   {
186      sock_send_string(c->sock, "huh?  Specify a screen #id\n");
187      return 0;
188   }
189   if(argc > 2)
190   {
191      sock_send_string(c->sock, "huh?  Too many parameters...\n");
192      return 0;
193   }
194
195
196   debug("screen_add: Adding screen %s\n", argv[1]);
197   err = screen_add(c, argv[1]);
198   if(err < 0)
199      fprintf(stderr, "screen_add_func:  Error adding screen\n");
200   if(err > 0)
201      sock_send_string(c->sock,
202                       "huh? You already have a screen with that id#\n");
203   
204   return 0;
205}
206
207///////////////////////////////////////////////////////////////////////////
208// Client requests that the server forget about a screen
209//
210int screen_del_func(client *c, int argc, char **argv)
211{
212   int err=0;
213   
214   if(!c->data->ack) return 1;
215   
216   if(argc < 2)
217   {
218      sock_send_string(c->sock, "huh?  Specify a screen #id\n");
219      return 0;
220   }
221   if(argc > 2)
222   {
223      sock_send_string(c->sock, "huh?  Too many parameters...\n");
224      return 0;
225   }
226
227
228   debug("screen_del: Deleting screen %s\n", argv[1]);
229   err = screen_remove(c, argv[1]);
230   if(err < 0)
231      fprintf(stderr, "screen_del_func:  Error removing screen\n");
232   if(err > 0)
233      sock_send_string(c->sock,
234                       "huh? You don't have a screen with that id#\n");
235   
236   return 0;
237}
238
239///////////////////////////////////////////////////////////////////////////
240// Configures info about a particular screen, such as its
241//  name, priority, or duration
242//
243int screen_set_func(client *c, int argc, char **argv)
244{
245   int i;
246
247   int number;
248   char *id;
249   screen *s;
250   
251   if(!c->data->ack) return 1;
252
253   
254   // If there weren't enough parameters...
255   if(argc < 2)
256   {
257      sock_send_string(c->sock, "huh? You must specify a screen id\n");
258      return 0;
259   }
260   
261   if(argc == 2)
262   {
263      sock_send_string(c->sock, "huh? What do you want to set?\n");
264      return 0;
265   }
266   
267
268   id = argv[1];
269   s = screen_find(c, id);
270   if(!s)
271   {
272      sock_send_string(c->sock, "huh? Invalid screen id\n");
273      return 0;
274   }
275   
276   // Handle the rest of the parameters
277   for(i=2; i<argc; i++)
278   {
279      // Handle the "name" parameter
280      if(0 == strcmp(argv[i], "name"))
281      {
282         if(argc > i+1)
283         {
284            i++;
285            debug("screen_set: name=\"%s\"\n", argv[i]);
286
287            // set the name...
288            if(s->name)
289               free(s->name);
290            s->name = strdup(argv[i]);
291         }
292         else
293         {
294            sock_send_string(c->sock, "huh? name requires a parameter\n");
295         }
296      }
297      // Handle the "priority" parameter
298      else if(0 == strcmp(argv[i], "priority"))
299      {
300         if(argc > i+1)
301         {
302            i++;
303            debug("screen_set: priority=\"%s\"\n", argv[i]);
304
305            // set the priority...
306            number = atoi(argv[i]);
307            if(number > 0)
308               s->priority = number;
309            screenlist_next();
310         }
311         else
312         {
313            sock_send_string(c->sock, "huh? priority requires a parameter\n");
314         }
315      }
316      // Handle the "duration" parameter
317      else if(0 == strcmp(argv[i], "duration"))
318      {
319         if(argc > i+1)
320         {
321            i++;
322            debug("screen_set: duration=\"%s\"\n", argv[i]);
323
324            // set the duration...
325            number = atoi(argv[i]);
326            if(number > 0)
327               s->duration = number;
328         }
329         else
330         {
331            sock_send_string(c->sock, "huh? duration requires a parameter\n");
332         }
333      }
334      // Handle the "wid" parameter
335      else if(0 == strcmp(argv[i], "wid"))
336      {
337         if(argc > i+1)
338         {
339            i++;
340            debug("screen_set: wid=\"%s\"\n", argv[i]);
341
342            // set the duration...
343            number = atoi(argv[i]);
344            if(number > 0)
345               s->wid = number;
346         }
347         else
348         {
349            sock_send_string(c->sock, "huh? wid requires a parameter\n");
350         }
351      }
352      // Handle the "hgt" parameter
353      else if(0 == strcmp(argv[i], "hgt"))
354      {
355         if(argc > i+1)
356         {
357            i++;
358            debug("screen_set: hgt=\"%s\"\n", argv[i]);
359
360            // set the duration...
361            number = atoi(argv[i]);
362            if(number > 0)
363               s->hgt = number;
364         }
365         else
366         {
367            sock_send_string(c->sock, "huh? hgt requires a parameter\n");
368         }
369      }
370      else
371      {
372         sock_send_string(c->sock, "huh? invalid parameter\n");
373      }
374   } // done checking argv
375
376   return 0;
377}
378
379///////////////////////////////////////////////////////////////////////////
380// Adds a widget to a screen, but doesn't give it a value
381//
382int widget_add_func(client *c, int argc, char **argv)
383{
384   int err;
385
386   char *type;
387   char *sid;
388   char *wid;
389   char *in = NULL;
390   screen *s;
391
392   
393   if(!c->data->ack) return 1;
394
395   
396   // If there weren't enough parameters...
397   if(argc < 2)
398   {
399      sock_send_string(c->sock, "huh? You must specify a screen id\n");
400      return 0;
401   }
402   if(argc < 3)
403   {
404      sock_send_string(c->sock, "huh? You must specify a widget id\n");
405      return 0;
406   }
407   if(argc < 4)
408   {
409      sock_send_string(c->sock, "huh? You must specify a widget type\n");
410      return 0;
411   }
412   if(argc > 6)
413   {
414      sock_send_string(c->sock, "huh? Too many parameters\n");
415      return 0;
416   }
417   
418
419   sid = argv[1];
420   wid = argv[2];
421
422   s = screen_find(c, sid);
423   if(!s)
424   {
425      sock_send_string(c->sock, "huh? Invalid screen id\n");
426      return 0;
427   }
428   
429   type = argv[3];
430
431   // Check for additional flags...
432   if(argc > 4)
433   {
434      // Handle the "-in" flag to place widgets in a container...
435      if(0 == strcmp(argv[4], "-in"))
436      {
437         if(argc < 6)
438         {
439            sock_send_string(c->sock,
440                             "huh? Specify a frame to place widget in\n");
441            return 0;
442         }
443         in = argv[5];
444      }
445   }
446
447   
448   // Add the widget and set its type...
449   err = widget_add(s, wid, type, in, c->sock);
450   if(err<0)
451      fprintf(stderr, "widget_add_func:  Error adding widget\n");
452   
453   return 0;
454}
455
456///////////////////////////////////////////////////////////////////////////
457// Removes a widget from a screen, and forgets about it
458//
459int widget_del_func(client *c, int argc, char **argv)
460{
461   int err=0;
462
463   char *sid;
464   char *wid;
465   screen *s;
466   
467   if(!c->data->ack) return 1;
468   
469   // Check the number of parameters...
470   if(argc < 2)
471   {
472      sock_send_string(c->sock, "huh?  Specify a screen #id\n");
473      return 0;
474   }
475   if(argc < 3)
476   {
477      sock_send_string(c->sock, "huh?  Specify a widget #id\n");
478      return 0;
479   }
480   if(argc > 3)
481   {
482      sock_send_string(c->sock, "huh?  Too many parameters...\n");
483      return 0;
484   }
485
486
487   sid = argv[1];
488   wid = argv[2];
489   
490   debug("screen_del: Deleting widget %s.%s\n", sid, wid);
491
492   s = screen_find(c, sid);
493   if(!s)
494   {
495      sock_send_string(c->sock, "huh? Invalid screen id\n");
496   }
497   
498   err = widget_remove(s, wid, c->sock);
499   if(err < 0)
500      fprintf(stderr, "widget_del_func:  Error removing widget\n");
501   
502   return 0;
503}
504
505///////////////////////////////////////////////////////////////////////////
506// Configures information about a widget, such as its size, shape,
507//  contents, position, speed, etc...
508//
509// Ack!  This is long!
510int widget_set_func(client *c, int argc, char **argv)
511{
512   int i;
513
514   int x, y;
515   int left, top, right, bottom;
516   int length, direction;
517   int width, height;
518   int speed;
519   char *sid, *wid;
520   screen *s;
521   widget *w;
522   
523   if(!c->data->ack) return 1;
524
525   
526   // If there weren't enough parameters...
527   if(argc < 2)
528   {
529      sock_send_string(c->sock, "huh? You must specify a screen id\n");
530      return 0;
531   }
532   if(argc < 3)
533   {
534      sock_send_string(c->sock, "huh? You must specify a widget id\n");
535      return 0;
536   }
537   if(argc < 4)
538   {
539      sock_send_string(c->sock, "huh? You must send some widget data\n");
540      return 0;
541   }
542   
543   
544   sid = argv[1];
545   wid = argv[2];
546   s = screen_find(c, sid);
547   if(!s)
548   {
549      sock_send_string(c->sock, "huh? Invalid screen id\n");
550      return 0;
551   }
552   w = widget_find(s, wid);
553   if(!w)
554   {
555      sock_send_string(c->sock, "huh? Invalid widget id\n");
556      // Client Debugging...
557      {
558         int i;
559         fprintf(stderr, "huh? Invalid widget id (%s)\n", wid);
560         for(i=0; i<argc; i++)
561           fprintf(stderr, "%s ", argv[i]);
562         fprintf(stderr, "\n");
563      }
564      return 0;
565   }
566
567
568   // FIXME?  Shouldn't this be handled in widget.c?
569   i = 3;
570   switch(w->type)
571   {
572      case WID_STRING:  // String takes "x y text"
573         if((argc != i+3) && (argc != i+2))
574            sock_send_string(c->sock, "huh? Wrong number of arguments\n");
575         else
576         {
577            if((!isdigit(argv[i][0]))  ||  (!isdigit(argv[i+1][0])))
578            {
579               sock_send_string(c->sock, "huh? Invalid coordinates\n");
580            }
581            else  // Set all the data...
582            {
583               x = atoi(argv[i]);
584               y = atoi(argv[i+1]);
585               w->x = x;
586               w->y = y;
587               if(w->text)
588                  free(w->text);
589               //empty/no string is allowed now!
590               if (argc == i+3)
591                    w->text = strdup(argv[i+2]);
592               else
593                    w->text = strdup("");
594               
595               if(!w->text)
596               {
597                  fprintf(stderr,
598                          "widget_set_func: Error allocating string\n");
599                  return -1;
600               }
601               debug("Widget %s set to %s\n", wid, w->text);
602            }
603         }
604         break;
605      case WID_HBAR:  // Hbar takes "x y length"
606         if(argc != i+3)
607            sock_send_string(c->sock, "huh? Wrong number of arguments\n");
608         else
609         {
610            if((!isdigit(argv[i][0]))  ||  (!isdigit(argv[i+1][0])))
611            {
612               sock_send_string(c->sock, "huh? Invalid coordinates\n");
613            }
614            else
615            {
616               x = atoi(argv[i]);
617               y = atoi(argv[i+1]);
618               length = atoi(argv[i+2]);
619               w->x = x;
620               w->y = y;
621               w->length = length;
622            }
623            debug("Widget %s set to %i\n", wid, w->length);
624         }
625         break;
626      case WID_VBAR:  // Vbar takes "x y length"
627         if(argc != i+3)
628            sock_send_string(c->sock, "huh? Wrong number of arguments\n");
629         else
630         {
631            if((!isdigit(argv[i][0]))  ||  (!isdigit(argv[i+1][0])))
632            {
633               sock_send_string(c->sock, "huh? Invalid coordinates\n");
634            }
635            else
636            {
637               x = atoi(argv[i]);
638               y = atoi(argv[i+1]);
639               length = atoi(argv[i+2]);
640               w->x = x;
641               w->y = y;
642               w->length = length;
643            }
644            debug("Widget %s set to %i\n", wid, w->length);
645         }
646         break;
647      case WID_ICON:  // Icon takes "x y binary_data"
648         if(argc != i+3)
649            sock_send_string(c->sock, "huh? Wrong number of arguments\n");
650         else
651         {
652            if((!isdigit(argv[i][0]))  ||  (!isdigit(argv[i+1][0])))
653            {
654               sock_send_string(c->sock, "huh? Invalid coordinates\n");
655            }
656            else
657            {
658               x = atoi(argv[i]);
659               y = atoi(argv[i+1]);
660               w->x = x;
661               w->y = y;
662               // TODO:  Parse binary data and copy it to widget's data...
663            }
664         }
665         sock_send_string(c->sock, "huh? Widget type not yet implemented\n");
666         break;
667      case WID_TITLE:  // title takes "text"
668         if(argc != i+1)
669            sock_send_string(c->sock, "huh? Wrong number of arguments\n");
670         else
671         {
672            if(w->text)
673               free(w->text);
674            w->text = strdup(argv[i]);
675            if(!w->text)
676            {
677               fprintf(stderr,
678                       "widget_set_func: Error allocating string\n");
679               return -1;
680            }
681            debug("Widget %s set to %s\n", wid, w->text);
682         }
683         break;
684      case WID_SCROLLER:  // Scroller takes "left top right bottom direction speed text"
685         if(argc != i+7) {
686            sock_send_string(c->sock, "huh? Wrong number of arguments\n");
687         }
688         else
689         {
690            if((!isdigit(argv[i][0]))  ||
691               (!isdigit(argv[i+1][0])) ||
692               (!isdigit(argv[i+2][0])) ||
693               (!isdigit(argv[i+3][0])))
694            {
695               sock_send_string(c->sock, "huh? Invalid coordinates\n");
696            }
697            else
698            {
699               left = atoi(argv[i]);
700               //debug("left: %d\n",left);
701               top = atoi(argv[i+1]);
702               //debug("top: %d\n",top);
703               right = atoi(argv[i+2]);
704               //debug("right: %d\n",right);
705               bottom = atoi(argv[i+3]);
706               //debug("bottom: %d\n",bottom);
707               direction = (int)(argv[i+4][0]);
708               //debug("dir: %c\n",(char)direction);
709               speed = atoi(argv[i+5]);
710               //debug("speed: %d\n",speed);
711               // Direction must be v or h
712               if(((char)direction != 'h')  &&  ((char)direction != 'v'))
713               {
714                  sock_send_string(c->sock, "huh? Invalid direction\n");
715               }
716               else
717               {
718                  w->left = left;
719                  w->top = top;
720                  w->right = right;
721                  w->bottom = bottom;
722                  w->length = direction;
723                  w->speed = speed;
724                  if(w->text)
725                     free(w->text);
726                  w->text = strdup(argv[i+6]);
727                  if(!w->text)
728                  {
729                     fprintf(stderr, "widget_set_func: Error allocating string\n");
730                     return -1;
731                  }
732                  debug("Widget %s set to %s\n", wid, w->text);
733               }
734            }
735         }
736         break;
737      case WID_FRAME:  // Frame takes "left top right bottom wid hgt direction speed"
738         if(argc != i+8) {
739            sock_send_string(c->sock, "huh? Wrong number of arguments\n");
740         }
741         else
742         {
743            if((!isdigit(argv[i][0]))  ||
744               (!isdigit(argv[i+1][0])) ||
745               (!isdigit(argv[i+2][0])) ||
746               (!isdigit(argv[i+3][0])) ||
747               (!isdigit(argv[i+4][0])) ||
748               (!isdigit(argv[i+5][0])))
749            {
750               sock_send_string(c->sock, "huh? Invalid coordinates\n");
751            }
752            else
753            {
754               left = atoi(argv[i]);
755               //debug("left: %d\n",left);
756               top = atoi(argv[i+1]);
757               //debug("top: %d\n",top);
758               right = atoi(argv[i+2]);
759               //debug("right: %d\n",right);
760               bottom = atoi(argv[i+3]);
761               //debug("bottom: %d\n",bottom);
762               width = atoi(argv[i+4]);
763               //debug("right: %d\n",right);
764               height = atoi(argv[i+5]);
765               //debug("bottom: %d\n",bottom);
766               direction = (int)(argv[i+6][0]);
767               //debug("dir: %c\n",(char)direction);
768               speed = atoi(argv[i+7]);
769               //debug("speed: %d\n",speed);
770               // Direction must be v or h
771               if(((char)direction != 'h')  &&  ((char)direction != 'v'))
772               {
773                  sock_send_string(c->sock, "huh? Invalid direction\n");
774               }
775               else
776               {
777                  w->left = left;
778                  w->top = top;
779                  w->right = right;
780                  w->bottom = bottom;
781                  w->wid = width;
782                  w->hgt = height;
783                  w->length = direction;
784                  w->speed = speed;
785                  debug("Widget %s set to (%i,%i)-(%i,%i) %ix%i\n",
786                        wid, left, top, right, bottom, width, height);
787               }
788            }
789         }
790         break;
791      case WID_NUM:  // Num takes "x num"
792         if(argc != i+2)
793            sock_send_string(c->sock, "huh? Wrong number of arguments\n");
794         else
795         {
796            if(!isdigit(argv[i][0]))
797            {
798               sock_send_string(c->sock, "huh? Invalid coordinates\n");
799            } else if(!isdigit(argv[i+1][0]))
800            {
801               sock_send_string(c->sock, "huh? Invalid number\n");
802            } else
803            {
804               x = atoi(argv[i]);
805               y = atoi(argv[i+1]);
806               w->x = x;
807               w->y = y;
808            }
809            debug("Widget %s set to %i\n", wid, w->y);
810         }
811         break;
812      case WID_NONE:
813      default:
814         sock_send_string(c->sock, "huh? Widget has no type\n");
815         break;
816   }
817   
818   return 0;
819}
820
821///////////////////////////////////////////////////////////////////////////
822// Adds a menu to the client; handled by the server...
823//
824int menu_add_func(client *c, int argc, char **argv)
825{
826   
827   
828   if(!c->data->ack) return 1;
829   
830   sock_send_string(c->sock, "huh?  Not implemented yet.\n");
831   
832   return 0;
833}
834
835///////////////////////////////////////////////////////////////////////////
836// Removes a client's menu and all contents from the server
837//
838int menu_del_func(client *c, int argc, char **argv)
839{
840   
841   
842   if(!c->data->ack) return 1;
843   
844   sock_send_string(c->sock, "huh?  Not implemented yet.\n");
845   
846   return 0;
847}
848
849///////////////////////////////////////////////////////////////////////////
850// Sets info about a menu, but not its items
851//
852// For example, should the menu be top-level, or buried somewhere?
853//
854int menu_set_func(client *c, int argc, char **argv)
855{
856   
857   
858   if(!c->data->ack) return 1;
859   
860   sock_send_string(c->sock, "huh?  Not implemented yet.\n");
861   
862   return 0;
863}
864
865///////////////////////////////////////////////////////////////////////////
866// Adds an item to a menu
867//
868int menu_item_add_func(client *c, int argc, char **argv)
869{
870   
871   
872   if(!c->data->ack) return 1;
873   
874   sock_send_string(c->sock, "huh?  Not implemented yet.\n");
875   
876   return 0;
877}
878
879///////////////////////////////////////////////////////////////////////////
880// Deletes an item from a menu
881//
882int menu_item_del_func(client *c, int argc, char **argv)
883{
884   
885   
886   if(!c->data->ack) return 1;
887   
888   sock_send_string(c->sock, "huh?  Not implemented yet.\n");
889   
890   return 0;
891}
892
893///////////////////////////////////////////////////////////////////////////
894// Sets the info about a menu item
895//
896// For example, text displayed, widget type, value, etc...
897//
898int menu_item_set_func(client *c, int argc, char **argv)
899{
900   
901   
902   if(!c->data->ack) return 1;
903   
904   sock_send_string(c->sock, "huh?  Not implemented yet.\n");
905   
906   return 0;
907}
908
909///////////////////////////////////////////////////////////////////////////
910// Toggles the backlight, if enabled.
911//
912int backlight_func(client *c, int argc, char **argv)
913{
914   if(!c->data->ack) return 1;
915   
916   // Check the number of parameters...
917   if(argc < 2)
918   {
919      sock_send_string(c->sock, "huh?  Specify a screen #id\n");
920      return 0;
921   }
922
923   if(argc > 2)
924   {
925      sock_send_string(c->sock, "huh?  Too many parameters...\n");
926      return 0;
927   }
928
929
930   debug("backlight(%s)\n", argv[1]);
931
932
933   switch(backlight)
934   {
935      case BACKLIGHT_OPEN:
936         if(0 == strcmp("on", argv[1]))
937         {
938            backlight_state = BACKLIGHT_ON;
939         }
940         if(0 == strcmp("off", argv[1]))
941         {
942            backlight_state = BACKLIGHT_OFF;
943         }
944         if(0 == strcmp("toggle", argv[1]))
945         {
946            if(backlight_state == BACKLIGHT_ON)
947               backlight_state = BACKLIGHT_OFF;
948            else if(backlight_state == BACKLIGHT_OFF)
949               backlight_state = BACKLIGHT_ON;
950         }
951         if(0 == strcmp("blink", argv[1]))
952         {
953            backlight_state |= BACKLIGHT_BLINK;
954         }
955         if(0 == strcmp("flash", argv[1]))
956         {
957            backlight_state |= BACKLIGHT_FLASH;
958         }
959         break;
960      case BACKLIGHT_VIS:
961         break;
962   }
963   
964   return 0;
965
966}
967
968////////////////////////////////////////////////////////////////////////////
969// Sets the output port on MtxOrb LCDs
970int output_func(client *c, int argc, char **argv)
971{
972   if(argc != 2)
973   {
974      sock_send_string(c->sock, "huh?  Too many parameters...\n");
975   }
976   else
977   {
978      if(0 == strcmp(argv[1], "on"))
979         output_state = 1;
980      else
981         output_state = 0;
982   }
983   return 0;
984}
985
986
987///////////////////////////////////////////////////////////////////////////
988///////////////////////////////////////////////////////////////////////////
989///////////////////////////////////////////////////////////////////////////
990///////////////////////////////////////////////////////////////////////////
991///////////////////////////////////////////////////////////////////////////
992
Note: See TracBrowser for help on using the repository browser.