2018-11-01 13:21:20 +00:00
|
|
|
#include <cc65.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <conio.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#ifdef __APPLE2__
|
|
|
|
#include <apple2_filetype.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "../inc/ip65.h"
|
|
|
|
#include "ifttt.h"
|
|
|
|
|
2018-11-07 19:43:20 +00:00
|
|
|
char key[80 + 1];
|
2018-11-01 13:21:20 +00:00
|
|
|
char text[280 + 1];
|
|
|
|
|
|
|
|
void error_exit(void)
|
|
|
|
{
|
2020-04-15 12:52:59 +00:00
|
|
|
printf("- %s\n", ip65_strerror(ip65_error));
|
2018-11-01 13:21:20 +00:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void confirm_exit(void)
|
|
|
|
{
|
|
|
|
printf("\nPress any key ");
|
|
|
|
cgetc();
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char cols(void)
|
|
|
|
{
|
|
|
|
unsigned char cols, rows;
|
|
|
|
|
|
|
|
screensize(&cols, &rows);
|
|
|
|
return cols;
|
|
|
|
}
|
|
|
|
|
|
|
|
void input(char* str, unsigned int max, const char* tag)
|
|
|
|
{
|
|
|
|
char chr;
|
|
|
|
uint8_t row;
|
|
|
|
uint16_t len = max / cols() + 1;
|
|
|
|
|
|
|
|
for (row = len; --row; row)
|
|
|
|
{
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
row = wherey() - len;
|
|
|
|
len = 0;
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
str[len] = '\0';
|
|
|
|
|
|
|
|
gotoxy(0, row);
|
|
|
|
cprintf("%s (%d/%d) \r\n%s", tag, len, max, str);
|
|
|
|
|
|
|
|
cursor(1);
|
|
|
|
chr = cgetc();
|
|
|
|
cursor(0);
|
|
|
|
|
|
|
|
if (chr == CH_ENTER)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (chr == CH_DEL)
|
|
|
|
{
|
|
|
|
if (len == 0)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (wherex() > 0)
|
|
|
|
{
|
|
|
|
gotox(wherex() - 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gotoxy(cols() - 1, wherey() - 1);
|
|
|
|
}
|
|
|
|
cputc(' ');
|
|
|
|
--len;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (len == max)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (isprint(chr))
|
|
|
|
{
|
|
|
|
str[len++] = chr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-15 19:25:23 +00:00
|
|
|
int main(void)
|
2018-11-01 13:21:20 +00:00
|
|
|
{
|
|
|
|
int retval;
|
2019-05-02 12:44:24 +00:00
|
|
|
uint8_t eth_init = ETH_INIT_DEFAULT;
|
2018-11-01 13:21:20 +00:00
|
|
|
|
|
|
|
if (doesclrscrafterexit())
|
|
|
|
{
|
|
|
|
atexit(confirm_exit);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
int file;
|
|
|
|
|
|
|
|
printf("\nLoading key ");
|
|
|
|
file = open("ifttt.key", O_RDONLY);
|
|
|
|
if (file != -1)
|
|
|
|
{
|
|
|
|
read(file, key, sizeof(key));
|
|
|
|
close(file);
|
|
|
|
printf("- Ok\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("- Failed\n\n\n");
|
|
|
|
input(key, sizeof(key) - 1, "IFTTT webhook key");
|
|
|
|
if (*key == '\0')
|
|
|
|
{
|
|
|
|
printf("\n");
|
2020-04-15 19:25:23 +00:00
|
|
|
return EXIT_FAILURE;
|
2018-11-01 13:21:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n\nSaving key ");
|
|
|
|
#ifdef __APPLE2__
|
|
|
|
_filetype = PRODOS_T_TXT;
|
|
|
|
#endif
|
|
|
|
file = open("ifttt.key", O_WRONLY | O_CREAT | O_TRUNC);
|
|
|
|
if (file != -1)
|
|
|
|
{
|
|
|
|
write(file, key, sizeof(key));
|
|
|
|
close(file);
|
|
|
|
printf("- Ok\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("- ");
|
|
|
|
perror(NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef __APPLE2__
|
|
|
|
{
|
|
|
|
int file;
|
|
|
|
|
|
|
|
printf("\nSetting slot ");
|
|
|
|
file = open("ethernet.slot", O_RDONLY);
|
|
|
|
if (file != -1)
|
|
|
|
{
|
2019-05-02 12:44:24 +00:00
|
|
|
read(file, ð_init, 1);
|
2018-11-01 13:21:20 +00:00
|
|
|
close(file);
|
2019-05-02 12:44:24 +00:00
|
|
|
eth_init &= ~'0';
|
2018-11-01 13:21:20 +00:00
|
|
|
}
|
2019-05-02 12:44:24 +00:00
|
|
|
printf("- %d\n", eth_init);
|
2018-11-01 13:21:20 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
printf("\nInitializing ");
|
2019-05-02 12:44:24 +00:00
|
|
|
if (ip65_init(eth_init))
|
2018-11-01 13:21:20 +00:00
|
|
|
{
|
|
|
|
error_exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("- Ok\n\nObtaining IP address ");
|
|
|
|
if (dhcp_init())
|
|
|
|
{
|
|
|
|
error_exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("- Ok\n\n\n");
|
|
|
|
input(text, sizeof(text) - 1, "Text");
|
|
|
|
if (*text == '\0')
|
|
|
|
{
|
|
|
|
printf("\n");
|
2020-04-15 19:25:23 +00:00
|
|
|
return EXIT_FAILURE;
|
2018-11-01 13:21:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n\nSending tweet ");
|
|
|
|
retval = ifttt_trigger(key, "tweet", text, NULL, NULL);
|
|
|
|
|
|
|
|
if (retval < 0)
|
|
|
|
{
|
|
|
|
error_exit();
|
|
|
|
}
|
|
|
|
if (retval != 200)
|
|
|
|
{
|
|
|
|
printf("- Error (HTTP status %d)\n", retval);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
printf("- Ok\n");
|
2020-04-15 19:25:23 +00:00
|
|
|
return EXIT_SUCCESS;
|
2018-11-01 13:21:20 +00:00
|
|
|
}
|