Giter VIP home page Giter VIP logo

Comments (9)

cgomesu avatar cgomesu commented on August 17, 2024 1

@juvus could you please take a look at this? it's related to your custom character implementation. (@Jumitti might be able to help as well. Feel free to chime in.)

from lcd.

juvus avatar juvus commented on August 17, 2024 1

Hi, sorry for late response. To redefine a custom character you need to pass a python list containing 7 strings as it is shown here:
cc.char_1_data = ["01110", "01010", "01110", "00100", "11111", "11111", "11111", "11111"]
In you case you have 1 string '0b000"00000", "00000", "00000", "00100", "00000", "00000", "00000", "00000"'. And this is not correct stuff causing a problem.
Solution: write you own parcer (or convertor) from your string (comming from flask app form) to a correct python list of strings.

from lcd.

Jumitti avatar Jumitti commented on August 17, 2024

@Jimmy106-e can you show me your code please? Also, I refer you to my GitHub repository, you may find the solution there https://github.com/Jumitti/lcd_home_automation

from lcd.

Jimmy106-e avatar Jimmy106-e commented on August 17, 2024

@Jimmy106-e can you show me your code please? Also, I refer you to my GitHub repository, you may find the solution there https://github.com/Jumitti/lcd_home_automation

Python code (With Flask)

from flask import Flask, render_template, request
import drivers

app = Flask(__name__)
display = drivers.Lcd()
cc = drivers.CustomCharacters(display)

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/get_bitmap', methods=['POST'])
def get_bitmap():
    bitmap_data = request.form['bitmapData']
    print("Bitmap data:", bitmap_data)
    cc.char_1_data = [bitmap_data]
    #cc.load_custom_characters_data()
    print(cc.char_1_data)
    #display.lcd_display_extended_string("{0x00}",1)
    return '', 204

if __name__ == '__main__':
    app.run('0.0.0.0')

HTML (in folder called "templates")

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Bitmap Editor</title>
  <style>
    .grid {
      display: grid;
      grid-template-columns: repeat(5, 30px);
      grid-template-rows: repeat(8, 30px);
      gap: 1px;
    }
    .cell {
      width: 30px;
      height: 30px;
      background-color: white;
      border: 1px solid black;
    }
    .cell.active {
      background-color: black;
    }
  </style>
</head>
<body>
  <form action="/get_bitmap" method="post">
    <h1>Bitmap Editor</h1>
    <div class="grid">
      {% for row in range(8) %}
        {% for col in range(5) %}
          <div class="cell" onclick="toggleCell(this)"></div>
        {% endfor %}
      {% endfor %}
    </div>
    <button type="submit">Get Bitmap</button>
    <input type="hidden" name="bitmapData" id="bitmapData">
  </form>

  <script>
    function toggleCell(cell) {
      cell.classList.toggle('active');
    }

    document.querySelector('form').addEventListener('submit', function(event) {
      event.preventDefault();
      const bitmapData = Array.from(document.querySelectorAll('.cell')).map(cell => cell.classList.contains('active') ? 1 : 0).join('');
      
      // Insert comma and quotation marks
      let bitmapString = '' ;
      for (let i = 0; i < bitmapData.length; i++) {
        if (i % 5 === 0) bitmapString += '"';
        bitmapString += bitmapData[i];
        if ((i + 1) % 5 === 0 && i !== bitmapData.length - 1) bitmapString += '", ';
      }
      bitmapString += '"'; // Add closing quotation mark
      
      document.getElementById('bitmapData').value = bitmapString;
      this.submit();
    });
  </script>
</body>
</html>

from lcd.

Jimmy106-e avatar Jimmy106-e commented on August 17, 2024

@Jimmy106-e can you show me your code please? Also, I refer you to my GitHub repository, you may find the solution there https://github.com/Jumitti/lcd_home_automation

I checked your repo and you have the custom characters already set while mine are set dynamically, from user input.

from lcd.

Jumitti avatar Jumitti commented on August 17, 2024

@Jimmy106-e Thank you for your answer

I don't understand why you have "0b000" in your error.
ValueError: invalid literal for int() with base 2: '0b000"00000", "00000", "00000", "00100", "00000", "00000", "00000", "00000"'

Are you sure your HTML code is correct? I am not a specialist and even less in HTML but here is what I did to create and generate the binary of a custom character (in HTML). And lightingxd forked my project into Flask too -> fork

We certainly didn't do any dynamics but I think it's in the creation of the custom character binary that there is a problem

from lcd.

cgomesu avatar cgomesu commented on August 17, 2024

I don't understand why you have "0b000" in your error.

see binary_str_cmd in the method below.

lcd/drivers/i2c_dev.py

Lines 271 to 284 in b5febdd

def load_custom_characters_data(self):
self.chars_list = [self.char_1_data, self.char_2_data, self.char_3_data,
self.char_4_data, self.char_5_data, self.char_6_data,
self.char_7_data, self.char_8_data]
# commands to load character adress to RAM srarting from desired base adresses:
char_load_cmds = [0x40, 0x48, 0x50, 0x58, 0x60, 0x68, 0x70, 0x78]
for char_num in range(8):
# command to start loading data into CG RAM:
self.lcd.lcd_write(char_load_cmds[char_num])
for line_num in range(8):
line = self.chars_list[char_num][line_num]
binary_str_cmd = "0b000{0}".format(line)
self.lcd.lcd_write(int(binary_str_cmd, 2), Rs)

the issue is that '0b000"00000", "00000", "00000", "00100", "00000", "00000", "00000", "00000"' is not a binary literal. it should be '0b0000000000000000000010000000000000000000000' instead. need to understand why this is happening.

from lcd.

Jimmy106-e avatar Jimmy106-e commented on August 17, 2024

ok thanks

from lcd.

cgomesu avatar cgomesu commented on August 17, 2024

thanks for the feedback, @juvus . closing this issue as a completed.

from lcd.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.