The New York Times RSS feed of World news


-----------lcd_display.service------------------------------------------
[Unit]
Description=run lcd display info updates
After=multi-user.target
Requires=network.target

[Service]
ExecStart=/usr/local/bin/aqi.sh
Restart=on-failure
RestartSec=60

[Install]
WantedBy=multi-user.target


---------read_rss.c-----------------------------------------------------

#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <wiringPi.h>
#include <lcd.h>

char line[8][20];
int numoflines;

void cutString(char *strptr) {

int strLen, i;

        numoflines = 0;
        strLen=strlen(strptr);
        while (strLen > 20) {
                i = 19;
                while ((strptr[i] != ' ') && (strptr[i] != '-')) {
                        i--;
                        if (i < 0) {
                                i=19;
                                break;
                        }
                }
                strptr[i] = '\0';
                strcpy(line[numoflines],strptr);
                strcpy(strptr,&strptr[i+1]);
                numoflines++;
                strLen = strlen(strptr);
        } //while
        strcpy(line[numoflines],strptr);
//        printf("%s\n", strptr);

}

int main(int argc, char *argv[]) {

FILE *fp;
static int lcdHandle;
char myString[160];
char *ptr;
int row=0;

        if (argc != 2) {
                return 1;
        }

        wiringPiSetup () ;

        lcdHandle = lcdInit (4, 20, 8, 11,10, 0,1,2,3,4,5,6,7) ;
        if (lcdHandle < 0)
        {
                fprintf (stderr,"lcdInit failed\n") ;
                return -1 ;
        }

        fp = fopen(argv[1], "r");

        while(fgets(myString, 160, fp)) {
                if ((ptr=strchr(myString,'\n')) != NULL) {
                        *(ptr)='.';
                }
                cutString(myString);
                row = 0;
                lcdClear(lcdHandle);
                for (int i=0; i < numoflines+1; i++) {
                        if (i == 4) {
                                row=0;
                                sleep(10);
                                lcdClear(lcdHandle);
                        }
                        lcdPosition (lcdHandle, 0, row) ; lcdPuts (lcdHandle, line[i]) ;
                        // printf(line[i]);
                        row++;
                }
                row = (row * 2) + 3;
                sleep(row);
        }

        fclose(fp);
        lcdClear(lcdHandle);


return 0;
}