Add the printer simulator draft.
This commit is contained in:
parent
dd466b08f6
commit
3495c03d65
8 changed files with 186 additions and 4 deletions
|
@ -28,9 +28,7 @@ VOID ResetUdp(VOID) {
|
|||
}
|
||||
|
||||
BOOL SendByteUdp(BYTE byData) {
|
||||
|
||||
LOGD("SendByteUdp(%d -> 0x%02x -> '%c')", byData, byData, byData);
|
||||
|
||||
sendByteUdp(byData);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
|
|
@ -253,6 +253,17 @@ void performHapticFeedback() {
|
|||
}
|
||||
}
|
||||
|
||||
void sendByteUdp(unsigned char byteSent) {
|
||||
JNIEnv *jniEnv = getJNIEnvironment();
|
||||
if(jniEnv) {
|
||||
jclass mainActivityClass = (*jniEnv)->GetObjectClass(jniEnv, mainActivity);
|
||||
if(mainActivityClass) {
|
||||
jmethodID midStr = (*jniEnv)->GetMethodID(jniEnv, mainActivityClass, "sendByteUdp", "(I)V");
|
||||
(*jniEnv)->CallVoidMethod(jniEnv, mainActivity, midStr, (int)byteSent);
|
||||
(*jniEnv)->DeleteLocalRef(jniEnv, mainActivityClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_emulator_forty_eight_NativeLib_start(JNIEnv *env, jobject thisz, jobject assetMgr, jobject bitmapMainScreen0, jobject activity, jobject view) {
|
||||
|
||||
|
|
|
@ -1255,5 +1255,6 @@ BOOL getFirstKMLFilenameForType(BYTE chipsetType, TCHAR * firstKMLFilename, size
|
|||
void clipboardCopyText(const TCHAR * text);
|
||||
const TCHAR * clipboardPasteText();
|
||||
void performHapticFeedback();
|
||||
void sendByteUdp(unsigned char byteSent);
|
||||
|
||||
typedef int SOCKET;
|
||||
|
|
|
@ -100,6 +100,8 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|||
}
|
||||
};
|
||||
|
||||
private PrinterSimulator printer = new PrinterSimulator();
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -325,6 +327,8 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|||
OnBackupDelete();
|
||||
} else if (id == R.id.nav_change_kml_script) {
|
||||
OnViewScript();
|
||||
} else if (id == R.id.nav_show_printer) {
|
||||
OnViewPrinter();
|
||||
} else if (id == R.id.nav_create_ram_card) {
|
||||
OnCreateRAMCard();
|
||||
} else if (id == R.id.nav_help) {
|
||||
|
@ -783,6 +787,17 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|||
showKMLPicker(true);
|
||||
}
|
||||
|
||||
private void OnViewPrinter() {
|
||||
String printerText = printer.getText();
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle(getString(R.string.message_printer))
|
||||
.setMessage(printerText)
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
}
|
||||
}).show();
|
||||
}
|
||||
|
||||
private void showKMLPicker(final boolean changeKML) {
|
||||
extractKMLScripts();
|
||||
|
||||
|
@ -1327,6 +1342,10 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
|||
mainScreenView.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
|
||||
}
|
||||
|
||||
void sendByteUdp(int byteSent) {
|
||||
printer.write(byteSent);
|
||||
}
|
||||
|
||||
private void setPort1Settings(boolean port1Plugged, boolean port1Writable) {
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
editor.putBoolean("settings_port1en", port1Plugged);
|
||||
|
|
147
app/src/main/java/org/emulator/forty/eight/PrinterSimulator.java
Normal file
147
app/src/main/java/org/emulator/forty/eight/PrinterSimulator.java
Normal file
|
@ -0,0 +1,147 @@
|
|||
package org.emulator.forty.eight;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/*
|
||||
* Based on the free HP82240B Printer Simulator by Christoph Giesselink
|
||||
*/
|
||||
public class PrinterSimulator {
|
||||
|
||||
private ArrayList<Integer> data = new ArrayList<>();
|
||||
private StringBuilder m_Text = new StringBuilder("");
|
||||
|
||||
|
||||
private final int ESC = 27; // ESC
|
||||
|
||||
private final byte PM_HP82240A = 0;
|
||||
private final byte PM_HP82240B = 1;
|
||||
private final byte PM_GenericSerial = 2;
|
||||
|
||||
private byte m_ePrinterModel;// selected printer model
|
||||
private boolean m_bExpChar; // printing expanded characters
|
||||
private boolean m_bUnderLined; // printing underlined characters
|
||||
private boolean m_bEcma94; // Roman 8 / ECMA 94 character set
|
||||
|
||||
private boolean m_bEsc; // not ESC sequence
|
||||
private int m_byGraphLength; // remaining no. of graphic bytes
|
||||
|
||||
public PrinterSimulator() {
|
||||
m_ePrinterModel = PM_HP82240B; // HP82240B printer
|
||||
|
||||
reset(); // reset printer state machine
|
||||
}
|
||||
|
||||
//
|
||||
// reset printer state machine
|
||||
//
|
||||
void reset() {
|
||||
m_bExpChar = false; // printing normal-width characters
|
||||
m_bUnderLined = false; // printing non underlined characters
|
||||
|
||||
// Roman 8 character set for HP82240A and HP82240B, ECMA 94 for serial printer type
|
||||
m_bEcma94 = (m_ePrinterModel == PM_GenericSerial);
|
||||
|
||||
m_bEsc = false; // not ESC sequence
|
||||
m_byGraphLength = 0; // no remaining graphic bytes
|
||||
}
|
||||
|
||||
//
|
||||
// printer selftest
|
||||
//
|
||||
void selftest() {
|
||||
// self test normally run in an endless loop, that's very hard to implement,
|
||||
// so this implementation printing all chracters only one time and then
|
||||
// go back to the communication interface
|
||||
|
||||
int i,nLF;
|
||||
|
||||
reset(); // reset printer state machine
|
||||
|
||||
nLF = 1;
|
||||
write((byte)4); // begin with special LF
|
||||
write((byte)95); // '_' instead if ' ' as first character
|
||||
for (i = 33; i <= 256; ++i) { // all ROMAN8 characters
|
||||
if (nLF == 0) write((byte)4); // LF after 24 characters printing
|
||||
write((byte)i); // print character
|
||||
nLF = ++nLF % 24;
|
||||
}
|
||||
|
||||
// post code, identification number: HP82240A = D, HP82240B = G
|
||||
write((byte)(m_ePrinterModel == PM_HP82240A ? 'D' : 'G'));
|
||||
|
||||
// rest of post code is battery state full
|
||||
String szPostPrt = "\u0004\u0004BAT: 5\u0004\u0004";
|
||||
|
||||
for (int ci = 0; ci < szPostPrt.length(); ci++) { // write post print
|
||||
char c = szPostPrt.charAt(ci);
|
||||
write((byte)c);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void write(int byData) {
|
||||
data.add(byData);
|
||||
|
||||
do {
|
||||
// check for begin of ESC sequence
|
||||
if (byData == ESC && !m_bEsc && m_byGraphLength == 0) {
|
||||
m_bEsc = true; // ESC sequence mode
|
||||
break;
|
||||
}
|
||||
|
||||
if (m_bEsc) { // byte is ESC command
|
||||
switch (byData) {
|
||||
case 255: // reset
|
||||
reset();
|
||||
break;
|
||||
case 254: // start self test
|
||||
selftest();
|
||||
break;
|
||||
case 253: // start printing expanded characters
|
||||
m_bExpChar = true;
|
||||
break;
|
||||
case 252: // return to normal-width characters
|
||||
m_bExpChar = false;
|
||||
break;
|
||||
case 251: // start printing underlined characters
|
||||
m_bUnderLined = true;
|
||||
break;
|
||||
case 250: // stop underlining
|
||||
m_bUnderLined = false;
|
||||
break;
|
||||
case 249: // ECMA 94 character set
|
||||
if (m_ePrinterModel == PM_HP82240B)
|
||||
m_bEcma94 = true;
|
||||
break;
|
||||
case 248: // Roman 8 character set
|
||||
if (m_ePrinterModel == PM_HP82240B)
|
||||
m_bEcma94 = false;
|
||||
break;
|
||||
default:
|
||||
// graphic data
|
||||
if (byData >= 1 && byData <= 166) {
|
||||
// remaining graphic bytes
|
||||
m_byGraphLength = byData;
|
||||
}
|
||||
}
|
||||
m_bEsc = false;
|
||||
break;
|
||||
}
|
||||
|
||||
// normal character
|
||||
if (m_byGraphLength == 0) { // not a graphic character
|
||||
m_Text.append((char)byData); // output to text window
|
||||
}
|
||||
|
||||
// output to graphic window
|
||||
//m_Graph.WriteChar(byData,m_byGraphLength > 0);
|
||||
|
||||
if (m_byGraphLength > 0) { // in graphic mode
|
||||
--m_byGraphLength; // graphic character printed
|
||||
}
|
||||
} while (false);
|
||||
}
|
||||
|
||||
String getText() {
|
||||
return m_Text.toString();
|
||||
}
|
||||
}
|
|
@ -88,6 +88,10 @@
|
|||
android:id="@+id/nav_change_kml_script"
|
||||
android:icon="@drawable/ic_wallpaper_black_24dp"
|
||||
android:title="@string/nav_change_kml_script" />
|
||||
<item
|
||||
android:id="@+id/nav_show_printer"
|
||||
android:icon="@drawable/ic_wallpaper_black_24dp"
|
||||
android:title="@string/nav_show_printer" />
|
||||
</menu>
|
||||
</item>
|
||||
<item android:title="@string/nav_tool">
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
<string name="nav_delete_backup">Delete Backup</string>
|
||||
<string name="nav_view">View</string>
|
||||
<string name="nav_change_kml_script">Change KML Script...</string>
|
||||
<string name="nav_show_printer">Show the Printer Simulator...</string>
|
||||
<string name="nav_tool">Tool</string>
|
||||
<string name="nav_create_ram_card">Create RAM Card...</string>
|
||||
<string name="nav_help">Help</string>
|
||||
|
@ -67,6 +68,7 @@
|
|||
<string name="message_kml_script_compilation_result">KML Script Compilation Result</string>
|
||||
<string name="message_kml_folder_selection_need_api_lollipop">Need Android 5.0</string>
|
||||
<string name="message_kml_folder_selection_need_api_lollipop_description">To select the KML folder, you need at least Android version 5.0</string>
|
||||
<string name="message_printer">Printer Simulator</string>
|
||||
|
||||
<string name="settings_category_general_title">General</string>
|
||||
<string name="settings_realspeed_title">Authentic Calculator Speed</string>
|
||||
|
|
|
@ -141,7 +141,7 @@
|
|||
<!--"Device",IDC_STATIC,13,42,24,8-->
|
||||
<!--COMBOBOX IDC_SOUND_DEVICE,44,40,193,87,CBS_DROPDOWNLIST |-->
|
||||
<!--</PreferenceCategory>-->
|
||||
<!--<PreferenceCategory app:title="Infrared Printer">
|
||||
<!--<PreferenceCategory app:title="Infrared PrinterSimulator">
|
||||
"IP Address:",IDC_STATIC
|
||||
"Port:",IDC_STATIC
|
||||
IDC_IR_ADDR
|
||||
|
|
Loading…
Reference in a new issue