Moving towards common commands.h for adruino and cc65
This commit is contained in:
parent
65168d2241
commit
99acc8187a
|
@ -0,0 +1,18 @@
|
|||
//
|
||||
// Commands and messages that are communicated between the ESP and the Apple
|
||||
// via the dual-port ram.
|
||||
//
|
||||
// Commands >=200 are "non-reserved", and are meant
|
||||
// to be defined within scipts that use this library.
|
||||
// So anything in this library should be below 200.
|
||||
//
|
||||
// If the values of these defines are changed, then they will need to be
|
||||
// updated within the code that runs on the Apple as well.
|
||||
|
||||
//#define COMMAND_GENERIC 0b10000000
|
||||
#define COMMAND_WIFI_SCAN 111
|
||||
#define COMMAND_WIFI_CONNECT 112
|
||||
#define ACK 0b00000110 // Acknowledge
|
||||
#define EOT 0b00000100 // End of transmit
|
||||
#define ERR 0b00000101 // Error
|
||||
#define MORE_TO_SEND 0b00000111
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef APPLE2IDIOT
|
||||
#define APPLE2IDIOT
|
||||
#include <Arduino.h>
|
||||
#include "A2I_commands.h"
|
||||
|
||||
/* DATA BUS (numbers mean GPIO port) */
|
||||
#define D0R 12
|
||||
|
@ -30,24 +31,6 @@
|
|||
#define RAM_BUSY 666
|
||||
#define MAX_STR_LEN 250 // arbitrary length.
|
||||
|
||||
//
|
||||
// Commands and messages that are communicated between the ESP and the Apple
|
||||
// via the dual-port ram.
|
||||
//
|
||||
// Commands >=200 are "non-reserved", and are meant
|
||||
// to be defined within scipts that use this library.
|
||||
// So anything in this library should be below 200.
|
||||
//
|
||||
// If the values of these defines are changed, then they will need to be
|
||||
// updated within the code that runs on the Apple as well.
|
||||
|
||||
//#define COMMAND_GENERIC 0b10000000
|
||||
#define COMMAND_WIFI_SCAN 111
|
||||
#define COMMAND_WIFI_CONNECT 112
|
||||
#define ACK 0b00000110 // Acknowledge
|
||||
#define EOT 0b00000100 // End of transmit
|
||||
#define ERR 0b00000101 // Error
|
||||
#define MORE_TO_SEND 0b00000111
|
||||
|
||||
/* IDT7132S dual port ram chip enable */
|
||||
#define RW_PIN 5
|
|
@ -1,177 +0,0 @@
|
|||
/*
|
||||
Use this program with the Apple2idIOT card and the basic programs RRAM, WRAM and CMDROT to read/write and rot13
|
||||
a single string contained within the dual port ram on the card.
|
||||
CA = 49664
|
||||
AA = CA + 1
|
||||
*/
|
||||
|
||||
// Load Wi-Fi library
|
||||
#include <WiFi.h>
|
||||
#include <Apple2Idiot.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include <HTTPClient.h>
|
||||
|
||||
Apple2Idiot a2i = Apple2Idiot();
|
||||
|
||||
#define COMMAND_SET_COUNTRY 200
|
||||
#define COMMAND_SET_CITY 201
|
||||
#define COMMAND_FETCH_WEATHER 205
|
||||
|
||||
const char* wifi_ssid = "GSO";
|
||||
const char* wifi_password = "xerxes27";
|
||||
|
||||
/*******************/
|
||||
/* Weather Service */
|
||||
/*******************/
|
||||
|
||||
const String weather_service_api_key= "0ab97bbbea58592d7c9d64067a34d2d0";
|
||||
const String weather_url = "http://api.openweathermap.org/data/2.5/weather?";
|
||||
|
||||
/*******************/
|
||||
/* Misc */
|
||||
/*******************/
|
||||
|
||||
const long readLoopInterval = 100; // millis
|
||||
unsigned long lastReadLoopTime = 0;
|
||||
|
||||
byte lastAppleCommand = 0;
|
||||
|
||||
/*################################################
|
||||
# Setup #
|
||||
################################################*/
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
a2i.init();
|
||||
|
||||
Serial.println("");
|
||||
Serial.println("Starting wifi...");
|
||||
Serial.print(" connecting to: ");
|
||||
Serial.println(wifi_ssid);
|
||||
|
||||
WiFi.begin(wifi_ssid, wifi_password);
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(600);
|
||||
Serial.print(".");
|
||||
}
|
||||
|
||||
Serial.println("");
|
||||
Serial.println("WiFi connected successfully");
|
||||
Serial.print("Got IP: ");
|
||||
Serial.println(WiFi.localIP()); //Show ESP32 IP on serial
|
||||
|
||||
Serial.println("Setup done");
|
||||
}
|
||||
|
||||
/*################################################
|
||||
# Functions #
|
||||
################################################*/
|
||||
|
||||
byte fetch_weather(char* city_name) {
|
||||
|
||||
byte result = 0;
|
||||
HTTPClient http;
|
||||
const String request_url = weather_url + "q=Tucson,us&APPID=" + weather_service_api_key;
|
||||
Serial.println(request_url);
|
||||
http.begin(request_url);
|
||||
int httpCode = http.GET(); //Make the request
|
||||
delay(10);
|
||||
|
||||
if (httpCode > 0) { //Check for the returning code
|
||||
String payload = http.getString();
|
||||
//Serial.println(httpCode);
|
||||
Serial.println("++++++++++++++++++++++++");
|
||||
Serial.println(payload);
|
||||
Serial.println("++++++++++++++++++++++++");
|
||||
StaticJsonDocument<200> filter;
|
||||
filter["weather"][0]["main"] = true;
|
||||
filter["weather"][0]["description"] = true;
|
||||
filter["main"]["humidity"] = true;
|
||||
filter["main"]["temp"] = true;
|
||||
filter["wind"]["speed"] = true;
|
||||
filter["wind"]["deg"] = true;
|
||||
StaticJsonDocument<400> doc;
|
||||
DeserializationError error = deserializeJson(doc, payload, DeserializationOption::Filter(filter));
|
||||
//DeserializationError error = deserializeJson(doc, payload);
|
||||
if (error) {
|
||||
Serial.print(F("deserializeJson() failed: "));
|
||||
Serial.println(error.f_str());
|
||||
} else {
|
||||
//const char* main = doc["main"];
|
||||
Serial.println("----------------------");
|
||||
serializeJsonPretty(doc, Serial);
|
||||
Serial.println("----------------------");
|
||||
serializeJsonPretty(doc["wind"], Serial);
|
||||
Serial.println("----------------------");
|
||||
//int temp = doc["main"]["temp"];
|
||||
//int humidity = doc["main"]["humidity"];
|
||||
//float wind_speed = doc["wind"]["speed"];
|
||||
//int wind_deg = doc["wind"]["deg"];
|
||||
//String weather_description = doc["weather"][0]["description"];
|
||||
//a2i.write_data(0, round(temp-273.15));
|
||||
//a2i.write_data(1, round(humidity));
|
||||
//a2i.write_data(2, round(wind_deg/10)); // divide by twn because 360 is too big for 8 bits
|
||||
//a2i.write_data(3, round(wind_speed));
|
||||
String temp = doc["main"]["temp"];
|
||||
String humidity = doc["main"]["humidity"];
|
||||
String wind_speed = doc["wind"]["speed"];
|
||||
String wind_deg = doc["wind"]["deg"];
|
||||
String weather_description = doc["weather"][0]["description"];
|
||||
int address_counter = a2i.write_string_to_shared_ram(temp, SHARED_RAM_START_ADDRESS);
|
||||
address_counter = a2i.write_string_to_shared_ram(humidity, address_counter + 1);
|
||||
address_counter = a2i.write_string_to_shared_ram(wind_speed, address_counter + 1);
|
||||
address_counter = a2i.write_string_to_shared_ram(wind_deg, address_counter + 1);
|
||||
}
|
||||
result = ACK;
|
||||
}
|
||||
else {
|
||||
Serial.println("Error on HTTP request");
|
||||
result = ERR;
|
||||
}
|
||||
|
||||
http.end(); //Free the resources
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/*################################################
|
||||
# Main #
|
||||
################################################*/
|
||||
|
||||
void loop() {
|
||||
|
||||
if ((millis() - lastReadLoopTime) > readLoopInterval) {
|
||||
byte command_byte = a2i.read_data(APPLE_COMMAND_ADDRESS);
|
||||
if (command_byte == RAM_BUSY) {
|
||||
Serial.println("Command Read: RAM BUSY");
|
||||
}
|
||||
else if (command_byte != lastAppleCommand){
|
||||
byte result = 0;
|
||||
Serial.print("Command Switch command_byte: ");
|
||||
Serial.println(command_byte);
|
||||
switch(command_byte) {
|
||||
case COMMAND_SET_COUNTRY:
|
||||
//a2i.write_data(ESP_COMMAND_ADDRESS, ACK); // notify Apple IIe we are processing command byte
|
||||
//int access_point_n = a2i.read_data(SHARED_RAM_START_ADDRESS) - 1;
|
||||
//String password_as_String = a2i.read_string_from_ram(SHARED_RAM_START_ADDRESS+1);
|
||||
//a2i.write_data(APPLE_COMMAND_ADDRESS, ACK);
|
||||
break;
|
||||
case COMMAND_SET_CITY:
|
||||
//a2i.write_data(ESP_COMMAND_ADDRESS, ACK); // notify Apple IIe we are processing command byte
|
||||
//int access_point_n = a2i.read_data(SHARED_RAM_START_ADDRESS) - 1;
|
||||
//String password_as_String = a2i.read_string_from_ram(SHARED_RAM_START_ADDRESS+1);
|
||||
//a2i.write_data(APPLE_COMMAND_ADDRESS, ACK);
|
||||
break;
|
||||
case COMMAND_FETCH_WEATHER:
|
||||
a2i.write_data(ESP_COMMAND_ADDRESS, ACK); // notify Apple IIe we are processing command byte
|
||||
result = fetch_weather("Tucson");
|
||||
a2i.write_data(APPLE_COMMAND_ADDRESS, ACK);
|
||||
a2i.write_data(ESP_COMMAND_ADDRESS, result); // notify Apple IIe we are done processing command byte
|
||||
break;
|
||||
}
|
||||
lastAppleCommand = command_byte;
|
||||
}
|
||||
lastReadLoopTime = millis();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue