diff --git a/__pycache__/keyboardClass.cpython-37.pyc b/__pycache__/keyboardClass.cpython-37.pyc index d663d53171d635dd81bfc30f4c75828ca4813bf8..e27ea5f86ca64dad6b6ff552d28b118a84b8a0f4 100644 Binary files a/__pycache__/keyboardClass.cpython-37.pyc and b/__pycache__/keyboardClass.cpython-37.pyc differ diff --git a/__pycache__/rpn.cpython-37.pyc b/__pycache__/rpn.cpython-37.pyc index 6ec70008e40fca9ed04d70d6484db52858c67494..cf6c5d72c2455e378503833d944bb0d9bd74d2e1 100644 Binary files a/__pycache__/rpn.cpython-37.pyc and b/__pycache__/rpn.cpython-37.pyc differ diff --git a/__pycache__/stackClass.cpython-37.pyc b/__pycache__/stackClass.cpython-37.pyc index 2389c31561fc0f073008f6004aa44db43db1ba35..8870585f3cf5d7943ef1449e914c898779bf935a 100644 Binary files a/__pycache__/stackClass.cpython-37.pyc and b/__pycache__/stackClass.cpython-37.pyc differ diff --git a/build/lib.linux-armv6l-3.7/dd_oled.cpython-37m-arm-linux-gnueabihf.so b/build/lib.linux-armv6l-3.7/dd_oled.cpython-37m-arm-linux-gnueabihf.so new file mode 100644 index 0000000000000000000000000000000000000000..135fcc74617f6b64674539de0ed97822264f3c62 Binary files /dev/null and b/build/lib.linux-armv6l-3.7/dd_oled.cpython-37m-arm-linux-gnueabihf.so differ diff --git a/build/temp.linux-armv6l-3.7/dd_oled.o b/build/temp.linux-armv6l-3.7/dd_oled.o index c62d6d2a6ba2e837fc30cc5d702e6fc0e212101e..30f2bb5d238218a8366c72a9d1fac9869b471ceb 100644 Binary files a/build/temp.linux-armv6l-3.7/dd_oled.o and b/build/temp.linux-armv6l-3.7/dd_oled.o differ diff --git a/calculator.py b/calculator.py index 0341f53925411d2e3d336ad1a99c3e1dfa8a9ea1..014031f8cd3391e8774f8a89aa85b43670364756 100644 --- a/calculator.py +++ b/calculator.py @@ -3,35 +3,88 @@ import stackClass import time import sy import rpn +import dd_oled +import RPi.GPIO as GPIO +def runCalculator(lastPressed=[]): + x = 0 + calculate = 0 + stack = stackClass.stack() + rpnStack = stackClass.stack() + while x < 200 and calculate == 0: #tempory return to while 1: + pressed = keypad.pressed() -keypad = keyboardClass.Keypad() -stack = stackClass.stack() -rpnStack = stackClass.stack() + for key in pressed: + if len(lastPressed) == 0: + if key != "=": + stack.push(key) + dd_oled.oled_fill(0) + dd_oled.write_string(0, 0, ''.join(stack.stack), 0) + else: + calculate = 1 + else: + for lastKey in lastPressed: + if lastKey != key: + if key != "=": + stack.push(key) + dd_oled.oled_fill(0) + dd_oled.write_string(0, 0, ''.join(stack.stack), 0) + else: + calculate = 1 -lastPressed = [] -x = 0 -while x < 10: #tempory return to while 1: - pressed = keypad.pressed() + lastPressed = pressed + + print(stack.stack) + time.sleep(.1) + x += 1 + test = sy.shunt(sy.tokenize(''.join(stack.stack))) - for key in pressed: - if len(lastPressed) == 0: - stack.push(key) - else: - for lastKey in lastPressed: - if lastKey != key: - stack.push(key) - lastPressed = pressed - print(stack.stack) - time.sleep(.5) - x += 1 + print(type(test)) + # ['1', '+', '2'] + # for item in test: + # print(item) + # print("hi") + ans = rpn.rpn_eval(test,rpnStack) + print(ans) + dd_oled.oled_fill(0) + dd_oled.write_string(0, 0, ''.join(ans), 0) # print(f"1 : {sy.shunt(stack.stack)}") -test = sy.shunt(stack.stack) -# ['1', '+', '2'] -# for item in test: -# print(item) -# print("hi") -print(rpn.rpn_eval(test,rpnStack)) +keypad = keyboardClass.Keypad() +dd_oled.oled_init(1, 0x3C, 1, 0, 0) +dd_oled.oled_fill(0) +dd_oled.write_string(1, 0, 'Welcome', 1) +dd_oled.write_string(5, 3, 'Press any key', 2) +lastPressed = [] +while True: + pressed = keypad.pressed() + if pressed != lastPressed: + lastPressed = pressed + break + lastPressed = pressed +dd_oled.oled_fill(0) +while True: + runCalculator(lastPressed) + lastPressed = [] + dd_oled.write_string(5, 2, 'Press any key.', 2) + dd_oled.write_string(5, 3, 'or \'#\' to exit', 2) + + while True: + time.sleep(1) + pressed = keypad.pressed() + if pressed != lastPressed: + print(f"pressed:{pressed}") + if '#' in pressed: + GPIO.cleanup() + exit() + + else: + lastPressed = pressed + break + lastPressed = pressed + +# ADD mine sweeper + + diff --git a/dd_oled.c b/dd_oled.c index 4bf7053df1e1b9817cbb742b03f8351b1bb0fd49..00a156198575e99785be1c9b0e9fb6e2f19b5517 100644 --- a/dd_oled.c +++ b/dd_oled.c @@ -358,7 +358,7 @@ static PyObject *_oled_fill(PyObject *self, PyObject * args) return Py_BuildValue("i",oledFill(fill)); } -static struct PyMethodDef hello_methods[] = { +static struct PyMethodDef dd_oled_methods[] = { {"hello_world", (PyCFunction)_hello_world, METH_NOARGS,"Python interface for hello world function"}, {"write_string", (PyCFunction)_write_string, METH_VARARGS,"Python interface for write string"}, {"oled_init", (PyCFunction)_oled_init, METH_VARARGS,"Python interface for oled INIT"}, @@ -366,15 +366,15 @@ static struct PyMethodDef hello_methods[] = { {NULL, NULL, 0, NULL}}; -static struct PyModuleDef hello_module = { +static struct PyModuleDef dd_oled_module = { PyModuleDef_HEAD_INIT, - "hello", - "Python interface for the C hello world function", + "dd_oled", + "Python interface for the C oled libary", -1, - hello_methods}; + dd_oled_methods}; -PyMODINIT_FUNC PyInit_hello(void) { - return PyModule_Create(&hello_module); +PyMODINIT_FUNC PyInit_dd_oled(void) { + return PyModule_Create(&dd_oled_module); } diff --git a/keyboard.py b/keyboard.py index 3f70d5c9f71453bd5e2e75ccc7c144a41aaff666..75f67b16326ee4e9ec58709dddc25091f1b59aea 100644 --- a/keyboard.py +++ b/keyboard.py @@ -1,6 +1,8 @@ import RPi.GPIO as GPIO import time + +test COL1 = 6 COL2 = 13 COL3 = 19 diff --git a/keyboardClass.py b/keyboardClass.py index 6d63e8cb2e5b2e7e1d934d050c478d197ea3f21f..e11a4d2f3b1c71e9db77bd9051c32560efcdaf23 100644 --- a/keyboardClass.py +++ b/keyboardClass.py @@ -25,7 +25,7 @@ class Keypad: GPIO.output(col, GPIO.LOW) state = GPIO.input(row) GPIO.output(col, GPIO.HIGH) - print("state: " + str(state)) + # print("state: " + str(state)) if state == 1: return False else: @@ -33,17 +33,17 @@ class Keypad: def pressed(self): pressed = [] - print(len(self.rows)) + # print(len(self.rows)) for row in range(0,len(self.rows)): for col in range(0,len(self.cols)): if self.isPressed(self.rows[row],self.cols[col]) == True: pressed.append(self.keyConverter(row,col)) - print("pressed detected ########################") - print("appended"+ str(self.keyConverter(row,col))) + # print("pressed detected ########################") + # print("appended"+ str(self.keyConverter(row,col))) return pressed def keyConverter(self,row,col): - print("row: " + str(row) + " col: " + str(col)) + # print("row: " + str(row) + " col: " + str(col)) if row == 0 and col == 0: return '1' elif row == 0 and col == 1: @@ -75,7 +75,7 @@ class Keypad: elif row == 3 and col == 2: return "#" elif row == 3 and col == 3: - return "D" + return "=" # input = Keypad() diff --git a/rpn.py b/rpn.py index 3d183e7bf16bb70b1fcec4c648927ad8aaa2ccd7..10cc4d0bffdea1e0ac42d2d29959b6106e48b267 100644 --- a/rpn.py +++ b/rpn.py @@ -5,8 +5,8 @@ def rpn_eval(tokens,stack): print(item) if item in "+-*/": print("here") - right = int(stack.pop()) - left = int(stack.pop()) + right = float(stack.pop()) + left = float(stack.pop()) if item == "+": output = left + right elif item == "-": @@ -15,7 +15,7 @@ def rpn_eval(tokens,stack): output = left * right elif item == "/": output = left / right - stack.push(output) + stack.push(str(output)) else: stack.push(item) pass diff --git a/setup.py b/setup.py index a3d487f40c1cb26cf9f42abd71a099826436b137..1b114c9165dfa0421ddfc907c8cc5cd016328b42 100644 --- a/setup.py +++ b/setup.py @@ -1,12 +1,12 @@ from distutils.core import setup, Extension def main(): - setup(name="hello-lib", + setup(name="dd_oled-lib", version="1.0.0", - description="Python interface for the hello C function", - author="<your name>", - author_email="your_email@gmail.com", - ext_modules=[Extension("hello", ["dd_oled.c"])] + description="Python interface for the C oled libary", + author="<Jack Holdsworth>", + author_email="jack@holdsworth.email", + ext_modules=[Extension("dd_oled", ["dd_oled.c"])] ) if __name__ == "__main__": main()