diff --git a/arduino-lib/Apple2Idiot/Apple2Idiot b/arduino-lib/Apple2Idiot/Apple2Idiot deleted file mode 120000 index 153195c..0000000 --- a/arduino-lib/Apple2Idiot/Apple2Idiot +++ /dev/null @@ -1 +0,0 @@ -Apple2Idiot \ No newline at end of file diff --git a/arduino-lib/Apple2Idiot/Apple2Idiot.cpp b/arduino-lib/Apple2Idiot/Apple2Idiot.cpp index 68dccff..2f9803c 100644 --- a/arduino-lib/Apple2Idiot/Apple2Idiot.cpp +++ b/arduino-lib/Apple2Idiot/Apple2Idiot.cpp @@ -103,7 +103,7 @@ boolean Apple2Idiot::write_data(byte address, byte byte_to_write) { unsigned int Apple2Idiot::write_string_to_shared_ram(String string_to_send, unsigned int address) { //if (string_to_send.length() > 15 - 1) { // - 1 because of null character at end of string. write_data(ESP_COMMAND_ADDRESS, 12); - unsigned int c = 0; + unsigned int c = 2; for (c=0; c < string_to_send.length(); c++) { Serial.print("A("); Serial.print(c); @@ -111,19 +111,20 @@ unsigned int Apple2Idiot::write_string_to_shared_ram(String string_to_send, unsi Serial.println(string_to_send[c]); write_data(address+c, string_to_send[c]); } - write_data(address+c, ETX); + write_data(address+c, EOS); //write_data(15, COMMAND_FROM_ESP + command_message + COMMAND_NO_DATA_WAITING); write_data(ESP_COMMAND_ADDRESS, 27); return address+c; } String Apple2Idiot::read_string_from_ram(int address) { - byte c = 0; + byte c = 2; int i = 0; String read_string = ""; - while ( (i %d, %c\n", 0xC200+i, p, p); - //} - //cursor(1); - //p = cgetc(); - //gotoxy(0, SIZE_Y-5); - //printf("You said: %c\n", p); } -unsigned char* write_string_to_ram(char* string_to_send, unsigned char address) { - unsigned char i, p, c; +unsigned char* write_string_to_ram(unsigned int address, char* string_to_send) { + unsigned char i; unsigned char size = strlen(string_to_send); gotoxy(0,2); if (string_to_send[size-1] == '\n') { - string_to_send[size-1] = 0; + string_to_send[size-1] = '\0'; } - //printf("write_string_to_ram()"); + //printf("%u (%s)\n", address, string_to_send); for (i=0; i +#include #include #include #include +#include #include "globals.h" #include "menu.h" #include "apple2idiot.h" unsigned char i = 0; -char p; -char text[20]; - +char pause_char; +char city[33]; +char country_code[3]; +char temperature[7]; +char humidity[7]; +char wind_speed[7]; +char wind_direction[5]; +char weather1[250]; +char weather2[250]; +unsigned int address_offset = 0; void main(void) { unsigned char key; + clrscr(); - while (key != ASCII_0) { // Last menu item should be Quit - clrscr(); + while (key != ASCII_5) { // Last menu item should be Quit drawMenuBar(); - //cvlinexy(0,1,size_x); - //fancy_hline(0,2); - //fputs("enter some text: ", stdout); - //fflush(stdout); /* http://c-faq.com/stdio/fflush.html */ - //fgets(text, sizeof text, stdin); - //printf("\ntext = \"%s\"", text); - //revers(1); + gotoxy(0,2); + printf("Country: %s City:%s", country_code, city); gotoxy(0,SIZE_Y-1); - printf("Selection:"); + printf("Menu Selection:"); cursor(1); - //revers(0); - //p = cgetc(); key = toupper(cgetc()); gotoxy(0,SIZE_Y-3); - printf("cgetc() -> \"%c\"", key); + //printf("cgetc() -> \"%c\"", key); switch((int)key) { case ASCII_0: - printf("QUIT!"); + break; + case ASCII_5: break; case ASCII_1: - printf("COUNTRY!"); - write_string_to_ram("US", 0xC202); + clrscr(); + drawMenuBar(); + gotoxy(0,SIZE_Y-1); + printf("Enter Country Code:"); + fgets(country_code, sizeof country_code, stdin); + strncpy(country_code, country_code, strlen(country_code)); + //country_code[strcspn(country_code, "\n")] = 0; + write_string_to_ram(RAM_DATA_START_ADDRESS, country_code); + write_byte(APPLE_COMMAND_ADDRESS, COMMAND_SET_COUNTRY); + //printf("C:[%s]", country_code); + //pause_char = cgetc(); break; case ASCII_2: - printf("City: "); - fgets(text, sizeof text, stdin); - write_string_to_ram(text, 0xC202); + clrscr(); + drawMenuBar(); + gotoxy(0,SIZE_Y-1); + printf("Enter City: "); + fgets(city, sizeof city, stdin); + city[strcspn(city, "\n")] = 0; + write_string_to_ram(RAM_DATA_START_ADDRESS, city); + write_byte(APPLE_COMMAND_ADDRESS, COMMAND_SET_CITY); + //printf("C:[%s]", city); + //pause_char = cgetc(); break; case ASCII_3: - printf("UPDATE!"); + clrscr(); + drawMenuBar(); + write_byte(APPLE_COMMAND_ADDRESS, COMMAND_FETCH_WEATHER); + break; + case ASCII_4: + clrscr(); + drawMenuBar(); + read_string_from_ram(RAM_DATA_START_ADDRESS + address_offset, temperature, sizeof temperature-1); + address_offset += strlen(temperature) + 1; + read_string_from_ram(RAM_DATA_START_ADDRESS + address_offset, humidity, sizeof humidity-1); + address_offset += strlen(humidity) + 1; + read_string_from_ram(RAM_DATA_START_ADDRESS + address_offset, wind_speed, sizeof wind_speed-1); + address_offset += strlen(wind_speed) + 1; + read_string_from_ram(RAM_DATA_START_ADDRESS + address_offset, wind_direction, sizeof wind_direction-1); + address_offset += strlen(wind_direction) + 1; + read_string_from_ram(RAM_DATA_START_ADDRESS + address_offset, weather1, sizeof weather1-1); + address_offset += strlen(weather1) + 1; + read_string_from_ram(RAM_DATA_START_ADDRESS + address_offset, weather2, sizeof weather2-1); + gotoxy(0,SIZE_Y-11); + printf("%s (%s)\n", city, country_code); + printf("-------------------------------------\n"); + printf("Temp: %s K\n", temperature); + printf("Humidity: %s%%\n", humidity); + printf("Wind Speed: %s m/s\n", wind_speed); + printf("Wind Dir: %s \n", wind_direction); + printf("Summary: %s, %s \n", weather1, weather2); + printf("-------------------------------------\n"); break; default: - printf("DEFAULT!"); break; } diff --git a/examples/weather/apple2-cc65/src/menu.c b/examples/weather/apple2-cc65/src/menu.c index 6e86764..b40c70a 100644 --- a/examples/weather/apple2-cc65/src/menu.c +++ b/examples/weather/apple2-cc65/src/menu.c @@ -6,9 +6,9 @@ #include "globals.h" #include "menu.h" -#define MENU_LENGTH 4 +#define MENU_LENGTH 5 #define MENU_WORD_LENGTH 8 -unsigned char menuEntries[MENU_LENGTH][MENU_WORD_LENGTH] = {"Country", "City", "Update", "Quit"}; +unsigned char menuEntries[MENU_LENGTH][MENU_WORD_LENGTH] = {"Country", "City", "Fetch", "Display", "Quit"}; void drawMenuBar() { static unsigned char i; diff --git a/examples/weather/apple2-cc65/weather.apple2 b/examples/weather/apple2-cc65/weather.apple2 index a2e49b9..c7502a4 100644 Binary files a/examples/weather/apple2-cc65/weather.apple2 and b/examples/weather/apple2-cc65/weather.apple2 differ diff --git a/examples/weather/apple2-cc65/weather.dsk b/examples/weather/apple2-cc65/weather.dsk index 8d996a5..cba1d05 100644 Binary files a/examples/weather/apple2-cc65/weather.dsk and b/examples/weather/apple2-cc65/weather.dsk differ